The DTP Sites web app development engine.
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.
 
 
 
 
 

37 lines
763 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 ( ) {
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',
create: (dtp) => { return new MarkdownService(dtp); },
};