Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gitbook-markdown

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitbook-markdown - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

27

lib/page.js

@@ -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 %}"
);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc