gitbook-markdown
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -6,25 +6,22 @@ var _ = require('lodash'); | ||
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: /`([^`]+)`/g | ||
}; | ||
function preparePage(src) { | ||
// GFM Fences | ||
src = src.replace(CODEBLOCKS.fences, function(all) { | ||
return RAW_START+all+RAW_END; | ||
}); | ||
var renderer = mdRenderer(); | ||
// 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; | ||
var escape = function(func, code, lang, escaped) { | ||
return RAW_START+func(code, lang, escaped)+RAW_END; | ||
}; | ||
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); | ||
} | ||
@@ -31,0 +28,0 @@ |
{ | ||
"name": "gitbook-markdown", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"homepage": "https://www.gitbook.com", | ||
@@ -11,2 +11,3 @@ "description": "Parse markdown content for gitbook", | ||
"kramed-text-renderer": "0.2.1", | ||
"kramed-markdown-renderer": "0.1.2", | ||
"highlight.js": "8.4.0" | ||
@@ -13,0 +14,0 @@ }, |
@@ -23,13 +23,20 @@ var fs = require('fs'); | ||
it('should escape codeblocks in preparation', function() { | ||
assert.equal(page.prepare("Hello `world`"), "Hello {% raw %}`world`{% endraw %}"); | ||
it('should escape codeblocks in preparation (1)', function() { | ||
assert.equal(page.prepare("Hello `world`"), "\nHello {% raw %}`world`{% endraw %}\n"); | ||
assert.equal(page.prepare("Hello `world test`"), "\nHello {% raw %}`world test`{% endraw %}\n"); | ||
assert.equal(page.prepare("Hello ```world test```"), "\nHello {% raw %}`world test`{% endraw %}\n"); | ||
assert.equal(page.prepare("Hello\n```js\nworld test\n```\n"), "\nHello\n{% raw %}\n```js\nworld test\n```\n{% endraw %}"); | ||
assert.equal(page.prepare("Hello\n```\ntest\n\tworld\n\ttest\n```"), "\nHello\n{% raw %}\n```\ntest\n world\n test\n```\n{% endraw %}"); | ||
}); | ||
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" | ||
"\nHello\n{% raw %}\n```\nworld\nhello\n```\n{% endraw %}\ntest\n" | ||
); | ||
assert.equal( | ||
page.prepare("Hello\n\n\n\tworld\n\thello\n\n\n"), | ||
"Hello\n{% raw %}\n\n\tworld\n\thello\n\n\n{% endraw %}" | ||
"\nHello\n{% raw %}\n```\nworld\nhello\n```\n{% endraw %}" | ||
); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18323
446
5
+ Addedkramed-markdown-renderer@0.1.2(transitive)