diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-08-03 18:13:03 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-08-03 18:13:03 +0200 |
commit | a1f8d90055edb97647eaf3601b8869c35b91df9f (patch) | |
tree | e87063e8328b2be2581dddf1f8b22ff68b24cfc7 /content | |
parent | ToggleIcon: Make cursor on hover be pointer (diff) | |
download | baitinq.ml-a1f8d90055edb97647eaf3601b8869c35b91df9f.tar.gz baitinq.ml-a1f8d90055edb97647eaf3601b8869c35b91df9f.tar.bz2 baitinq.ml-a1f8d90055edb97647eaf3601b8869c35b91df9f.zip |
Change markdown generator to showdown
Diffstat (limited to 'content')
-rw-r--r-- | content/projects/project/osxiv.md | 135 |
1 files changed, 6 insertions, 129 deletions
diff --git a/content/projects/project/osxiv.md b/content/projects/project/osxiv.md index 8bf7177..e6a74ec 100644 --- a/content/projects/project/osxiv.md +++ b/content/projects/project/osxiv.md @@ -6,140 +6,17 @@ draft: false --- -<div id="tag-id"></div> +<div id="fetched-markdown"></div> -<script> - -function markdown(src) { - - var rx_lt = /</g; - var rx_gt = />/g; - var rx_space = /\t|\r|\uf8ff/g; - var rx_escape = /\\([\\\|`*_{}\[\]()#+\-~])/g; - var rx_hr = /^([*\-=_] *){3,}$/gm; - var rx_blockquote = /\n *> *([^]*?)(?=(\n|$){2})/g; - var rx_list = /\n( *)(?:[*\-+]|((\d+)|([a-z])|[A-Z])[.)]) +([^]*?)(?=(\n|$){2})/g; - var rx_listjoin = /<\/(ol|ul)>\n\n<\1>/g; - var rx_highlight = /(^|[^A-Za-z\d\\])(([*_])|(~)|(\^)|(--)|(\+\+)|`)(\2?)([^<]*?)\2\8(?!\2)(?=\W|_|$)/g; - var rx_code = /\n((```|~~~).*\n?([^]*?)\n?\2|(( .*?\n)+))/g; - var rx_link = /((!?)\[(.*?)\]\((.*?)( ".*")?\)|\\([\\`*_{}\[\]()#+\-.!~]))/g; - var rx_table = /\n(( *\|.*?\| *\n)+)/g; - var rx_thead = /^.*\n( *\|( *\:?-+\:?-+\:? *\|)* *\n|)/; - var rx_row = /.*\n/g; - var rx_cell = /\||(.*?[^\\])\|/g; - var rx_heading = /(?=^|>|\n)([>\s]*?)(#{1,6}) (.*?)( #*)? *(?=\n|$)/g; - var rx_para = /(?=^|>|\n)\s*\n+([^<]+?)\n+\s*(?=\n|<|$)/g; - var rx_stash = /-\d+\uf8ff/g; - - function replace(rex, fn) { - src = src.replace(rex, fn); - } - - function element(tag, content) { - return '<' + tag + '>' + content + '</' + tag + '>'; - } - - function blockquote(src) { - return src.replace(rx_blockquote, function(all, content) { - return element('blockquote', blockquote(highlight(content.replace(/^ *> */gm, '')))); - }); - } - - function list(src) { - return src.replace(rx_list, function(all, ind, ol, num, low, content) { - var entry = element('li', highlight(content.split( - RegExp('\n ?' + ind + '(?:(?:\\d+|[a-zA-Z])[.)]|[*\\-+]) +', 'g')).map(list).join('</li><li>'))); - - return '\n' + (ol - ? '<ol start="' + (num - ? ol + '">' - : parseInt(ol,36) - 9 + '" style="list-style-type:' + (low ? 'low' : 'upp') + 'er-alpha">') + entry + '</ol>' - : element('ul', entry)); - }); - } - - function highlight(src) { - return src.replace(rx_highlight, function(all, _, p1, emp, sub, sup, small, big, p2, content) { - return _ + element( - emp ? (p2 ? 'strong' : 'em') - : sub ? (p2 ? 's' : 'sub') - : sup ? 'sup' - : small ? 'small' - : big ? 'big' - : 'code', - highlight(content)); - }); - } - - function unesc(str) { - return str.replace(rx_escape, '$1'); - } - - var stash = []; - var si = 0; - - src = '\n' + src + '\n'; - - replace(rx_lt, '<'); - replace(rx_gt, '>'); - replace(rx_space, ' '); - - // blockquote - src = blockquote(src); - - // horizontal rule - replace(rx_hr, '<hr/>'); - - // list - src = list(src); - replace(rx_listjoin, ''); - - // code - replace(rx_code, function(all, p1, p2, p3, p4) { - stash[--si] = element('pre', element('code', p3||p4.replace(/^ /gm, ''))); - return si + '\uf8ff'; - }); - - // link or image - replace(rx_link, function(all, p1, p2, p3, p4, p5, p6) { - stash[--si] = p4 - ? p2 - ? '<img src="' + p4 + '" alt="' + p3 + '"/>' - : '<a href="' + p4 + '">' + unesc(highlight(p3)) + '</a>' - : p6; - return si + '\uf8ff'; - }); - - // table - replace(rx_table, function(all, table) { - var sep = table.match(rx_thead)[1]; - return '\n' + element('table', - table.replace(rx_row, function(row, ri) { - return row == sep ? '' : element('tr', row.replace(rx_cell, function(all, cell, ci) { - return ci ? element(sep && !ri ? 'th' : 'td', unesc(highlight(cell || ''))) : '' - })) - }) - ) - }); - - // heading - replace(rx_heading, function(all, _, p1, p2) { return _ + element('h' + p1.length, unesc(highlight(p2))) }); - - // paragraph - replace(rx_para, function(all, content) { return element('p', unesc(highlight(content))) }); - - // stash - replace(rx_stash, function(all) { return stash[parseInt(all)] }); - - return src.trim(); -}; +<script src="https://cdn.jsdelivr.net/npm/showdown@1.9.0/dist/showdown.min.js" type="text/javascript"></script> +<script> -//can we render as md fetch("https://raw.githubusercontent.com/Baitinq/OSXIV/master/README.md").then((response) => response.text()).then((data) => { - document.getElementById('tag-id').innerHTML = markdown(data); - console.log(markdown(data)); console.log(data); + const converter = new showdown.Converter(); + const html = converter.makeHtml(data); + document.getElementById('fetched-markdown').innerHTML = html; }); </script> |