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.2 to 0.3.3

lib/annotate_blocks.js

46

lib/page.js

@@ -6,3 +6,3 @@ var _ = require('lodash');

var lnormalize = require('./utils/lang').normalize;
var mdRenderer = require('kramed-markdown-renderer');
var annotate = require('./annotate');

@@ -12,18 +12,42 @@ var RAW_START = "{% raw %}";

function escape(str) {
return RAW_START + str + RAW_END;
}
// Combines annotated nodes
function combine(nodes) {
return _.pluck(nodes, 'raw').join('');
}
function escapeCodeElement(el) {
if(el.type == 'code') {
el.raw = escape(el.raw);
}
return el;
}
function preparePage(src) {
var renderer = mdRenderer();
var lexed = annotate.blocks(src);
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 escaped = lexed
// Escape code blocks
.map(escapeCodeElement)
// Escape inline code blocks
.map(function(el) {
// Only escape paragraphs and headings
if(!(el.type == 'paragraph' || el.type == 'heading')) {
return el;
}
var options = _.extend({}, kramed.defaults, {
renderer: renderer,
escape: false
// Escape inline code blocks
var newInline = annotate.inline(el.raw).map(escapeCodeElement);
// Change raw source code
el.raw = combine(newInline);
return el;
});
return kramed(src, options);
return combine(escaped);
}

@@ -30,0 +54,0 @@

{
"name": "gitbook-markdown",
"version": "0.3.2",
"version": "0.3.3",
"homepage": "https://www.gitbook.com",

@@ -11,3 +11,2 @@ "description": "Parse markdown content for gitbook",

"kramed-text-renderer": "0.2.1",
"kramed-markdown-renderer": "0.1.2",
"highlight.js": "8.4.0"

@@ -14,0 +13,0 @@ },

@@ -24,7 +24,7 @@ var fs = require('fs');

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 %}");
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```\n{% endraw %}");
assert.equal(page.prepare("Hello\n```\ntest\n\tworld\n\ttest\n```"), "Hello\n{% raw %}```\ntest\n\tworld\n\ttest\n```{% endraw %}");
});

@@ -35,7 +35,7 @@

page.prepare("Hello\n\n\n\tworld\n\thello\n\n\ntest"),
"\nHello\n{% raw %}\n```\nworld\nhello\n```\n{% endraw %}\ntest\n"
"Hello\n\n\n{% raw %}\tworld\n\thello\n\n\n{% endraw %}test"
);
assert.equal(
page.prepare("Hello\n\n\n\tworld\n\thello\n\n\n"),
"\nHello\n{% raw %}\n```\nworld\nhello\n```\n{% endraw %}"
"Hello\n\n\n{% raw %}\tworld\n\thello\n\n\n{% endraw %}"
);

@@ -47,5 +47,5 @@ });

page.prepare('Hello {{ "Bonjour" }} ```test```'),
'\nHello {{ "Bonjour" }} {% raw %}`test`{% endraw %}\n'
'Hello {{ "Bonjour" }} {% raw %}```test```{% 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