diff options
Diffstat (limited to 'packages/gitbook-markdown/lib/page.js')
-rw-r--r-- | packages/gitbook-markdown/lib/page.js | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/packages/gitbook-markdown/lib/page.js b/packages/gitbook-markdown/lib/page.js index de0ed98..b7af03b 100644 --- a/packages/gitbook-markdown/lib/page.js +++ b/packages/gitbook-markdown/lib/page.js @@ -3,30 +3,26 @@ var kramed = require('kramed'); var hljs = require('highlight.js'); var lnormalize = require('./utils/lang').normalize; +var mdRenderer = require('kramed-markdown-renderer'); var RAW_START = "{% raw %}"; var RAW_END = "{% endraw %}"; -var CODEBLOCKS = { - md: /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/, - fences: /(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm -}; function preparePage(src) { - // GFM Fences - src = src.replace(CODEBLOCKS.fences, function(wholeMatch, m1, m2, m3, m4) { - wholeMatch = wholeMatch.slice(m1.length); - return m1+RAW_START+wholeMatch+RAW_END; - }); + var renderer = mdRenderer(); + + var escape = function(func, code, lang, escaped) { + return RAW_START+func(code, lang, escaped)+RAW_END; + }; - // Normal codeblocks - src += "~0"; - src = src.replace(CODEBLOCKS.md, function(all, m1, m2) { - all = all.slice(0, -m2.length); - return RAW_START+all+RAW_END+m2; + renderer.code = _.wrap(renderer.code, escape); + renderer.codespan = _.wrap(renderer.codespan, escape); + + var options = _.extend({}, kramed.defaults, { + renderer: renderer }); - src = src.replace(/~0/, ""); - return src; + return kramed(src, options); } function parsePage(src) { |