[Documentation] Add custom renderer

MissionControl/vista#21
This commit is contained in:
Victor Woeltjen 2015-08-04 13:37:45 -07:00
parent 55d52d060a
commit aea286779e
2 changed files with 21 additions and 2 deletions

View File

@ -86,11 +86,30 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
return transform; return transform;
} }
function CustomRenderer() {
var renderer = new marked.Renderer(),
customRenderer = Object.create(renderer);
customRenderer.heading = function (text, level) {
var escapedText = (text || "").trim().toLowerCase().replace(/\W/g, "-"),
aOpen = "<a name=\"" + escapedText + "\" href=\"#" + escapedText + "\">",
aClose = "</a>";
return aOpen + renderer.heading.apply(renderer, arguments) + aClose;
};
// Change links to .md files to .html
customRenderer.link = function (href, title, text) {
// ...but only if they look like relative paths
return (href || "").indexOf(":") === -1 && href[0] !== "/" ?
renderer.link(href.replace(/md$/, "html"), title, text) :
renderer.link.apply(renderer, arguments);
};
return customRenderer;
}
options['in'] = options['in'] || options.i; options['in'] = options['in'] || options.i;
options.out = options.out || options.o; options.out = options.out || options.o;
marked.setOptions({ marked.setOptions({
renderer: new marked.Renderer(), renderer: new CustomRenderer(),
gfm: true, gfm: true,
tables: true, tables: true,
breaks: false, breaks: false,

View File

@ -107,4 +107,4 @@ As such, the specific architecture of any given application built on
Open MCT Web can look very different. Open MCT Web can look very different.
The specific service infrastructure provided by the platform is described The specific service infrastructure provided by the platform is described
in the [Platform Architecture](Platform.html). in the [Platform Architecture](Platform.md).