@ink-feather-org/typedoc-plugin-asciidoctor
Version:
Adds README.adoc support to typedoc.
51 lines (48 loc) • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.load = void 0;
var tslib_1 = require("tslib");
var typedoc_1 = require("typedoc");
var ts_utils_1 = require("@ink-feather-org/ts-utils");
var core_1 = tslib_1.__importDefault(require("@asciidoctor/core"));
var asciidoctor_shiki_1 = require("@ink-feather-org/asciidoctor-shiki");
var doctor = (0, core_1.default)();
doctor.SyntaxHighlighter.register('shiki', asciidoctor_shiki_1.AsciidoctorShiki);
var options = {
attributes: {
'source-highlighter': 'shiki',
},
};
function load(app) {
// using the readme option is not ideal
// in a perfect world i could tell typedoc to 'treat' .adoc files as readmes.
var readmeOption = app.options.getValue('readme');
if ((0, ts_utils_1.getFileExtension)(readmeOption) === 'adoc') {
app.converter.on(typedoc_1.Converter.EVENT_END, function (event) {
if (event.project.readme)
event.project.readme = doctor.convert(event.project.readme, options).toString();
});
/*app.renderer.on(Renderer.EVENT_END_PAGE, (event: PageEvent) => {
if (Path.basename(event.filename, Path.extname(event.filename)) === 'index') {
let html = event.contents
if (!html || !html.includes('highlight'))
return
// https://github.com/kamiazya/typedoc-plugin-mermaid/blob/fbb3763e51c2ba7f1ab4ef4bacbace05d352ff81/src/plugin.ts#L177
// https://highlightjs.org/usage/
console.log('index found')
// find the closing </body> tag and insert our style
const headEndIndex = html.indexOf('</head>')
html = html.slice(0, headEndIndex) + '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.0/styles/a11y-dark.min.css">' + html.slice(headEndIndex)
// find the closing </body> tag and insert our scripts
// const bodyEndIndex = html.lastIndexOf('</body>')
// html =
// html.slice(0, bodyEndIndex) +
// '<script src="/path/to/highlight.min.js"></script><script>hljs.highlightAll();</script>' +
// html.slice(bodyEndIndex)
event.contents = html
}
}) */
}
}
exports.load = load;
//# sourceMappingURL=index.js.map