@datawrapper/snarkdown 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jason Miller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ <p align="center">
2
+ <img src="https://cdn.jsdelivr.net/emojione/assets/svg/1f63c.svg" width="256" height="256" alt="Snarkdown">
3
+ </p>
4
+ <h1 align="center">
5
+ Snarkdown
6
+ <a href="https://www.npmjs.org/package/snarkdown">
7
+ <img src="https://img.shields.io/npm/v/snarkdown.svg?style=flat" alt="npm">
8
+ </a>
9
+ </h1>
10
+
11
+ Snarkdown is a dead simple **1kb** [Markdown] parser.
12
+
13
+ It's designed to be as minimal as possible, for constrained use-cases where a full Markdown parser would be inappropriate.
14
+
15
+
16
+ ## Features
17
+
18
+ - **Fast:** since it's basically one regex and a huge if statement
19
+ - **Tiny:** it's 1kb of gzipped ES3
20
+ - **Simple:** pass a Markdown string, get back an HTML string
21
+
22
+ > **Note:** Tables are not yet supported. If you love impossible to read regular expressions, submit a PR!
23
+ >
24
+ > **Note on XSS:** Snarkdown [doesn't sanitize HTML](https://github.com/developit/snarkdown/issues/70), since its primary target usage doesn't require it.
25
+
26
+ ## Demos & Examples
27
+
28
+ - ⚛️ [**Snarky**](https://snarky.surge.sh) - markdown editor built with Preact & Snarkdown
29
+ - ✏️ [**Simple Markdown Editor**](http://jsfiddle.net/developit/828w6t1x/)
30
+
31
+
32
+ ## Usage
33
+
34
+ Snarkdown exports a single function, which parses a string of Markdown and returns a String of HTML. Couldn't be simpler.
35
+
36
+ The snarkdown module is available in [every module format](https://unpkg.com/snarkdown/dist/) you'd ever need: ES Modules, CommonJS, UMD...
37
+
38
+ ```js
39
+ import snarkdown from 'snarkdown';
40
+
41
+ let md = '_this_ is **easy** to `use`.';
42
+ let html = snarkdown(md);
43
+ console.log(html);
44
+ // <em>this</em> is <strong>easy</strong> to <code>use</code>.
45
+ ```
46
+
47
+ ### Add-ons and Libraries
48
+
49
+ - For Webpack users, [`snarkdown-loader`](https://github.com/Plugin-contrib/snarkdown-loader) renders markdown files to html.
50
+
51
+
52
+
53
+ [Markdown]: http://daringfireball.net/projects/markdown/
@@ -0,0 +1,2 @@
1
+ var e={"":["<em>","</em>"],_:["<strong>","</strong>"],"*":["<strong>","</strong>"],"~":["<s>","</s>"],"\n":["<br />"]," ":["<br />"],"-":["<hr />"]};function n(e){return e.replace(RegExp("^"+(e.match(/^(\t| )+/)||"")[0],"gm"),"")}function r(e){return(e+"").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}export default function t(a,c){var o,g,l,s,u,p=/((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,i=[],h="",m=c||{},f=0;function d(n){var r=e[n[1]||""],t=i[i.length-1]==n;return r?r[1]?(t?i.pop():i.push(n),r[0|t]):r[0]:n}function $(){for(var e="";i.length;)e+=d(i[i.length-1]);return e}for(a=(a=a.replace(/\\([*_[\]{}`<>()#+\-!|.])/g,function(e){return"&%"+e.charCodeAt(1)+"%;"})).replace(/^\[(.+?)\]:\s*(.+)$/gm,function(e,n,r){return m[n.toLowerCase()]=r,""}).replace(/^\n+|\n+$/g,"");l=p.exec(a);)g=a.substring(f,l.index),f=p.lastIndex,o=l[0],g.match(/[^\\](\\\\)*\\$/)||((u=l[3]||l[4])?o='<pre class="code '+(l[4]?"poetry":l[2].toLowerCase())+'"><code'+(l[2]?' class="language-'+l[2].toLowerCase()+'"':"")+">"+n(r(u).replace(/^\n+|\n+$/g,""))+"</code></pre>":(u=l[6])?(u.match(/\./)&&(l[5]=l[5].replace(/^\d+/gm,"")),s=t(n(l[5].replace(/^\s*[>*+.-]/gm,""))),">"==u?u="blockquote":(u=u.match(/\./)?"ol":"ul",s=s.replace(/^(.*)(\n|$)/gm,"<li>$1</li>")),o="<"+u+">"+s+"</"+u+">"):l[8]?o='<img src="'+r(l[8])+'" alt="'+r(l[7])+'">':l[10]?(h=h.replace("<a>",'<a href="'+r(l[11]||m[g.toLowerCase()])+'">'),o=$()+"</a>"):l[9]?o="<a>":l[12]||l[14]?o="<"+(u="h"+(l[14]?l[14].length:l[13]>"="?1:2))+">"+t(l[12]||l[15],m)+"</"+u+">":l[16]?o="<code>"+r(l[16])+"</code>":(l[17]||l[1])&&(o=d(l[17]||"--"))),h+=g,h+=o;return(h+a.substring(f).replace(/&%[0-9]+%;/g,function(e){return String.fromCharCode(+e.substring(2,e.length-2))})+$()).replace(/^\n+|\n+$/g,"")}
2
+ //# sourceMappingURL=snarkdown.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snarkdown.es.js","sources":["../src/index.js"],"sourcesContent":["const TAGS = {\n\t'': ['<em>','</em>'],\n\t_: ['<strong>','</strong>'],\n\t'*': ['<strong>','</strong>'],\n\t'~': ['<s>','</s>'],\n\t'\\n': ['<br />'],\n\t' ': ['<br />'],\n\t'-': ['<hr />']\n};\n\n/** Outdent a string based on the first indented line's leading whitespace\n *\t@private\n */\nfunction outdent(str) {\n\treturn str.replace(RegExp('^'+(str.match(/^(\\t| )+/) || '')[0], 'gm'), '');\n}\n\n/** Encode special attribute characters to HTML entities in a String.\n *\t@private\n */\nfunction encodeAttr(str) {\n\treturn (str+'').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\n/** Parse Markdown into an HTML String. */\nexport default function parse(md, prevLinks) {\n\tlet tokenizer = /((?:^|\\n+)(?:\\n---+|\\* \\*(?: \\*)+)\\n)|(?:^``` *(\\w*)\\n([\\s\\S]*?)\\n```$)|((?:(?:^|\\n+)(?:\\t| {2,}).+)+\\n*)|((?:(?:^|\\n)([>*+-]|\\d+\\.)\\s+.*)+)|(?:!\\[([^\\]]*?)\\]\\(([^)]+?)\\))|(\\[)|(\\](?:\\(([^)]+?)\\))?)|(?:(?:^|\\n+)([^\\s].*)\\n(-{3,}|={3,})(?:\\n+|$))|(?:(?:^|\\n+)(#{1,6})\\s*(.+)(?:\\n+|$))|(?:`([^`].*?)`)|( \\n\\n*|\\n{2,}|__|\\*\\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,\n\t\tcontext = [],\n\t\tout = '',\n\t\tlinks = prevLinks || {},\n\t\tlast = 0,\n\t\tchunk, prev, token, inner, t;\n\t// escape special characters\n\tmd = md.replace(/\\\\([*_[\\]{}`<>()#+\\-!|.])/g, m => `&%${m.charCodeAt(1)}%;`);\n\n\tfunction tag(token) {\n\t\tlet desc = TAGS[token[1] || ''];\n\t\tlet end = context[context.length-1] == token;\n\t\tif (!desc) return token;\n\t\tif (!desc[1]) return desc[0];\n\t\tif (end) context.pop();\n\t\telse context.push(token);\n\t\treturn desc[end|0];\n\t}\n\n\tfunction flush() {\n\t\tlet str = '';\n\t\twhile (context.length) str += tag(context[context.length-1]);\n\t\treturn str;\n\t}\n\n\tmd = md.replace(/^\\[(.+?)\\]:\\s*(.+)$/gm, (s, name, url) => {\n\t\tlinks[name.toLowerCase()] = url;\n\t\treturn '';\n\t}).replace(/^\\n+|\\n+$/g, '');\n\n\twhile ( (token=tokenizer.exec(md)) ) {\n\t\tprev = md.substring(last, token.index);\n\t\tlast = tokenizer.lastIndex;\n\t\tchunk = token[0];\n\t\tif (prev.match(/[^\\\\](\\\\\\\\)*\\\\$/)) {\n\t\t\t// escaped\n\t\t}\n\t\t// Code/Indent blocks:\n\t\telse if (t = (token[3] || token[4])) {\n\t\t\tchunk = '<pre class=\"code '+(token[4]?'poetry':token[2].toLowerCase())+'\"><code'+(token[2] ? ` class=\"language-${token[2].toLowerCase()}\"` : '')+'>'+outdent(encodeAttr(t).replace(/^\\n+|\\n+$/g, ''))+'</code></pre>';\n\t\t}\n\t\t// > Quotes, -* lists:\n\t\telse if (t = token[6]) {\n\t\t\tif (t.match(/\\./)) {\n\t\t\t\ttoken[5] = token[5].replace(/^\\d+/gm, '');\n\t\t\t}\n\t\t\tinner = parse(outdent(token[5].replace(/^\\s*[>*+.-]/gm, '')));\n\t\t\tif (t=='>') t = 'blockquote';\n\t\t\telse {\n\t\t\t\tt = t.match(/\\./) ? 'ol' : 'ul';\n\t\t\t\tinner = inner.replace(/^(.*)(\\n|$)/gm, '<li>$1</li>');\n\t\t\t}\n\t\t\tchunk = '<'+t+'>' + inner + '</'+t+'>';\n\t\t}\n\t\t// Images:\n\t\telse if (token[8]) {\n\t\t\tchunk = `<img src=\"${encodeAttr(token[8])}\" alt=\"${encodeAttr(token[7])}\">`;\n\t\t}\n\t\t// Links:\n\t\telse if (token[10]) {\n\t\t\tout = out.replace('<a>', `<a href=\"${encodeAttr(token[11] || links[prev.toLowerCase()])}\">`);\n\t\t\tchunk = flush() + '</a>';\n\t\t}\n\t\telse if (token[9]) {\n\t\t\tchunk = '<a>';\n\t\t}\n\t\t// Headings:\n\t\telse if (token[12] || token[14]) {\n\t\t\tt = 'h' + (token[14] ? token[14].length : (token[13]>'=' ? 1 : 2));\n\t\t\tchunk = '<'+t+'>' + parse(token[12] || token[15], links) + '</'+t+'>';\n\t\t}\n\t\t// `code`:\n\t\telse if (token[16]) {\n\t\t\tchunk = '<code>'+encodeAttr(token[16])+'</code>';\n\t\t}\n\t\t// Inline formatting: *em*, **strong** & friends\n\t\telse if (token[17] || token[1]) {\n\t\t\tchunk = tag(token[17] || '--');\n\t\t}\n\t\tout += prev;\n\t\tout += chunk;\n\t}\n\n\treturn (\n\t\tout +\n\t\tmd\n\t\t\t.substring(last)\n\t\t\t// unscape special characters\n\t\t\t.replace(/&%[0-9]+%;/g, (m) =>\n\t\t\t\tString.fromCharCode(+m.substring(2, m.length - 2))\n\t\t\t) +\n\t\tflush()\n\t).replace(/^\\n+|\\n+$/g, '');\n}\n"],"names":["TAGS","_","*","~","\n"," ","-","outdent","str","replace","RegExp","match","encodeAttr","parse","md","prevLinks","chunk","prev","token","inner","t","tokenizer","context","out","links","last","tag","desc","end","length","pop","push","flush","m","charCodeAt","s","name","url","toLowerCase","exec","substring","index","lastIndex","String","fromCharCode"],"mappings":"AAAA,IAAMA,EAAO,CACZ,GAAI,CAAC,OAAO,SACZC,EAAG,CAAC,WAAW,aACfC,IAAK,CAAC,WAAW,aACjBC,IAAK,CAAC,MAAM,QACZC,KAAM,CAAC,UACPC,IAAK,CAAC,UACNC,IAAK,CAAC,WAMP,SAAS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AM,GAAKA,EAAM,GAAGT,QAAQ,SAAU,KAEvCU,EAAQN,EAAMN,EAAQW,EAAM,GAAGT,QAAQ,gBAAiB,MACjD,KAAHW,EAAQA,EAAI,cAEfA,EAAIA,EAAET,MAAM,MAAQ,KAAO,KAC3BQ,EAAQA,EAAMV,QAAQ,gBAAiB,gBAExCO,EAAQ,IAAII,EAAE,IAAMD,EAAQ,KAAKC,EAAE,KAG3BF,EAAM,GACdF,eAAqBJ,EAAWM,EAAM,cAAaN,EAAWM,EAAM,SAG5DA,EAAM,KACdK,EAAMA,EAAId,QAAQ,kBAAmBG,EAAWM,EAAM,KAAOM,EAAMP,EAAKqB,sBACxEtB,EAAQgB,IAAU,QAEVd,EAAM,GACdF,EAAQ,MAGAE,EAAM,KAAOA,EAAM,IAE3BF,EAAQ,KADRI,EAAI,KAAOF,EAAM,IAAMA,EAAM,IAAIW,OAAUX,EAAM,IAAI,IAAM,EAAI,IACjD,IAAML,EAAMK,EAAM,KAAOA,EAAM,IAAKM,GAAS,KAAKJ,EAAE,IAG1DF,EAAM,IACdF,EAAQ,SAASJ,EAAWM,EAAM,KAAK,WAG/BA,EAAM,KAAOA,EAAM,MAC3BF,EAAQU,EAAIR,EAAM,KAAO,QAE1BK,GAAON,EACPM,GAAOP,EAGR,OACCO,EACAT,EACE0B,UAAUf,GAEVhB,QAAQ,cAAe,SAACwB,UACxBU,OAAOC,cAAcX,EAAEO,UAAU,EAAGP,EAAEJ,OAAS,MAEjDG,KACCvB,QAAQ,aAAc"}
@@ -0,0 +1,2 @@
1
+ var e={"":["<em>","</em>"],_:["<strong>","</strong>"],"*":["<strong>","</strong>"],"~":["<s>","</s>"],"\n":["<br />"]," ":["<br />"],"-":["<hr />"]};function n(e){return e.replace(RegExp("^"+(e.match(/^(\t| )+/)||"")[0],"gm"),"")}function r(e){return(e+"").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}module.exports=function t(a,o){var c,g,l,s,u,p=/((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,i=[],h="",m=o||{},d=0;function f(n){var r=e[n[1]||""],t=i[i.length-1]==n;return r?r[1]?(t?i.pop():i.push(n),r[0|t]):r[0]:n}function $(){for(var e="";i.length;)e+=f(i[i.length-1]);return e}for(a=(a=a.replace(/\\([*_[\]{}`<>()#+\-!|.])/g,function(e){return"&%"+e.charCodeAt(1)+"%;"})).replace(/^\[(.+?)\]:\s*(.+)$/gm,function(e,n,r){return m[n.toLowerCase()]=r,""}).replace(/^\n+|\n+$/g,"");l=p.exec(a);)g=a.substring(d,l.index),d=p.lastIndex,c=l[0],g.match(/[^\\](\\\\)*\\$/)||((u=l[3]||l[4])?c='<pre class="code '+(l[4]?"poetry":l[2].toLowerCase())+'"><code'+(l[2]?' class="language-'+l[2].toLowerCase()+'"':"")+">"+n(r(u).replace(/^\n+|\n+$/g,""))+"</code></pre>":(u=l[6])?(u.match(/\./)&&(l[5]=l[5].replace(/^\d+/gm,"")),s=t(n(l[5].replace(/^\s*[>*+.-]/gm,""))),">"==u?u="blockquote":(u=u.match(/\./)?"ol":"ul",s=s.replace(/^(.*)(\n|$)/gm,"<li>$1</li>")),c="<"+u+">"+s+"</"+u+">"):l[8]?c='<img src="'+r(l[8])+'" alt="'+r(l[7])+'">':l[10]?(h=h.replace("<a>",'<a href="'+r(l[11]||m[g.toLowerCase()])+'">'),c=$()+"</a>"):l[9]?c="<a>":l[12]||l[14]?c="<"+(u="h"+(l[14]?l[14].length:l[13]>"="?1:2))+">"+t(l[12]||l[15],m)+"</"+u+">":l[16]?c="<code>"+r(l[16])+"</code>":(l[17]||l[1])&&(c=f(l[17]||"--"))),h+=g,h+=c;return(h+a.substring(d).replace(/&%[0-9]+%;/g,function(e){return String.fromCharCode(+e.substring(2,e.length-2))})+$()).replace(/^\n+|\n+$/g,"")};
2
+ //# sourceMappingURL=snarkdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snarkdown.js","sources":["../src/index.js"],"sourcesContent":["const TAGS = {\n\t'': ['<em>','</em>'],\n\t_: ['<strong>','</strong>'],\n\t'*': ['<strong>','</strong>'],\n\t'~': ['<s>','</s>'],\n\t'\\n': ['<br />'],\n\t' ': ['<br />'],\n\t'-': ['<hr />']\n};\n\n/** Outdent a string based on the first indented line's leading whitespace\n *\t@private\n */\nfunction outdent(str) {\n\treturn str.replace(RegExp('^'+(str.match(/^(\\t| )+/) || '')[0], 'gm'), '');\n}\n\n/** Encode special attribute characters to HTML entities in a String.\n *\t@private\n */\nfunction encodeAttr(str) {\n\treturn (str+'').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\n/** Parse Markdown into an HTML String. */\nexport default function parse(md, prevLinks) {\n\tlet tokenizer = /((?:^|\\n+)(?:\\n---+|\\* \\*(?: \\*)+)\\n)|(?:^``` *(\\w*)\\n([\\s\\S]*?)\\n```$)|((?:(?:^|\\n+)(?:\\t| {2,}).+)+\\n*)|((?:(?:^|\\n)([>*+-]|\\d+\\.)\\s+.*)+)|(?:!\\[([^\\]]*?)\\]\\(([^)]+?)\\))|(\\[)|(\\](?:\\(([^)]+?)\\))?)|(?:(?:^|\\n+)([^\\s].*)\\n(-{3,}|={3,})(?:\\n+|$))|(?:(?:^|\\n+)(#{1,6})\\s*(.+)(?:\\n+|$))|(?:`([^`].*?)`)|( \\n\\n*|\\n{2,}|__|\\*\\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,\n\t\tcontext = [],\n\t\tout = '',\n\t\tlinks = prevLinks || {},\n\t\tlast = 0,\n\t\tchunk, prev, token, inner, t;\n\t// escape special characters\n\tmd = md.replace(/\\\\([*_[\\]{}`<>()#+\\-!|.])/g, m => `&%${m.charCodeAt(1)}%;`);\n\n\tfunction tag(token) {\n\t\tlet desc = TAGS[token[1] || ''];\n\t\tlet end = context[context.length-1] == token;\n\t\tif (!desc) return token;\n\t\tif (!desc[1]) return desc[0];\n\t\tif (end) context.pop();\n\t\telse context.push(token);\n\t\treturn desc[end|0];\n\t}\n\n\tfunction flush() {\n\t\tlet str = '';\n\t\twhile (context.length) str += tag(context[context.length-1]);\n\t\treturn str;\n\t}\n\n\tmd = md.replace(/^\\[(.+?)\\]:\\s*(.+)$/gm, (s, name, url) => {\n\t\tlinks[name.toLowerCase()] = url;\n\t\treturn '';\n\t}).replace(/^\\n+|\\n+$/g, '');\n\n\twhile ( (token=tokenizer.exec(md)) ) {\n\t\tprev = md.substring(last, token.index);\n\t\tlast = tokenizer.lastIndex;\n\t\tchunk = token[0];\n\t\tif (prev.match(/[^\\\\](\\\\\\\\)*\\\\$/)) {\n\t\t\t// escaped\n\t\t}\n\t\t// Code/Indent blocks:\n\t\telse if (t = (token[3] || token[4])) {\n\t\t\tchunk = '<pre class=\"code '+(token[4]?'poetry':token[2].toLowerCase())+'\"><code'+(token[2] ? ` class=\"language-${token[2].toLowerCase()}\"` : '')+'>'+outdent(encodeAttr(t).replace(/^\\n+|\\n+$/g, ''))+'</code></pre>';\n\t\t}\n\t\t// > Quotes, -* lists:\n\t\telse if (t = token[6]) {\n\t\t\tif (t.match(/\\./)) {\n\t\t\t\ttoken[5] = token[5].replace(/^\\d+/gm, '');\n\t\t\t}\n\t\t\tinner = parse(outdent(token[5].replace(/^\\s*[>*+.-]/gm, '')));\n\t\t\tif (t=='>') t = 'blockquote';\n\t\t\telse {\n\t\t\t\tt = t.match(/\\./) ? 'ol' : 'ul';\n\t\t\t\tinner = inner.replace(/^(.*)(\\n|$)/gm, '<li>$1</li>');\n\t\t\t}\n\t\t\tchunk = '<'+t+'>' + inner + '</'+t+'>';\n\t\t}\n\t\t// Images:\n\t\telse if (token[8]) {\n\t\t\tchunk = `<img src=\"${encodeAttr(token[8])}\" alt=\"${encodeAttr(token[7])}\">`;\n\t\t}\n\t\t// Links:\n\t\telse if (token[10]) {\n\t\t\tout = out.replace('<a>', `<a href=\"${encodeAttr(token[11] || links[prev.toLowerCase()])}\">`);\n\t\t\tchunk = flush() + '</a>';\n\t\t}\n\t\telse if (token[9]) {\n\t\t\tchunk = '<a>';\n\t\t}\n\t\t// Headings:\n\t\telse if (token[12] || token[14]) {\n\t\t\tt = 'h' + (token[14] ? token[14].length : (token[13]>'=' ? 1 : 2));\n\t\t\tchunk = '<'+t+'>' + parse(token[12] || token[15], links) + '</'+t+'>';\n\t\t}\n\t\t// `code`:\n\t\telse if (token[16]) {\n\t\t\tchunk = '<code>'+encodeAttr(token[16])+'</code>';\n\t\t}\n\t\t// Inline formatting: *em*, **strong** & friends\n\t\telse if (token[17] || token[1]) {\n\t\t\tchunk = tag(token[17] || '--');\n\t\t}\n\t\tout += prev;\n\t\tout += chunk;\n\t}\n\n\treturn (\n\t\tout +\n\t\tmd\n\t\t\t.substring(last)\n\t\t\t// unscape special characters\n\t\t\t.replace(/&%[0-9]+%;/g, (m) =>\n\t\t\t\tString.fromCharCode(+m.substring(2, m.length - 2))\n\t\t\t) +\n\t\tflush()\n\t).replace(/^\\n+|\\n+$/g, '');\n}\n"],"names":["TAGS","_","*","~","\n"," ","-","outdent","str","replace","RegExp","match","encodeAttr","parse","md","prevLinks","chunk","prev","token","inner","t","tokenizer","context","out","links","last","tag","desc","end","length","pop","push","flush","m","charCodeAt","s","name","url","toLowerCase","exec","substring","index","lastIndex","String","fromCharCode"],"mappings":"AAAA,IAAMA,EAAO,CACZ,GAAI,CAAC,OAAO,SACZC,EAAG,CAAC,WAAW,aACfC,IAAK,CAAC,WAAW,aACjBC,I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WQ,GAAGX,QAAQ,aAAc,KAAK,iBAG9LW,EAAIF,EAAM,KACdE,EAAET,MAAM,QACXO,EAAM,GAAKA,EAAM,GAAGT,QAAQ,SAAU,KAEvCU,EAAQN,EAAMN,EAAQW,EAAM,GAAGT,QAAQ,gBAAiB,MACjD,KAAHW,EAAQA,EAAI,cAEfA,EAAIA,EAAET,MAAM,MAAQ,KAAO,KAC3BQ,EAAQA,EAAMV,QAAQ,gBAAiB,gBAExCO,EAAQ,IAAII,EAAE,IAAMD,EAAQ,KAAKC,EAAE,KAG3BF,EAAM,GACdF,eAAqBJ,EAAWM,EAAM,cAAaN,EAAWM,EAAM,SAG5DA,EAAM,KACdK,EAAMA,EAAId,QAAQ,kBAAmBG,EAAWM,EAAM,KAAOM,EAAMP,EAAKqB,sBACxEtB,EAAQgB,IAAU,QAEVd,EAAM,GACdF,EAAQ,MAGAE,EAAM,KAAOA,EAAM,IAE3BF,EAAQ,KADRI,EAAI,KAAOF,EAAM,IAAMA,EAAM,IAAIW,OAAUX,EAAM,IAAI,IAAM,EAAI,IACjD,IAAML,EAAMK,EAAM,KAAOA,EAAM,IAAKM,GAAS,KAAKJ,EAAE,IAG1DF,EAAM,IACdF,EAAQ,SAASJ,EAAWM,EAAM,KAAK,WAG/BA,EAAM,KAAOA,EAAM,MAC3BF,EAAQU,EAAIR,EAAM,KAAO,QAE1BK,GAAON,EACPM,GAAOP,EAGR,OACCO,EACAT,EACE0B,UAAUf,GAEVhB,QAAQ,cAAe,SAACwB,UACxBU,OAAOC,cAAcX,EAAEO,UAAU,EAAGP,EAAEJ,OAAS,MAEjDG,KACCvB,QAAQ,aAAc"}
@@ -0,0 +1,2 @@
1
+ const e={"":["<em>","</em>"],_:["<strong>","</strong>"],"*":["<strong>","</strong>"],"~":["<s>","</s>"],"\n":["<br />"]," ":["<br />"],"-":["<hr />"]};function n(e){return e.replace(RegExp("^"+(e.match(/^(\t| )+/)||"")[0],"gm"),"")}function r(e){return(e+"").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}export default function t(a,c){let o,l,g,s,p,u=/((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,h=[],$="",m=c||{},i=0;function d(n){let r=e[n[1]||""],t=h[h.length-1]==n;return r?r[1]?(t?h.pop():h.push(n),r[0|t]):r[0]:n}function f(){let e="";for(;h.length;)e+=d(h[h.length-1]);return e}for(a=(a=a.replace(/\\([*_[\]{}`<>()#+\-!|.])/g,e=>`&%${e.charCodeAt(1)}%;`)).replace(/^\[(.+?)\]:\s*(.+)$/gm,(e,n,r)=>(m[n.toLowerCase()]=r,"")).replace(/^\n+|\n+$/g,"");g=u.exec(a);)l=a.substring(i,g.index),i=u.lastIndex,o=g[0],l.match(/[^\\](\\\\)*\\$/)||((p=g[3]||g[4])?o='<pre class="code '+(g[4]?"poetry":g[2].toLowerCase())+'"><code'+(g[2]?` class="language-${g[2].toLowerCase()}"`:"")+">"+n(r(p).replace(/^\n+|\n+$/g,""))+"</code></pre>":(p=g[6])?(p.match(/\./)&&(g[5]=g[5].replace(/^\d+/gm,"")),s=t(n(g[5].replace(/^\s*[>*+.-]/gm,""))),">"==p?p="blockquote":(p=p.match(/\./)?"ol":"ul",s=s.replace(/^(.*)(\n|$)/gm,"<li>$1</li>")),o="<"+p+">"+s+"</"+p+">"):g[8]?o=`<img src="${r(g[8])}" alt="${r(g[7])}">`:g[10]?($=$.replace("<a>",`<a href="${r(g[11]||m[l.toLowerCase()])}">`),o=f()+"</a>"):g[9]?o="<a>":g[12]||g[14]?(p="h"+(g[14]?g[14].length:g[13]>"="?1:2),o="<"+p+">"+t(g[12]||g[15],m)+"</"+p+">"):g[16]?o="<code>"+r(g[16])+"</code>":(g[17]||g[1])&&(o=d(g[17]||"--"))),$+=l,$+=o;return($+a.substring(i).replace(/&%[0-9]+%;/g,e=>String.fromCharCode(+e.substring(2,e.length-2)))+f()).replace(/^\n+|\n+$/g,"")}
2
+ //# sourceMappingURL=snarkdown.modern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snarkdown.modern.js","sources":["../src/index.js"],"sourcesContent":["const TAGS = {\n\t'': ['<em>','</em>'],\n\t_: ['<strong>','</strong>'],\n\t'*': ['<strong>','</strong>'],\n\t'~': ['<s>','</s>'],\n\t'\\n': ['<br />'],\n\t' ': ['<br />'],\n\t'-': ['<hr />']\n};\n\n/** Outdent a string based on the first indented line's leading whitespace\n *\t@private\n */\nfunction outdent(str) {\n\treturn str.replace(RegExp('^'+(str.match(/^(\\t| )+/) || '')[0], 'gm'), '');\n}\n\n/** Encode special attribute characters to HTML entities in a String.\n *\t@private\n */\nfunction encodeAttr(str) {\n\treturn (str+'').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\n/** Parse Markdown into an HTML String. */\nexport default function parse(md, prevLinks) {\n\tlet tokenizer = /((?:^|\\n+)(?:\\n---+|\\* \\*(?: \\*)+)\\n)|(?:^``` *(\\w*)\\n([\\s\\S]*?)\\n```$)|((?:(?:^|\\n+)(?:\\t| {2,}).+)+\\n*)|((?:(?:^|\\n)([>*+-]|\\d+\\.)\\s+.*)+)|(?:!\\[([^\\]]*?)\\]\\(([^)]+?)\\))|(\\[)|(\\](?:\\(([^)]+?)\\))?)|(?:(?:^|\\n+)([^\\s].*)\\n(-{3,}|={3,})(?:\\n+|$))|(?:(?:^|\\n+)(#{1,6})\\s*(.+)(?:\\n+|$))|(?:`([^`].*?)`)|( \\n\\n*|\\n{2,}|__|\\*\\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,\n\t\tcontext = [],\n\t\tout = '',\n\t\tlinks = prevLinks || {},\n\t\tlast = 0,\n\t\tchunk, prev, token, inner, t;\n\t// escape special characters\n\tmd = md.replace(/\\\\([*_[\\]{}`<>()#+\\-!|.])/g, m => `&%${m.charCodeAt(1)}%;`);\n\n\tfunction tag(token) {\n\t\tlet desc = TAGS[token[1] || ''];\n\t\tlet end = context[context.length-1] == token;\n\t\tif (!desc) return token;\n\t\tif (!desc[1]) return desc[0];\n\t\tif (end) context.pop();\n\t\telse context.push(token);\n\t\treturn desc[end|0];\n\t}\n\n\tfunction flush() {\n\t\tlet str = '';\n\t\twhile (context.length) str += tag(context[context.length-1]);\n\t\treturn str;\n\t}\n\n\tmd = md.replace(/^\\[(.+?)\\]:\\s*(.+)$/gm, (s, name, url) => {\n\t\tlinks[name.toLowerCase()] = url;\n\t\treturn '';\n\t}).replace(/^\\n+|\\n+$/g, '');\n\n\twhile ( (token=tokenizer.exec(md)) ) {\n\t\tprev = md.substring(last, token.index);\n\t\tlast = tokenizer.lastIndex;\n\t\tchunk = token[0];\n\t\tif (prev.match(/[^\\\\](\\\\\\\\)*\\\\$/)) {\n\t\t\t// escaped\n\t\t}\n\t\t// Code/Indent blocks:\n\t\telse if (t = (token[3] || token[4])) {\n\t\t\tchunk = '<pre class=\"code '+(token[4]?'poetry':token[2].toLowerCase())+'\"><code'+(token[2] ? ` class=\"language-${token[2].toLowerCase()}\"` : '')+'>'+outdent(encodeAttr(t).replace(/^\\n+|\\n+$/g, ''))+'</code></pre>';\n\t\t}\n\t\t// > Quotes, -* lists:\n\t\telse if (t = token[6]) {\n\t\t\tif (t.match(/\\./)) {\n\t\t\t\ttoken[5] = token[5].replace(/^\\d+/gm, '');\n\t\t\t}\n\t\t\tinner = parse(outdent(token[5].replace(/^\\s*[>*+.-]/gm, '')));\n\t\t\tif (t=='>') t = 'blockquote';\n\t\t\telse {\n\t\t\t\tt = t.match(/\\./) ? 'ol' : 'ul';\n\t\t\t\tinner = inner.replace(/^(.*)(\\n|$)/gm, '<li>$1</li>');\n\t\t\t}\n\t\t\tchunk = '<'+t+'>' + inner + '</'+t+'>';\n\t\t}\n\t\t// Images:\n\t\telse if (token[8]) {\n\t\t\tchunk = `<img src=\"${encodeAttr(token[8])}\" alt=\"${encodeAttr(token[7])}\">`;\n\t\t}\n\t\t// Links:\n\t\telse if (token[10]) {\n\t\t\tout = out.replace('<a>', `<a href=\"${encodeAttr(token[11] || links[prev.toLowerCase()])}\">`);\n\t\t\tchunk = flush() + '</a>';\n\t\t}\n\t\telse if (token[9]) {\n\t\t\tchunk = '<a>';\n\t\t}\n\t\t// Headings:\n\t\telse if (token[12] || token[14]) {\n\t\t\tt = 'h' + (token[14] ? token[14].length : (token[13]>'=' ? 1 : 2));\n\t\t\tchunk = '<'+t+'>' + parse(token[12] || token[15], links) + '</'+t+'>';\n\t\t}\n\t\t// `code`:\n\t\telse if (token[16]) {\n\t\t\tchunk = '<code>'+encodeAttr(token[16])+'</code>';\n\t\t}\n\t\t// Inline formatting: *em*, **strong** & friends\n\t\telse if (token[17] || token[1]) {\n\t\t\tchunk = tag(token[17] || '--');\n\t\t}\n\t\tout += prev;\n\t\tout += chunk;\n\t}\n\n\treturn (\n\t\tout +\n\t\tmd\n\t\t\t.substring(last)\n\t\t\t// unscape special characters\n\t\t\t.replace(/&%[0-9]+%;/g, (m) =>\n\t\t\t\tString.fromCharCode(+m.substring(2, m.length - 2))\n\t\t\t) +\n\t\tflush()\n\t).replace(/^\\n+|\\n+$/g, '');\n}\n"],"names":["TAGS","_","*","~","\n"," ","-","outdent","str","replace","RegExp","match","encodeAttr","parse","md","prevLinks","chunk","prev","token","inner","t","tokenizer","context","out","links","last","tag","desc","end","length","pop","push","flush","m","charCodeAt","s","name","url","toLowerCase","exec","substring","index","lastIndex","String","fromCharCode"],"mappings":"AAAA,MAAMA,EAAO,CACZ,G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AWpB,EAAM,GAAM,oBAAmBA,EAAM,GAAGoB,iBAAmB,IAAI,IAAI/B,EAAQK,EAAWQ,GAAGX,QAAQ,aAAc,KAAK,iBAG9LW,EAAIF,EAAM,KACdE,EAAET,MAAM,QACXO,EAAM,GAAKA,EAAM,GAAGT,QAAQ,SAAU,KAEvCU,EAAQN,EAAMN,EAAQW,EAAM,GAAGT,QAAQ,gBAAiB,MACjD,KAAHW,EAAQA,EAAI,cAEfA,EAAIA,EAAET,MAAM,MAAQ,KAAO,KAC3BQ,EAAQA,EAAMV,QAAQ,gBAAiB,gBAExCO,EAAQ,IAAII,EAAE,IAAMD,EAAQ,KAAKC,EAAE,KAG3BF,EAAM,GACdF,EAAS,aAAYJ,EAAWM,EAAM,aAAaN,EAAWM,EAAM,QAG5DA,EAAM,KACdK,EAAMA,EAAId,QAAQ,MAAQ,YAAWG,EAAWM,EAAM,KAAOM,EAAMP,EAAKqB,qBACxEtB,EAAQgB,IAAU,QAEVd,EAAM,GACdF,EAAQ,MAGAE,EAAM,KAAOA,EAAM,KAC3BE,EAAI,KAAOF,EAAM,IAAMA,EAAM,IAAIW,OAAUX,EAAM,IAAI,IAAM,EAAI,GAC/DF,EAAQ,IAAII,EAAE,IAAMP,EAAMK,EAAM,KAAOA,EAAM,IAAKM,GAAS,KAAKJ,EAAE,KAG1DF,EAAM,IACdF,EAAQ,SAASJ,EAAWM,EAAM,KAAK,WAG/BA,EAAM,KAAOA,EAAM,MAC3BF,EAAQU,EAAIR,EAAM,KAAO,QAE1BK,GAAON,EACPM,GAAOP,EAGR,OACCO,EACAT,EACE0B,UAAUf,GAEVhB,QAAQ,cAAgBwB,GACxBU,OAAOC,cAAcX,EAAEO,UAAU,EAAGP,EAAEJ,OAAS,KAEjDG,KACCvB,QAAQ,aAAc"}
@@ -0,0 +1,2 @@
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).snarkdown=n()}(this,function(){var e={"":["<em>","</em>"],_:["<strong>","</strong>"],"*":["<strong>","</strong>"],"~":["<s>","</s>"],"\n":["<br />"]," ":["<br />"],"-":["<hr />"]};function n(e){return e.replace(RegExp("^"+(e.match(/^(\t| )+/)||"")[0],"gm"),"")}function r(e){return(e+"").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}return function t(o,a){var c,s,l,g,u,p=/((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,i=[],f="",d=a||{},m=0;function h(n){var r=e[n[1]||""],t=i[i.length-1]==n;return r?r[1]?(t?i.pop():i.push(n),r[0|t]):r[0]:n}function $(){for(var e="";i.length;)e+=h(i[i.length-1]);return e}for(o=(o=o.replace(/\\([*_[\]{}`<>()#+\-!|.])/g,function(e){return"&%"+e.charCodeAt(1)+"%;"})).replace(/^\[(.+?)\]:\s*(.+)$/gm,function(e,n,r){return d[n.toLowerCase()]=r,""}).replace(/^\n+|\n+$/g,"");l=p.exec(o);)s=o.substring(m,l.index),m=p.lastIndex,c=l[0],s.match(/[^\\](\\\\)*\\$/)||((u=l[3]||l[4])?c='<pre class="code '+(l[4]?"poetry":l[2].toLowerCase())+'"><code'+(l[2]?' class="language-'+l[2].toLowerCase()+'"':"")+">"+n(r(u).replace(/^\n+|\n+$/g,""))+"</code></pre>":(u=l[6])?(u.match(/\./)&&(l[5]=l[5].replace(/^\d+/gm,"")),g=t(n(l[5].replace(/^\s*[>*+.-]/gm,""))),">"==u?u="blockquote":(u=u.match(/\./)?"ol":"ul",g=g.replace(/^(.*)(\n|$)/gm,"<li>$1</li>")),c="<"+u+">"+g+"</"+u+">"):l[8]?c='<img src="'+r(l[8])+'" alt="'+r(l[7])+'">':l[10]?(f=f.replace("<a>",'<a href="'+r(l[11]||d[s.toLowerCase()])+'">'),c=$()+"</a>"):l[9]?c="<a>":l[12]||l[14]?c="<"+(u="h"+(l[14]?l[14].length:l[13]>"="?1:2))+">"+t(l[12]||l[15],d)+"</"+u+">":l[16]?c="<code>"+r(l[16])+"</code>":(l[17]||l[1])&&(c=h(l[17]||"--"))),f+=s,f+=c;return(f+o.substring(m).replace(/&%[0-9]+%;/g,function(e){return String.fromCharCode(+e.substring(2,e.length-2))})+$()).replace(/^\n+|\n+$/g,"")}});
2
+ //# sourceMappingURL=snarkdown.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snarkdown.umd.js","sources":["../src/index.js"],"sourcesContent":["const TAGS = {\n\t'': ['<em>','</em>'],\n\t_: ['<strong>','</strong>'],\n\t'*': ['<strong>','</strong>'],\n\t'~': ['<s>','</s>'],\n\t'\\n': ['<br />'],\n\t' ': ['<br />'],\n\t'-': ['<hr />']\n};\n\n/** Outdent a string based on the first indented line's leading whitespace\n *\t@private\n */\nfunction outdent(str) {\n\treturn str.replace(RegExp('^'+(str.match(/^(\\t| )+/) || '')[0], 'gm'), '');\n}\n\n/** Encode special attribute characters to HTML entities in a String.\n *\t@private\n */\nfunction encodeAttr(str) {\n\treturn (str+'').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n}\n\n/** Parse Markdown into an HTML String. */\nexport default function parse(md, prevLinks) {\n\tlet tokenizer = /((?:^|\\n+)(?:\\n---+|\\* \\*(?: \\*)+)\\n)|(?:^``` *(\\w*)\\n([\\s\\S]*?)\\n```$)|((?:(?:^|\\n+)(?:\\t| {2,}).+)+\\n*)|((?:(?:^|\\n)([>*+-]|\\d+\\.)\\s+.*)+)|(?:!\\[([^\\]]*?)\\]\\(([^)]+?)\\))|(\\[)|(\\](?:\\(([^)]+?)\\))?)|(?:(?:^|\\n+)([^\\s].*)\\n(-{3,}|={3,})(?:\\n+|$))|(?:(?:^|\\n+)(#{1,6})\\s*(.+)(?:\\n+|$))|(?:`([^`].*?)`)|( \\n\\n*|\\n{2,}|__|\\*\\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,\n\t\tcontext = [],\n\t\tout = '',\n\t\tlinks = prevLinks || {},\n\t\tlast = 0,\n\t\tchunk, prev, token, inner, t;\n\t// escape special characters\n\tmd = md.replace(/\\\\([*_[\\]{}`<>()#+\\-!|.])/g, m => `&%${m.charCodeAt(1)}%;`);\n\n\tfunction tag(token) {\n\t\tlet desc = TAGS[token[1] || ''];\n\t\tlet end = context[context.length-1] == token;\n\t\tif (!desc) return token;\n\t\tif (!desc[1]) return desc[0];\n\t\tif (end) context.pop();\n\t\telse context.push(token);\n\t\treturn desc[end|0];\n\t}\n\n\tfunction flush() {\n\t\tlet str = '';\n\t\twhile (context.length) str += tag(context[context.length-1]);\n\t\treturn str;\n\t}\n\n\tmd = md.replace(/^\\[(.+?)\\]:\\s*(.+)$/gm, (s, name, url) => {\n\t\tlinks[name.toLowerCase()] = url;\n\t\treturn '';\n\t}).replace(/^\\n+|\\n+$/g, '');\n\n\twhile ( (token=tokenizer.exec(md)) ) {\n\t\tprev = md.substring(last, token.index);\n\t\tlast = tokenizer.lastIndex;\n\t\tchunk = token[0];\n\t\tif (prev.match(/[^\\\\](\\\\\\\\)*\\\\$/)) {\n\t\t\t// escaped\n\t\t}\n\t\t// Code/Indent blocks:\n\t\telse if (t = (token[3] || token[4])) {\n\t\t\tchunk = '<pre class=\"code '+(token[4]?'poetry':token[2].toLowerCase())+'\"><code'+(token[2] ? ` class=\"language-${token[2].toLowerCase()}\"` : '')+'>'+outdent(encodeAttr(t).replace(/^\\n+|\\n+$/g, ''))+'</code></pre>';\n\t\t}\n\t\t// > Quotes, -* lists:\n\t\telse if (t = token[6]) {\n\t\t\tif (t.match(/\\./)) {\n\t\t\t\ttoken[5] = token[5].replace(/^\\d+/gm, '');\n\t\t\t}\n\t\t\tinner = parse(outdent(token[5].replace(/^\\s*[>*+.-]/gm, '')));\n\t\t\tif (t=='>') t = 'blockquote';\n\t\t\telse {\n\t\t\t\tt = t.match(/\\./) ? 'ol' : 'ul';\n\t\t\t\tinner = inner.replace(/^(.*)(\\n|$)/gm, '<li>$1</li>');\n\t\t\t}\n\t\t\tchunk = '<'+t+'>' + inner + '</'+t+'>';\n\t\t}\n\t\t// Images:\n\t\telse if (token[8]) {\n\t\t\tchunk = `<img src=\"${encodeAttr(token[8])}\" alt=\"${encodeAttr(token[7])}\">`;\n\t\t}\n\t\t// Links:\n\t\telse if (token[10]) {\n\t\t\tout = out.replace('<a>', `<a href=\"${encodeAttr(token[11] || links[prev.toLowerCase()])}\">`);\n\t\t\tchunk = flush() + '</a>';\n\t\t}\n\t\telse if (token[9]) {\n\t\t\tchunk = '<a>';\n\t\t}\n\t\t// Headings:\n\t\telse if (token[12] || token[14]) {\n\t\t\tt = 'h' + (token[14] ? token[14].length : (token[13]>'=' ? 1 : 2));\n\t\t\tchunk = '<'+t+'>' + parse(token[12] || token[15], links) + '</'+t+'>';\n\t\t}\n\t\t// `code`:\n\t\telse if (token[16]) {\n\t\t\tchunk = '<code>'+encodeAttr(token[16])+'</code>';\n\t\t}\n\t\t// Inline formatting: *em*, **strong** & friends\n\t\telse if (token[17] || token[1]) {\n\t\t\tchunk = tag(token[17] || '--');\n\t\t}\n\t\tout += prev;\n\t\tout += chunk;\n\t}\n\n\treturn (\n\t\tout +\n\t\tmd\n\t\t\t.substring(last)\n\t\t\t// unscape special characters\n\t\t\t.replace(/&%[0-9]+%;/g, (m) =>\n\t\t\t\tString.fromCharCode(+m.substring(2, m.length - 2))\n\t\t\t) +\n\t\tflush()\n\t).replace(/^\\n+|\\n+$/g, '');\n}\n"],"names":["TAGS","_","*","~","\n"," ","-","outdent","str","replace","RegExp","match","encodeAttr","parse","md","prevLinks","chunk","prev","token","inner","t","tokenizer","context","out","links","last","tag","desc","end","length","pop","push","flush","m","charCodeAt","s","name","url","toLowerCase","exec","substring","index","lastIndex","String","fromCharCode"],"mappings":"kLAAA,IAAMA,EAAO,CACZ,GAAI,CAAC,OAAO,SACZC,EAAG,CAAC,WAAW,aACfC,IAAK,CAAC,WAAW,aACjBC,IAAK,CAAC,MAAM,QACZC,KAAM,CAAC,UACPC,IAAK,CAAC,UACNC,IAAK,CAAC,WAMP,SAASC,EAAQC,GAChB,OAAOA,EAAIC,QAAQC,OAAO,KAAKF,EAAIG,MAAM,aAAe,IAAI,GAAI,MAAO,IAMxE,SAASC,EAAWJ,GACnB,OAAQA,EAAI,IAAIC,QAAQ,KAAM,UAAUA,QAAQ,KAAM,QAAQA,QAAQ,KAAM,wBAIrDI,EAAMC,EAAIC,GACjC,IAKCC,EAAOC,EAAMC,EAAOC,EAAOC,EALxBC,EAAY,kWACfC,EAAU,GACVC,EAAM,GACNC,EAAQT,GAAa,GACrBU,EAAO,EAKR,SAASC,EAAIR,GACZ,IAAIS,EAAO3B,EAAKkB,EAAM,IAAM,IACxBU,EAAMN,EAAQA,EAAQO,OAAO,IAAMX,EACvC,OAAKS,EACAA,EAAK,IACNC,EAAKN,EAAQQ,MACZR,EAAQS,KAAKb,GACXS,EAAS,EAAJC,IAHSD,EAAK,GADRT,EAOnB,SAASc,IAER,IADA,IAAIxB,EAAM,GACHc,EAAQO,QAAQrB,GAAOkB,EAAIJ,EAAQA,EAAQO,OAAO,IACzD,OAAOrB,EAQR,IALAM,GAlBAA,EAAKA,EAAGL,QAAQ,6BAA8B,SAAAwB,cAAUA,EAAEC,WAAW,WAkB7DzB,QAAQ,wBAAyB,SAAC0B,EAAGC,EAAMC,GAElD,OADAb,EAAMY,EAAKE,eAAiBD,EACrB,KACL5B,QAAQ,aAAc,IAEhBS,EAAMG,EAAUkB,KAAKzB,IAC7BG,EA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AU,EAAGP,EAAEJ,OAAS,MAEjDG,KACCvB,QAAQ,aAAc"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@datawrapper/snarkdown",
3
+ "description": "Transform Markdown into HTML.",
4
+ "version": "2.0.1",
5
+ "main": "./dist/snarkdown.js",
6
+ "module": "./dist/snarkdown.es.js",
7
+ "modern": "./dist/snarkdown.modern.js",
8
+ "umd:main": "./dist/snarkdown.umd.js",
9
+ "unpkg": "./dist/snarkdown.umd.js",
10
+ "types": "./snarkdown.d.ts",
11
+ "scripts": {
12
+ "build": "microbundle",
13
+ "dev": "microbundle watch",
14
+ "test": "eslint src test && NODE_ENV=test mocha --compilers @babel/register",
15
+ "prepublish": "npm run -s build",
16
+ "release": "npm run -s build && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
17
+ },
18
+ "authors": [
19
+ "Jason Miller <jason@developit.ca>"
20
+ ],
21
+ "files": [
22
+ "src",
23
+ "dist",
24
+ "snarkdown.d.ts"
25
+ ],
26
+ "homepage": "https://github.com/developit/snarkdown",
27
+ "repository": "developit/snarkdown",
28
+ "license": "MIT",
29
+ "keywords": [
30
+ "markdown",
31
+ "gfm",
32
+ "md",
33
+ "html",
34
+ "parser"
35
+ ],
36
+ "devDependencies": {
37
+ "@babel/preset-env": "^7.11.5",
38
+ "@babel/register": "^7.11.5",
39
+ "chai": "^3.5.0",
40
+ "eslint": "^7.7.0",
41
+ "eslint-config-developit": "^1.2.0",
42
+ "microbundle": "^0.12.0",
43
+ "mocha": "^5.1.1",
44
+ "npm-merge-driver-install": "^1.1.1"
45
+ },
46
+ "eslintConfig": {
47
+ "extends": "developit",
48
+ "env": {
49
+ "browser": true,
50
+ "mocha": true,
51
+ "node": true,
52
+ "es6": true
53
+ },
54
+ "globals": {
55
+ "expect": true
56
+ },
57
+ "rules": {
58
+ "jest/valid-expect": 0,
59
+ "no-console": 1,
60
+ "no-cond-assign": 0,
61
+ "no-regex-spaces": 0
62
+ }
63
+ },
64
+ "babel": {
65
+ "env": {
66
+ "test": {
67
+ "presets": [
68
+ "@babel/preset-env"
69
+ ]
70
+ }
71
+ }
72
+ }
73
+ }
package/snarkdown.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ declare module "snarkdown" {
2
+ interface Links {
3
+ [index: string]: string;
4
+ }
5
+ export default function (urlStr: string, prevLinks?: Links): string;
6
+ }
package/src/index.js ADDED
@@ -0,0 +1,120 @@
1
+ const TAGS = {
2
+ '': ['<em>','</em>'],
3
+ _: ['<strong>','</strong>'],
4
+ '*': ['<strong>','</strong>'],
5
+ '~': ['<s>','</s>'],
6
+ '\n': ['<br />'],
7
+ ' ': ['<br />'],
8
+ '-': ['<hr />']
9
+ };
10
+
11
+ /** Outdent a string based on the first indented line's leading whitespace
12
+ * @private
13
+ */
14
+ function outdent(str) {
15
+ return str.replace(RegExp('^'+(str.match(/^(\t| )+/) || '')[0], 'gm'), '');
16
+ }
17
+
18
+ /** Encode special attribute characters to HTML entities in a String.
19
+ * @private
20
+ */
21
+ function encodeAttr(str) {
22
+ return (str+'').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
23
+ }
24
+
25
+ /** Parse Markdown into an HTML String. */
26
+ export default function parse(md, prevLinks) {
27
+ let tokenizer = /((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)|<[a-zA-Z][^>]*>/gm,
28
+ context = [],
29
+ out = '',
30
+ links = prevLinks || {},
31
+ last = 0,
32
+ chunk, prev, token, inner, t;
33
+ // escape special characters
34
+ md = md.replace(/\\([*_[\]{}`<>()#+\-!|.])/g, m => `&%${m.charCodeAt(1)}%;`);
35
+
36
+ function tag(token) {
37
+ let desc = TAGS[token[1] || ''];
38
+ let end = context[context.length-1] == token;
39
+ if (!desc) return token;
40
+ if (!desc[1]) return desc[0];
41
+ if (end) context.pop();
42
+ else context.push(token);
43
+ return desc[end|0];
44
+ }
45
+
46
+ function flush() {
47
+ let str = '';
48
+ while (context.length) str += tag(context[context.length-1]);
49
+ return str;
50
+ }
51
+
52
+ md = md.replace(/^\[(.+?)\]:\s*(.+)$/gm, (s, name, url) => {
53
+ links[name.toLowerCase()] = url;
54
+ return '';
55
+ }).replace(/^\n+|\n+$/g, '');
56
+
57
+ while ( (token=tokenizer.exec(md)) ) {
58
+ prev = md.substring(last, token.index);
59
+ last = tokenizer.lastIndex;
60
+ chunk = token[0];
61
+ if (prev.match(/[^\\](\\\\)*\\$/)) {
62
+ // escaped
63
+ }
64
+ // Code/Indent blocks:
65
+ else if (t = (token[3] || token[4])) {
66
+ chunk = '<pre class="code '+(token[4]?'poetry':token[2].toLowerCase())+'"><code'+(token[2] ? ` class="language-${token[2].toLowerCase()}"` : '')+'>'+outdent(encodeAttr(t).replace(/^\n+|\n+$/g, ''))+'</code></pre>';
67
+ }
68
+ // > Quotes, -* lists:
69
+ else if (t = token[6]) {
70
+ if (t.match(/\./)) {
71
+ token[5] = token[5].replace(/^\d+/gm, '');
72
+ }
73
+ inner = parse(outdent(token[5].replace(/^\s*[>*+.-]/gm, '')));
74
+ if (t=='>') t = 'blockquote';
75
+ else {
76
+ t = t.match(/\./) ? 'ol' : 'ul';
77
+ inner = inner.replace(/^(.*)(\n|$)/gm, '<li>$1</li>');
78
+ }
79
+ chunk = '<'+t+'>' + inner + '</'+t+'>';
80
+ }
81
+ // Images:
82
+ else if (token[8]) {
83
+ chunk = `<img src="${encodeAttr(token[8])}" alt="${encodeAttr(token[7])}">`;
84
+ }
85
+ // Links:
86
+ else if (token[10]) {
87
+ out = out.replace('<a>', `<a href="${encodeAttr(token[11] || links[prev.toLowerCase()])}">`);
88
+ chunk = flush() + '</a>';
89
+ }
90
+ else if (token[9]) {
91
+ chunk = '<a>';
92
+ }
93
+ // Headings:
94
+ else if (token[12] || token[14]) {
95
+ t = 'h' + (token[14] ? token[14].length : (token[13]>'=' ? 1 : 2));
96
+ chunk = '<'+t+'>' + parse(token[12] || token[15], links) + '</'+t+'>';
97
+ }
98
+ // `code`:
99
+ else if (token[16]) {
100
+ chunk = '<code>'+encodeAttr(token[16])+'</code>';
101
+ }
102
+ // Inline formatting: *em*, **strong** & friends
103
+ else if (token[17] || token[1]) {
104
+ chunk = tag(token[17] || '--');
105
+ }
106
+ out += prev;
107
+ out += chunk;
108
+ }
109
+
110
+ return (
111
+ out +
112
+ md
113
+ .substring(last)
114
+ // unscape special characters
115
+ .replace(/&%[0-9]+%;/g, (m) =>
116
+ String.fromCharCode(+m.substring(2, m.length - 2))
117
+ ) +
118
+ flush()
119
+ ).replace(/^\n+|\n+$/g, '');
120
+ }