-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Expand file tree
/
Copy pathrenderMarkup.ts
More file actions
33 lines (30 loc) · 1.17 KB
/
Copy pathrenderMarkup.ts
File metadata and controls
33 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import markupLanguageUtils from '../markupLanguageUtils';
import Setting from '../models/Setting';
import { CommandRuntime, CommandDeclaration, CommandContext } from '../services/CommandService';
import { themeStyle } from '../theme';
import attachedResources from '../utils/attachedResources';
import { MarkupLanguage } from '@joplin/renderer';
import { Options } from '@joplin/renderer/MdToHtml';
import { RenderOptions } from '@joplin/renderer/types';
export const declaration: CommandDeclaration = {
name: 'renderMarkup',
};
const getMarkupToHtml = () => {
return markupLanguageUtils.newMarkupToHtml({}, {
resourceBaseUrl: `file://${Setting.value('resourceDir')}/`,
customCss: '',
});
};
export const runtime = (): CommandRuntime => {
return {
execute: async (_context: CommandContext, markupLanguage: MarkupLanguage, markup: string, _rendererOptions: Options = null, renderOptions: RenderOptions = null) => {
const markupToHtml = getMarkupToHtml();
const html = await markupToHtml.render(markupLanguage, markup, themeStyle(Setting.value('theme')), {
...renderOptions,
resources: await attachedResources(markup),
splitted: true,
});
return html;
},
};
};