add support for > and syntax
This commit is contained in:
parent
3f19a2f889
commit
81ca01ef1a
13
moka.html
13
moka.html
|
@ -587,7 +587,7 @@ SOFTWARE.
|
|||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// xtx
|
||||
|
||||
const sref = l => l.replace(/{/g, "{").replace(/}/g, "}").replace(/#\[\[([^\n]+?)\]\]/g, '#$1').replace(/\[\[([^\n]+?)\]\]/g, (match, p1) => `<a href="#${p1}">${p1}</a>`);
|
||||
const sref = l => l.replace(/{/g, "{").replace(/}/g, "}").replace(/#\[\[([^\n]+?)\]\]/g, '#$1').replace(/`([^`]+)`/g, '<code>$1</code>').replace(/\[\[([^\n]+?)\]\]/g, (match, p1) => `<a href="#${p1}">${p1}</a>`);
|
||||
const escapeHtml = unsafe => unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||||
|
||||
function toHTML(text) {
|
||||
|
@ -595,19 +595,20 @@ SOFTWARE.
|
|||
const lines = text.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
let l = lines[i];
|
||||
if (l.startsWith('# ')) rv += '<h1>' + sref(l.slice(2)) + '</h1>';
|
||||
else if (l.startsWith('## ')) rv += '<h2>' + sref(l.slice(3)) + '</h2>';
|
||||
else if (l.startsWith('### ')) rv += '<h3>' + sref(l.slice(4)) + '</h3>';
|
||||
if (l.startsWith('# ')) rv += `<h1>${sref(l.slice(2))}</h1>`;
|
||||
else if (l.startsWith('## ')) rv += `<h2>${sref(l.slice(3))}</h2>`;
|
||||
else if (l.startsWith('### ')) rv += `<h3>${sref(l.slice(4))}</h3>`;
|
||||
else if (l.startsWith('> ')) rv += `<blockquote>${sref(l.slice(2))}</blockquote>`;
|
||||
else if (l.startsWith('* ')) {
|
||||
!isList && (isList = true, rv += '<ul>');
|
||||
rv += '<li>' + sref(l.slice(2)) + '</li>';
|
||||
rv += `<li>${sref(l.slice(2))}</li>`;
|
||||
} else if (l.startsWith(' ')) {
|
||||
!isPre && (isPre = true, rv += '<pre>');
|
||||
rv += escapeHtml(l.slice(2)) + '\n';
|
||||
} else {
|
||||
isList && (isList = false, rv += '</ul>');
|
||||
isPre && (isPre = false, rv += '</pre>');
|
||||
l && (rv += '<p>' + sref(l) + '</p>');
|
||||
l && (rv += `<p>${sref(l)}</p>`);
|
||||
}
|
||||
}
|
||||
isList && (rv += '</ul>');
|
||||
|
|
Loading…
Reference in New Issue