diff --git a/bin/remarkable.js b/bin/remarkable.js index c359d7a..5622250 100755 --- a/bin/remarkable.js +++ b/bin/remarkable.js @@ -61,7 +61,10 @@ readFile(options.file, 'utf8', function (error, input) { process.exit(1); } - md = new Remarkable(); + md = new Remarkable({ + html: true, + xhtml: true + }); try { output = md.render(input); diff --git a/lib/common/html_re.js b/lib/common/html_re.js index c58213a..f059e22 100644 --- a/lib/common/html_re.js +++ b/lib/common/html_re.js @@ -44,10 +44,10 @@ var open_tag = replace(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/) var close_tag = /<\/[A-Za-z][A-Za-z0-9]*\s*>/; var comment = //; var processing = /<[?].*?[?]>/; -var declaration = /]*>/; +var declaration = /]*>/; var cdata = /])*\]\]>/; -var HTML_TAG_RE = replace(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/, 'i') +var HTML_TAG_RE = replace(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/) ('open_tag', open_tag) ('close_tag', close_tag) ('comment', comment) diff --git a/lib/lexer_block/htmlblock.js b/lib/lexer_block/htmlblock.js index db095e6..c631e52 100644 --- a/lib/lexer_block/htmlblock.js +++ b/lib/lexer_block/htmlblock.js @@ -66,7 +66,7 @@ module.exports = function htmlblock(state, startLine, endLine, silent) { } state.tokens.push({ - type: 'html', + type: 'htmlblock', content: getLines(state, startLine, nextLine, 0, true) }); diff --git a/lib/lexer_inline.js b/lib/lexer_inline.js index 856776d..1dc68cb 100644 --- a/lib/lexer_inline.js +++ b/lib/lexer_inline.js @@ -19,6 +19,7 @@ rules.push(require('./lexer_inline/backticks')); // // rules.push(require('./lexer_inline/autolink')); +rules.push(require('./lexer_inline/htmltag')); rules.push(require('./lexer_inline/entity')); rules.push(require('./lexer_inline/escape_html_char')); diff --git a/lib/lexer_inline/autolink.js b/lib/lexer_inline/autolink.js index a9ab35e..a02e152 100644 --- a/lib/lexer_inline/autolink.js +++ b/lib/lexer_inline/autolink.js @@ -22,7 +22,7 @@ module.exports = function autolink(state) { linkMatch = tail.match(AUTOLINK_RE); if (linkMatch) { - if (url_schemas.indexOf(linkMatch[1]) < 0) { return false; } + if (url_schemas.indexOf(linkMatch[1].toLowerCase()) < 0) { return false; } state.push({ type: 'link_open', diff --git a/lib/lexer_inline/htmltag.js b/lib/lexer_inline/htmltag.js new file mode 100644 index 0000000..c2489cb --- /dev/null +++ b/lib/lexer_inline/htmltag.js @@ -0,0 +1,52 @@ +// Process html tags + +'use strict'; + + +var HTML_TAG_RE = require('../common/html_re').HTML_TAG_RE; + + +function isLetter(ch) { + /*eslint no-bitwise:0*/ + var lc = ch | 0x20; // to lower case + return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */); +} + + +module.exports = function htmltag(state) { + var ch, match, max, pos = state.pos; + + if (!state.options.html) { return false; } + + // Check start + max = state.posMax; + if (state.src.charCodeAt(pos) !== 0x3C/* < */ || + pos + 2 >= max) { + return false; + } + + // Quick fail on second char + ch = state.src.charCodeAt(pos + 1); + if (ch !== 0x21/* ! */ && + ch !== 0x3F/* ? */ && + ch !== 0x2F/* / */ && + !isLetter(ch)) { + return false; + } +// console.log(HTML_TAG_RE) + + match = state.src.slice(pos).match(HTML_TAG_RE); + if (!match) { return false; } + +// console.log('--------') +// console.log(state.src.slice(pos)) +// console.log(match) + + state.push({ + type: 'htmltag', + content: state.src.slice(pos, pos + match[0].length) + }); +//console.log(state.tokens) + state.pos += match[0].length; + return true; +}; diff --git a/lib/renderer.js b/lib/renderer.js index 8bfafb2..9aa8f8b 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -149,7 +149,10 @@ rules.text = function (tokens, idx /*, options*/) { }; -rules.html = function (tokens, idx /*, options*/) { +rules.htmlblock = function (tokens, idx /*, options*/) { + return tokens[idx].content; +}; +rules.htmltag = function (tokens, idx /*, options*/) { return tokens[idx].content; }; diff --git a/test/fixtures/stmd/bad.txt b/test/fixtures/stmd/bad.txt index de9ac88..2af7c52 100644 --- a/test/fixtures/stmd/bad.txt +++ b/test/fixtures/stmd/bad.txt @@ -63,26 +63,9 @@ src line: 1406 error: -
*Markdown*
-[Foo bar]:
+[Foo bar]:
[Foo bar]
@@ -673,20 +656,6 @@ error:\*emphasis*
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 3694 - -. - -. - -. - -error: - - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 3704 @@ -718,20 +687,6 @@ error:[foo]: /bar* "ti*tle"
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 3791 - -. - -. - -. - -error: - - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 3797 @@ -763,20 +718,6 @@ error:[foo]: /föö "föö"
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 3954 - -. -` -. - -. - -error: - -` - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 4095 @@ -985,34 +926,6 @@ error:_foo [bar_](/url)
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 4196 - -. -** -. - -. - -error: - -**<a href="**">
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 4202 - -. -__ -. - -. - -error: - -__<a href="__">
- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 4208 @@ -1841,20 +1754,6 @@ error: "title" ) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 4898 - -. -[foo[foo
[foo <bar attr="](baz)">
- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 4927 @@ -2435,7 +2334,7 @@ src line: 5271 error: -![foo](<url>)
+![foo](
[foo]: /url "title"
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5464 - -. -<MAILTO:FOO@BAR.BAZ>
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5627 - -. -foo
-. - -error: - -foo <!-- this is a -comment - with hyphen -->
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5739 - -. -foo -. -foo
-. - -error: - -foo <?php echo $a; ?>
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5747 - -. -foo -. -foo
-. - -error: - -foo <!ELEMENT br EMPTY>
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5755 - -. -foo &<]]> -. -foo &<]]>
-. - -error: - -foo <![CDATA[>&<]]>
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5763 - -. - -. - -. - -error: - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5771 - -. - -. - -. - -error: - - - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 5839 @@ -2872,37 +2591,3 @@ error: bar* -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5873 - -. - -. - -. - -error: - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 5881 - -. - -. - -. - -error: - - - - diff --git a/test/fixtures/stmd/good.txt b/test/fixtures/stmd/good.txt index ebccd9c..92e3d4e 100644 --- a/test/fixtures/stmd/good.txt +++ b/test/fixtures/stmd/good.txt @@ -1218,6 +1218,17 @@ bar *foo* . +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 1534 + +. +&MadeUpEntity;
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 3791 + +. + +. + +. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 3811 @@ -2858,6 +2887,15 @@ src line: 3946 . +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 3954 + +. +` +. + +. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 3963 @@ -2876,6 +2914,24 @@ src line: 3969`foo
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 4196 + +. +** +. + +. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 4202 + +. +__ +. + +. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 4220 @@ -3130,6 +3186,15 @@ src line: 4889[link] (/uri)
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 4898 + +. +[foo[foo
foo@bar.baz.com
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5627 + +. +<a href='bar'title=title>
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5705 + +. +</a href="foo">
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5723 + +. +foo +. +foo
+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 5731 @@ -3312,6 +3448,51 @@ foofoo <!-- not a comment -- two hyphens -->
. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5739 + +. +foo +. +foo
+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5747 + +. +foo +. +foo
+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5755 + +. +foo &<]]> +. +foo &<]]>
+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5763 + +. + +. + +. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 5771 + +. + +. + +. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 5777 @@ -3396,6 +3577,28 @@ span`code\ span