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.5.3 to 1.0.0

lib/tohtml.js

16

lib/index.js

@@ -1,10 +0,8 @@

var kramed = require("kramed");
var _ = require("lodash");
var htmlParser = require('gitbook-html');
module.exports = {
summary: require("./summary"),
glossary: require("./glossary"),
langs: require("./langs"),
readme: require("./readme"),
page: require("./page")
};
var toHTML = require('./tohtml');
var toMarkdown = require('./tomarkdown');
var page = require('./page');
module.exports = htmlParser.createParser(toHTML, toMarkdown);
module.exports.page.prepare = page.prepare;
var _ = require('lodash');
var kramed = require('kramed');
var annotate = require('kramed/lib/annotate/');
var RAW_START = "{% raw %}";
var RAW_END = "{% endraw %}";
var RAW_START = '{% raw %}';
var RAW_END = '{% endraw %}';

@@ -18,2 +17,3 @@ function escape(str) {

// Add templating "raw" to code blocks
function preparePage(src) {

@@ -58,26 +58,4 @@ var lexed = annotate.blocks(src);

function parsePage(src) {
var options = _.extend({}, kramed.defaults, {
mathjax: false,
renderer: new kramed.Renderer({
langPrefix: 'lang-',
smartypants: false,
headerPrefix: '',
headerAutoId: false,
xhtml: false
})
});
return {
sections: [
{
type: "normal",
content: kramed(src, options)
}
]
};
}
// Exports
module.exports = parsePage;
module.exports.prepare = preparePage;
module.exports = {
prepare: preparePage
};
{
"name": "gitbook-markdown",
"version": "0.5.3",
"version": "1.0.0",
"homepage": "https://www.gitbook.com",

@@ -10,9 +10,10 @@ "description": "Parse markdown content for gitbook",

"kramed": "0.5.5",
"kramed-text-renderer": "0.2.1"
"kramed-text-renderer": "0.2.1",
"gitbook-html": "1.0.0"
},
"devDependencies": {
"mocha": "2.3.3"
"mocha": "^2.3.3"
},
"scripts": {
"test": "export TESTING=true; mocha --reporter list"
"test": "export TESTING=true; mocha --reporter list --bail"
},

@@ -19,0 +20,0 @@ "repository": {

@@ -1,2 +0,2 @@

# Magic
## Magic
Sufficiently advanced technology, beyond the understanding of the observer producing a sense of wonder.

@@ -6,9 +6,9 @@

# PHP
## PHP
An atrocious language, invented for the sole purpose of inflicting pain and suffering amongst the proframming wizards of this world.
# Clojure
## Clojure
Lisp re-invented for hipsters.
# Go
## Go
Go Go Google [Wow](https://www.google.com)

@@ -29,4 +29,4 @@

# Gitbook
## Gitbook
Awesome project. Really amazing, I'm really at a loss for words ...

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

var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/GLOSSARY.md'), 'utf8');
var LEXED = glossary(CONTENT);
describe('Glossary parsing', function () {
var LEXED;
describe('Glossary parsing', function () {
before(function() {
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/GLOSSARY.md'), 'utf8');
LEXED = glossary(CONTENT);
});
it('should only get heading + paragraph pairs', function() {

@@ -23,5 +27,5 @@ assert.equal(LEXED.length, 5);

it('should correctly convert it to text', function() {
var text = glossary.toText(LEXED);
assertObjectsEqual(glossary(text), LEXED);
var text = glossary.toText(LEXED);
assertObjectsEqual(glossary(text), LEXED);
});
});

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

var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/LANGS.md'), 'utf8');
var LEXED = langs(CONTENT);
describe('Languages parsing', function () {
var LEXED;
describe('Languages parsing', function () {
before(function() {
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/LANGS.md'), 'utf8');
LEXED = langs(CONTENT);
});
it('should detect paths and titles', function() {

@@ -13,0 +17,0 @@ assert.equal(LEXED.length, 2);

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

function loadPage (name, options) {
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/' + name + '.md'), 'utf8');
return page(CONTENT, options).sections;
}
var LEXED = loadPage('PAGE');
describe('Page parsing', function() {
var LEXED;
describe('Page parsing', function() {
it('should detect sections', function() {
assert.equal(LEXED.length, 1);
before(function() {
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/PAGE.md'), 'utf8');
LEXED = page(CONTENT);
});
it('should gen content for normal sections', function() {
assert(LEXED[0].content);
it('should gen content', function() {
assert(LEXED.content);
});
it('should not add id to headings', function() {
assert.equal(page('# Hello').sections[0].content, '<h1>Hello</h1>\n');
assert.equal(page('# Hello {#test}').sections[0].content, '<h1 id="test">Hello </h1>\n');
assert.equal(page('# Hello').content, '<h1>Hello</h1>\n');
assert.equal(page('# Hello {#test}').content, '<h1 id="test">Hello </h1>\n');
});

@@ -28,0 +25,0 @@

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

describe('Readme parsing', function () {
var LEXED;
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/README.md'), 'utf8');
var LEXED = readme(CONTENT);
before(function() {
var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/README.md'), 'utf8');
LEXED = readme(CONTENT);
});
describe('Readme parsing', function () {
it('should contain a title', function() {

@@ -15,0 +17,0 @@ assert(LEXED.title);

@@ -16,38 +16,48 @@ var fs = require('fs');

var LEXED = lex('SUMMARY.md');
describe('Summary parsing', function () {
var LEXED;
describe('Summary parsing', function () {
before(function() {
LEXED = lex('SUMMARY.md');
PART = LEXED.parts[0];
});
it('should detect chapters', function() {
assert.equal(LEXED.chapters.length, 5);
assert.equal(PART.articles.length, 5);
});
it('should support articles', function() {
assert.equal(LEXED.chapters[0].articles.length, 2);
assert.equal(LEXED.chapters[1].articles.length, 0);
assert.equal(LEXED.chapters[2].articles.length, 0);
assert.equal(PART.articles[0].articles.length, 2);
assert.equal(PART.articles[1].articles.length, 0);
assert.equal(PART.articles[2].articles.length, 0);
});
it('should detect paths and titles', function() {
assert(LEXED.chapters[0].path);
assert(LEXED.chapters[1].path);
assert(LEXED.chapters[2].path);
assert(LEXED.chapters[3].path);
assert.equal(LEXED.chapters[4].path, null);
assert(PART.articles[0].path);
assert(PART.articles[1].path);
assert(PART.articles[2].path);
assert(PART.articles[3].path);
assert.equal(PART.articles[4].path, null);
assert(LEXED.chapters[0].title);
assert(LEXED.chapters[1].title);
assert(LEXED.chapters[2].title);
assert(LEXED.chapters[3].title);
assert(LEXED.chapters[4].title);
assert(PART.articles[0].title);
assert(PART.articles[1].title);
assert(PART.articles[2].title);
assert(PART.articles[3].title);
assert(PART.articles[4].title);
});
it('should normalize paths from .md', function() {
assert.equal(LEXED.chapters[0].path,'chapter-1/README.md');
assert.equal(LEXED.chapters[1].path,'chapter-2/README.md');
assert.equal(LEXED.chapters[2].path,'chapter-3/README.md');
assert.equal(PART.articles[0].path,'chapter-1/README.md');
assert.equal(PART.articles[1].path,'chapter-2/README.md');
assert.equal(PART.articles[2].path,'chapter-3/README.md');
});
it('should part parts', function() {
var l = lex('SUMMARY_PARTS.md');
assert.equal(l.parts.length, 3);
});
it('should allow lists separated by whitespace', function() {
var l = lex('SUMMARY_WHITESPACE.md');
assert.equal(l.chapters.length, 5);
assert.equal(l.parts[0].articles.length, 5);
});

@@ -57,14 +67,5 @@

var l = lex('SUMMARY_EMPTY.md');
assert.equal(l.chapters.length, 1);
assert.equal(l.parts[0].articles.length, 1);
});
it('should throw error for sublist entries', function() {
assert.throws(
function() {
var l = lex('SUMMARY_SUBLIST.md');
},
"Invalid entry in the SUMMARY"
);
});
it('should correctly convert it to text', function() {

@@ -71,0 +72,0 @@ var text = summary.toText(LEXED);

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