diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-04-02 18:19:10 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 15:00:44 +0100 |
commit | 2017cdf1390b4a98615c29880061875f426ea19c (patch) | |
tree | 35399e3aa77c7fd62894edd39fdb7a931175b223 | |
parent | d32e72acd2ffe36488c2f6b458725999149ca6ca (diff) | |
download | gitbook-2017cdf1390b4a98615c29880061875f426ea19c.zip gitbook-2017cdf1390b4a98615c29880061875f426ea19c.tar.gz gitbook-2017cdf1390b4a98615c29880061875f426ea19c.tar.bz2 |
Fix code blocks annotation
-rw-r--r-- | packages/gitbook-markdown/lib/annotate_blocks.js | 11 | ||||
-rw-r--r-- | packages/gitbook-markdown/lib/annotate_inline.js | 11 | ||||
-rw-r--r-- | packages/gitbook-markdown/test/page.js | 4 |
3 files changed, 14 insertions, 12 deletions
diff --git a/packages/gitbook-markdown/lib/annotate_blocks.js b/packages/gitbook-markdown/lib/annotate_blocks.js index cb8ada8..3f329cb 100644 --- a/packages/gitbook-markdown/lib/annotate_blocks.js +++ b/packages/gitbook-markdown/lib/annotate_blocks.js @@ -16,9 +16,8 @@ var rules = { newline: /^\n+/, table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/, paragraph: /^((?:[^\n]+\n?(?! *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\2 *(?:\n+|$)|( *)((?:[*+-]|\d+\.)) [\s\S]+?(?:\n+(?=\3?(?:[-*_] *){3,}(?:\n+|$))|\n+(?= *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$))|\n{2,}(?! )(?!\1(?:[*+-]|\d+\.) )\n*|\s*$)|( *[-*_]){3,} *(?:\n+|$)| *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)|([^\n]+)\n *(=|-){2,} *(?:\n+|$)|( *>[^\n]+(\n(?! *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$))[^\n]+)*\n*)+|<(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b| *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)| *(\${2,}) *([\s\S]+?)\s*\1 *(?:\n+|$)))+)\n*/, text: /^[^\n]+/, - math: /^ *(\${2,}) *([\s\S]+?)\s*\1 *(?:\n+|$)/, - rawStart: /^{%([\s]*)raw([\s]*)%}/, - rawEnd: /^{%([\s]*)endraw([\s]*)%}/ + //rawStart: /^{%([\s]*)raw([\s]*)%}/, + //rawEnd: /^{%([\s]*)endraw([\s]*)%}/ // These are lower level, ignore them //bullet: /(?:[*+-]|\d+\.)/, //item: /^( *)((?:[*+-]|\d+\.)) [^\n]*(?:\n(?!\1(?:[*+-]|\d+\.) )[^\n]*)*/gm, @@ -27,9 +26,9 @@ var rules = { newline: /^\n+/, // List of all the regexes we want to run var ruleTypes = [ -'rawStart', 'rawEnd', 'newline', 'code', 'fences', 'footnote', 'math', 'heading', -'nptable', 'lheading', 'hr', 'blockquote', 'list', -'html', 'def', 'table', 'paragraph', 'text', + 'newline', 'code', 'fences', 'footnote', 'heading', + 'nptable', 'lheading', 'hr', 'blockquote', 'list', + 'html', 'def', 'table', 'paragraph', 'text', ]; // Mapping if rule type is different from token type diff --git a/packages/gitbook-markdown/lib/annotate_inline.js b/packages/gitbook-markdown/lib/annotate_inline.js index 376b092..469f4d8 100644 --- a/packages/gitbook-markdown/lib/annotate_inline.js +++ b/packages/gitbook-markdown/lib/annotate_inline.js @@ -15,19 +15,18 @@ var rules = { code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/, br: /^ {2,}\n(?!\s*$)/, del: /^~~(?=\S)([\s\S]*?\S)~~/, - text: /^[\s\S]+?(?=[\\<!\[_*`$~]|https?:\/\/| {2,}\n|$)/, - math: /^\$\$\s*([\s\S]*?[^\$])\s*\$\$(?!\$)/, + text: /^[\s\S]+?(?=[\\<!\[_*`$~]|{%([\s]*)raw([\s]*)%}|{%([\s]*)endraw([\s]*)|https?:\/\/| {2,}\n|$)/, rawStart: /^{%([\s]*)raw([\s]*)%}/, - rawEnd: /[\s\S]*{%([\s]*)endraw([\s]*)%}/ // /^{%([\s]*)endraw([\s]*)%}/ + rawEnd: /^{%([\s]*)endraw([\s]*)%}/ ///[\s\S]*{%([\s]*)endraw([\s]*)%}/ //_inside: /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/, //_href: /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/ }; // List of all the regexes we want to run var ruleTypes = [ -'escape', 'rawStart', 'rawEnd', 'autolink', 'url', 'tag', 'link', 'reflink', -'nolink', 'reffn', 'strong', 'em', 'code', 'br', -'del', 'text', 'math' + 'escape', 'autolink', 'url', 'tag', 'link', 'reflink', + 'nolink', 'reffn', 'strong', 'em', 'code', 'br', + 'del', 'rawStart', 'rawEnd', 'text' ]; // Mapping if rule type is different from token type diff --git a/packages/gitbook-markdown/test/page.js b/packages/gitbook-markdown/test/page.js index c7384b6..5c12692 100644 --- a/packages/gitbook-markdown/test/page.js +++ b/packages/gitbook-markdown/test/page.js @@ -55,6 +55,10 @@ describe('Page parsing', function() { page.prepare('{% raw %}Hello {{ "Bonjour" }} {% raw %}{% endraw %}```test```'), '{% raw %}Hello {{ "Bonjour" }} {% raw %}{% endraw %}{% raw %}```test```{% endraw %}' ); + assert.equal( + page.prepare('```{% raw %}Hello {{ "Bonjour" }} {% raw %}```'), + '{% raw %}```{% raw %}Hello {{ "Bonjour" }} {% raw %}```{% endraw %}' + ); }); it('should not process math', function() { |