mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 11:03:39 +00:00
Normalize .md links to .html when rendering pages
This commit is contained in:
+8
-1
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user