diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-31 12:09:28 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-31 12:09:28 -0700 |
commit | 89593f46ab0c7dddab8414c5da55f0faeb3e61a4 (patch) | |
tree | 9649f634aebcd644b96225a8f2e596fe216ed180 | |
parent | 1d321207b045f7f9c34267fa4ce86fb41a1172a4 (diff) | |
download | gitbook-89593f46ab0c7dddab8414c5da55f0faeb3e61a4.zip gitbook-89593f46ab0c7dddab8414c5da55f0faeb3e61a4.tar.gz gitbook-89593f46ab0c7dddab8414c5da55f0faeb3e61a4.tar.bz2 |
Normalize .md links to .html when rendering pages
-rw-r--r-- | lib/parse/page.js | 9 | ||||
-rw-r--r-- | lib/parse/renderer.js | 27 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/parse/page.js b/lib/parse/page.js index 047f3e4..b1e4332 100644 --- a/lib/parse/page.js +++ b/lib/parse/page.js @@ -1,6 +1,8 @@ var _ = require('lodash'); var marked = require('marked'); +var renderer = require('./renderer'); + // Split a page up into sections (lesson, exercises, ...) function splitSections(nodes) { @@ -49,10 +51,15 @@ function parsePage(src) { // marked's Render expects this, we don't use it yet section.links = {}; + // Build options using defaults and our custom renderer + var options = _.extend({}, marked.defaults, { + renderer: renderer() + }); + // Render normal pages return { type: section.type, - content: marked.parser(section) + content: marked.parser(section, options) }; }) .value(); diff --git a/lib/parse/renderer.js b/lib/parse/renderer.js new file mode 100644 index 0000000..66aad46 --- /dev/null +++ b/lib/parse/renderer.js @@ -0,0 +1,27 @@ +var inherits = require('util').inherits; + +var marked = require('marked'); + + +function GitBookRenderer(options) { + if(!(this instanceof GitBookRenderer)) { + return new GitBookRenderer(options); + } + GitBookRenderer.super_.call(this, options); +} +inherits(GitBookRenderer, marked.Renderer); + + +GitBookRenderer.prototype.link = function(href, title, text) { + // Replace .md extensions by .html + return GitBookRenderer.super_.prototype.link.call( + this, + href.replace(/\.md$/, '.html'), + title, + text + ); +}; + + +// Exports +module.exports = GitBookRenderer; |