typedoc-plugin-markdown
Advanced tools
Comparing version 3.13.4 to 3.13.5
import { MarkdownTheme } from '../../theme'; | ||
export default function (theme: MarkdownTheme): void; | ||
export declare function readFile(file: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.readFile = void 0; | ||
const fs = require("fs"); | ||
const Handlebars = require("handlebars"); | ||
const Path = require("path"); | ||
function default_1(theme) { | ||
@@ -42,5 +45,63 @@ Handlebars.registerHelper('comment', function (parts) { | ||
} | ||
return result.join(''); | ||
return parseMarkdown(result.join(''), theme); | ||
}); | ||
} | ||
exports.default = default_1; | ||
function parseMarkdown(text, theme) { | ||
const includePattern = /\[\[include:([^\]]+?)\]\]/g; | ||
const mediaPattern = /media:\/\/([^ ")\]}]+)/g; | ||
if (theme.includes) { | ||
text = text.replace(includePattern, (_match, path) => { | ||
path = Path.join(theme.includes, path.trim()); | ||
if (fs.existsSync(path) && fs.statSync(path).isFile()) { | ||
const contents = readFile(path); | ||
return contents; | ||
} | ||
else { | ||
theme.application.logger.warn('Could not find file to include: ' + path); | ||
return ''; | ||
} | ||
}); | ||
} | ||
if (theme.mediaDirectory) { | ||
text = text.replace(mediaPattern, (match, path) => { | ||
const fileName = Path.join(theme.mediaDirectory, path); | ||
if (fs.existsSync(fileName) && fs.statSync(fileName).isFile()) { | ||
return Handlebars.helpers.relativeURL('media') + '/' + path; | ||
} | ||
else { | ||
theme.application.logger.warn('Could not find media file: ' + fileName); | ||
return match; | ||
} | ||
}); | ||
} | ||
return text; | ||
} | ||
function readFile(file) { | ||
const buffer = fs.readFileSync(file); | ||
switch (buffer[0]) { | ||
case 0xfe: | ||
if (buffer[1] === 0xff) { | ||
let i = 0; | ||
while (i + 1 < buffer.length) { | ||
const temp = buffer[i]; | ||
buffer[i] = buffer[i + 1]; | ||
buffer[i + 1] = temp; | ||
i += 2; | ||
} | ||
return buffer.toString('ucs2', 2); | ||
} | ||
break; | ||
case 0xff: | ||
if (buffer[1] === 0xfe) { | ||
return buffer.toString('ucs2', 2); | ||
} | ||
break; | ||
case 0xef: | ||
if (buffer[1] === 0xbb) { | ||
return buffer.toString('utf8', 3); | ||
} | ||
} | ||
return buffer.toString('utf8', 0); | ||
} | ||
exports.readFile = readFile; |
{ | ||
"name": "typedoc-plugin-markdown", | ||
"version": "3.13.4", | ||
"version": "3.13.5", | ||
"description": "A plugin for TypeDoc that enables TypeScript API documentation to be generated in Markdown.", | ||
@@ -17,4 +17,4 @@ "main": "dist/index.js", | ||
"docs": "yarn run build && yarn run docs:md && yarn run docs:html", | ||
"docs:md": "typedoc --plugin typedoc-plugin-markdown --plugin typedoc-plugin-mdn-links --options ../../test/typedoc-options.json --out ./docs/md", | ||
"docs:html": "typedoc --options ../../test/typedoc-options.json --plugin typedoc-plugin-mdn-links --out ./docs/html" | ||
"docs:md": "typedoc --plugin typedoc-plugin-markdown --plugin typedoc-plugin-mdn-links --options ../../stub-project/typedoc-options.json --out ./docs/md", | ||
"docs:html": "typedoc --options ../../stub-project/typedoc-options.json --plugin typedoc-plugin-mdn-links --out ./docs/html" | ||
}, | ||
@@ -21,0 +21,0 @@ "author": "Thomas Grey", |
82815
1732
2