gitbook-markdown
Advanced tools
Comparing version 0.2.4 to 0.3.0
var _ = require('lodash'); | ||
var kramed = require('kramed'); | ||
var hljs = require('highlight.js'); | ||
@@ -8,2 +7,26 @@ | ||
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; | ||
}); | ||
// 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; | ||
}); | ||
src = src.replace(/~0/, ""); | ||
return src; | ||
} | ||
function parsePage(src) { | ||
@@ -38,1 +61,2 @@ var options = _.extend({}, kramed.defaults, { | ||
module.exports = parsePage; | ||
module.exports.prepare = preparePage; |
{ | ||
"name": "gitbook-markdown", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"homepage": "https://www.gitbook.com", | ||
@@ -5,0 +5,0 @@ "description": "Parse markdown content for gitbook", |
@@ -22,2 +22,14 @@ var fs = require('fs'); | ||
}); | ||
it('should escape codeblocks in preparation', function() { | ||
assert.equal(page.prepare("Hello `world`"), "Hello {% raw %}`world`{% endraw %}"); | ||
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" | ||
); | ||
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 %}" | ||
); | ||
}); | ||
}); |
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
17735
445