You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
820 B
39 lines
820 B
// markdown.js
|
|
// Copyright (C) 2022 DTP Technologies, LLC
|
|
// License: Apache-2.0
|
|
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
|
|
const { SiteService } = require('../../lib/site-lib');
|
|
|
|
const marked = require('marked');
|
|
|
|
class MarkdownService extends SiteService {
|
|
|
|
constructor (dtp) {
|
|
super(dtp, module.exports);
|
|
}
|
|
|
|
async start ( ) {
|
|
await super.start();
|
|
this.markedRenderer = new marked.Renderer();
|
|
}
|
|
|
|
async renderFile (documentFile) {
|
|
const markdown = await fs.promises.readFile(documentFile, 'utf8');
|
|
return this.render(markdown);
|
|
}
|
|
|
|
async render (markdown) {
|
|
return marked.parse(markdown, { renderer: this.markedRenderer });
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
slug: 'markdown',
|
|
name: 'markdown',
|
|
className: 'MarkdownService',
|
|
create: (dtp) => { return new MarkdownService(dtp); },
|
|
};
|