#page
max-width: 500px;
margin: 15px;
word-wrap: break-word;
h1
display: flex;
align-items: baseline;
h1 span
display: inline-block;
margin: 0 0 0 10px;
img
max-width: 500px;
pre
word-wrap: break-word;
white-space: pre-wrap;
a
text-decoration: none;
input
width: 60%;
ul, ol
padding-left: 1em;
dd
margin: 1em;
var title
var names
function escape (text)
return text
.replace(/&/g, '&')
.replace(/, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
function emphasis (text)
return text
.replace(/'''(.*?)'''/g, '$1')
.replace(/''(.*?)''/g, '$1')
.replace(/^-----*/, '
')
var code = ''
var codes = []
function enter(key, replacement)
// $code = $key;
// while (@code > $depth) local($_) = pop @code; print "n"
// while (@code < $depth) push (@code, $key); print "n"
// if ($code[$#code] ne $key)
// print "n";
// $code[$#code] = $key;
//
return function (match, p1, p2)
var depth = p1.length
function complete (text)
return enter("", "")("","","") + text
function bullets (text)
// $code = "";
// s/^s*$/ / && ($code = '...');
// s/^(t+)(.+):t/$2 / && &enter('DL', length $1);
// s/^(t+)*// && &enter('UL', length $1);
// s/^(*+)/ / && &enter('UL', length $1);
// s/^(t+)d+.?/ / && &enter('OL', length $1);
// /^s/ && &enter('PRE', 1);
code = ''
result = text
.replace(/^s*$/, enter('...', 'p2 ') )
.replace(/^(t+)*/, enter('UL', '') )
.replace(/^(*+)/, enter('UL', ' ') )
.replace(/^(t+)d+.?/, enter('OL', ' ') )
.replace(/^(s)/, enter('PRE', 'p1') )
return result
function links (text, sanitize)
// link conversion happens in four phases:
// unexpected markers are adulterated
// links are found, converted, and stashed away properly escaped
// remaining text is processed and escaped
// unique markers are replaced with unstashed links
var stashed = []
function stash (text)
var here = stashed.length
stashed.push(text)
return "〖" + here + "〗"
function unstash (match, digits)
return stashed[+digits]
function internal (title)
if (names && names.indexOf(title)!=-1)
var url = location.origin + location.pathname + "?" + title
return stash("" + title + "")
else
return title
function external (url) png)$/))
return stash("")
else
return stash("" + url + "")
function youtube (match, p1, p2)
var embed =
"" +
"" +
"" +
"" +
"" +
""
return stash(embed)
function isbn (match, isbn)
var code = isbn.replace(/[- ]/g, "")
if (code.match(/^d9.$/))
return stash("ISBN " + isbn + "")
else
return "ISBN " + isbn
function titlesearch ()
function link(text)
return "" + text + ""
get = function()
var want = search.value
if (want.length > 1)
var found = names.filter(function (e) return e.includes(want) )
if (found.length)
return window.searchresult.innerHTML = found.slice(0,500).map(link).join('
')
window.searchresult.innerHTML = ''
got = function (e)
if (!e) e = window.event;
if ((e.keyCode
return stash("
max-width: 500px;
margin: 15px;
word-wrap: break-word;
h1
display: flex;
align-items: baseline;
h1 span
display: inline-block;
margin: 0 0 0 10px;
img
max-width: 500px;
pre
word-wrap: break-word;
white-space: pre-wrap;
a
text-decoration: none;
input
width: 60%;
ul, ol
padding-left: 1em;
dd
margin: 1em;
var title
var names
function escape (text)
return text
.replace(/&/g, '&')
.replace(/, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
function emphasis (text)
return text
.replace(/'''(.*?)'''/g, '$1')
.replace(/''(.*?)''/g, '$1')
.replace(/^-----*/, '
')
var code = ''
var codes = []
function enter(key, replacement)
// $code = $key;
// while (@code > $depth) local($_) = pop @code; print "n"
// while (@code < $depth) push (@code, $key); print "n"
// if ($code[$#code] ne $key)
// print "n";
// $code[$#code] = $key;
//
return function (match, p1, p2)
var depth = p1.length
function complete (text)
return enter("", "")("","","") + text
function bullets (text)
// $code = "";
// s/^s*$/ / && ($code = '...');
// s/^(t+)(.+):t/
// s/^(t+)*/
// s/^(*+)/
// s/^(t+)d+.?/
// /^s/ && &enter('PRE', 1);
code = ''
result = text
.replace(/^s*$/, enter('...', '
' ) )
.replace(/^(t+)(.+):t/, enter('DL', '
.replace(/^(t+)*/, enter('UL', '
.replace(/^(*+)/, enter('UL', '
.replace(/^(t+)d+.?/, enter('OL', '
.replace(/^(s)/, enter('PRE', 'p1') )
return result
function links (text, sanitize)
// link conversion happens in four phases:
// unexpected markers are adulterated
// links are found, converted, and stashed away properly escaped
// remaining text is processed and escaped
// unique markers are replaced with unstashed links
var stashed = []
function stash (text)
var here = stashed.length
stashed.push(text)
return "〖" + here + "〗"
function unstash (match, digits)
return stashed[+digits]
function internal (title)
if (names && names.indexOf(title)!=-1)
var url = location.origin + location.pathname + "?" + title
return stash("" + title + "")
else
return title
function external (url) png)$/))
return stash("")
else
return stash("" + url + "")
function youtube (match, p1, p2)
var embed =
"" +
"" +
"" +
"" +
"" +
""
return stash(embed)
function isbn (match, isbn)
var code = isbn.replace(/[- ]/g, "")
if (code.match(/^d9.$/))
return stash("ISBN " + isbn + "")
else
return "ISBN " + isbn
function titlesearch ()
function link(text)
return "" + text + ""
get = function()
var want = search.value
if (want.length > 1)
var found = names.filter(function (e) return e.includes(want) )
if (found.length)
return window.searchresult.innerHTML = found.slice(0,500).map(link).join('
')
window.searchresult.innerHTML = ''
got = function (e)
if (!e) e = window.event;
if ((e.keyCode
return stash("
")
function fullsearch ()
return stash("")
var prepass = text
.replace(/〖(d+)〗/g, '〖 $1 〗')
.replace(/^http://(www.)?youtube.com/watch?v=([-w]+)/, youtube)
.replace(/[Search]/, titlesearch)
.replace(/[Fullsearch]/, fullsearch)
.replace(/[?ISBN:? *([0-9- xX]10,)]?/i, isbn)
.replace(/b(https?
function inner (text)
text = escape(text)
text = bullets(text)
text = emphasis(text)
return text
function render (text)
return links(text, inner)
function markup (text)
var lines = text.replace(/\n/,' ').split(/n/)
var expand = lines.map(render).join("n")
return expand + complete('')
function trouble (msg)
var recourse = "
See github"
page.innerHTML = "
function fullsearch ()
return stash("")
var prepass = text
.replace(/〖(d+)〗/g, '〖 $1 〗')
.replace(/^http://(www.)?youtube.com/watch?v=([-w]+)/, youtube)
.replace(/[Search]/, titlesearch)
.replace(/[Fullsearch]/, fullsearch)
.replace(/[?ISBN:? *([0-9- xX]10,)]?/i, isbn)
.replace(/b(https?
function inner (text)
text = escape(text)
text = bullets(text)
text = emphasis(text)
return text
function render (text)
return links(text, inner)
function markup (text)
var lines = text.replace(/\n/,' ').split(/n/)
var expand = lines.map(render).join("n")
return expand + complete('')
function trouble (msg)
var recourse = "
See github"
page.innerHTML = "
Trouble Encountered
" + msg + recourse
function head()
var words = document.title = title.replace(/([a-z])([A-Z])/g, '$1 $2');
return [
'
',
'' + words + '',
''
].join('')
function foot(json)
return [
'
Last edit ',
json.date,
', See github about remodling.'
].join('')
function anypage ()
var any = Math.floor(Math.random() * names.length)
return '*' + names[any]
function show (json)
if (Object.keys(json).length == 0)
trouble('Page unavailable until conversion completed.')
else
if (title == 'RandomPages')
json.text = json.text.replace(/*w+/g, anypage)
page.innerHTML = head() + markup(json.text) + foot(json)
function loadDoc(url, done)
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
if (this.readyState == 4)
if (this.status == 200)
done(this.responseText)
else
trouble(url + "
can't fetch document
" + this.statusText)
xhttp.open("GET", url, true);
xhttp.send();
function fetchNames (done)
loadDoc('names.txt', done)
function fetchPage (done)
function init()
var json
function ready () names && json && show(json)
fetchNames(function(data) names = data.split(/r?n/); ready())
fetchPage(function(data) json = JSON.parse(data); ready())
if (!window.location.origin)
// https://github.com/WardCunningham/remodeling/issues/20
window.location.origin = window.location.protocol + '//' +
window.location.hostname +
(window.location.port ? (':' + window.location.port) : '');
init()
_uacct = "UA-2377314-2";_udn="c2.com"; urchinTracker();
'' + words + '',
''
].join('')
function foot(json)
return [
'
Last edit ',
json.date,
', See github about remodling.'
].join('')
function anypage ()
var any = Math.floor(Math.random() * names.length)
return '*' + names[any]
function show (json)
if (Object.keys(json).length == 0)
trouble('Page unavailable until conversion completed.')
else
if (title == 'RandomPages')
json.text = json.text.replace(/*w+/g, anypage)
page.innerHTML = head() + markup(json.text) + foot(json)
function loadDoc(url, done)
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
if (this.readyState == 4)
if (this.status == 200)
done(this.responseText)
else
trouble(url + "
can't fetch document
" + this.statusText)
xhttp.open("GET", url, true);
xhttp.send();
function fetchNames (done)
loadDoc('names.txt', done)
function fetchPage (done)
function init()
var json
function ready () names && json && show(json)
fetchNames(function(data) names = data.split(/r?n/); ready())
fetchPage(function(data) json = JSON.parse(data); ready())
if (!window.location.origin)
// https://github.com/WardCunningham/remodeling/issues/20
window.location.origin = window.location.protocol + '//' +
window.location.hostname +
(window.location.port ? (':' + window.location.port) : '');
init()
_uacct = "UA-2377314-2";_udn="c2.com"; urchinTracker();