diff options
Diffstat (limited to 'packages/gitbook-markdown')
-rw-r--r-- | packages/gitbook-markdown/lib/page.js | 7 | ||||
-rw-r--r-- | packages/gitbook-markdown/test/page.js | 8 |
2 files changed, 11 insertions, 4 deletions
diff --git a/packages/gitbook-markdown/lib/page.js b/packages/gitbook-markdown/lib/page.js index 3a130ea..de0ed98 100644 --- a/packages/gitbook-markdown/lib/page.js +++ b/packages/gitbook-markdown/lib/page.js @@ -8,13 +8,14 @@ var RAW_START = "{% raw %}"; var RAW_END = "{% endraw %}"; var CODEBLOCKS = { md: /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/, - fences: /`([^`]+)`/g + fences: /(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm }; function preparePage(src) { // GFM Fences - src = src.replace(CODEBLOCKS.fences, function(all) { - return RAW_START+all+RAW_END; + src = src.replace(CODEBLOCKS.fences, function(wholeMatch, m1, m2, m3, m4) { + wholeMatch = wholeMatch.slice(m1.length); + return m1+RAW_START+wholeMatch+RAW_END; }); // Normal codeblocks diff --git a/packages/gitbook-markdown/test/page.js b/packages/gitbook-markdown/test/page.js index 8486435..67c209d 100644 --- a/packages/gitbook-markdown/test/page.js +++ b/packages/gitbook-markdown/test/page.js @@ -20,8 +20,14 @@ describe('Page parsing', function() { assert(LEXED[0].content); }); - it('should escape codeblocks in preparation', function() { + it('should escape codeblocks in preparation (1)', function() { assert.equal(page.prepare("Hello `world`"), "Hello {% raw %}`world`{% endraw %}"); + assert.equal(page.prepare("Hello `world test`"), "Hello {% raw %}`world test`{% endraw %}"); + assert.equal(page.prepare("Hello ```world test```"), "Hello {% raw %}```world test```{% endraw %}"); + assert.equal(page.prepare("Hello\n```js\nworld test\n```\n"), "Hello\n{% raw %}```js\nworld test\n```{% endraw %}\n"); + }); + + it('should escape codeblocks in preparation (2)', function() { assert.equal( page.prepare("Hello\n\n\n\tworld\n\thello\n\n\ntest"), "Hello\n{% raw %}\n\n\tworld\n\thello\n\n\n{% endraw %}test" |