2020-11-05 18:58:23 +02:00
|
|
|
import InMemoryCache from './InMemoryCache';
|
2020-10-21 01:23:55 +02:00
|
|
|
import noteStyle from './noteStyle';
|
2024-01-18 13:20:10 +02:00
|
|
|
import { fileExtension } from '@joplin/utils/path';
|
2021-01-02 18:53:59 +02:00
|
|
|
import setupLinkify from './MdToHtml/setupLinkify';
|
|
|
|
import validateLinks from './MdToHtml/validateLinks';
|
2021-08-14 13:19:53 +02:00
|
|
|
import { Options as NoteStyleOptions } from './noteStyle';
|
2024-01-18 13:20:10 +02:00
|
|
|
import { FsDriver, ItemIdToUrlHandler, MarkupRenderer, OptionsResourceModel, RenderOptions, RenderResult, RenderResultPluginAsset } from './types';
|
2022-05-26 17:46:56 +02:00
|
|
|
import hljs from './highlight';
|
2023-11-03 21:45:21 +02:00
|
|
|
import * as MarkdownIt from 'markdown-it';
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2022-11-14 19:16:59 +02:00
|
|
|
const Entities = require('html-entities').AllHtmlEntities;
|
|
|
|
const htmlentities = new Entities().encode;
|
2020-01-30 23:05:23 +02:00
|
|
|
const md5 = require('md5');
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
interface RendererRule {
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
install(context: any, ruleOptions: any): any;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2024-06-04 00:49:09 +02:00
|
|
|
assets?(theme: any): PluginAsset[];
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
plugin?: any;
|
2020-12-10 18:09:31 +02:00
|
|
|
assetPath?: string;
|
2021-02-05 23:27:19 +02:00
|
|
|
assetPathIsAbsolute?: boolean;
|
2023-11-03 21:45:21 +02:00
|
|
|
pluginId?: string;
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface RendererRules {
|
2020-11-12 21:29:22 +02:00
|
|
|
[pluginName: string]: RendererRule;
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface RendererPlugin {
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
module: any;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
options?: any;
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface RendererPlugins {
|
2020-11-12 21:29:22 +02:00
|
|
|
[pluginName: string]: RendererPlugin;
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
2020-03-23 02:47:25 +02:00
|
|
|
|
|
|
|
// /!\/!\ Note: the order of rules is important!! /!\/!\
|
2020-11-12 21:13:28 +02:00
|
|
|
const rules: RendererRules = {
|
2020-03-23 02:47:25 +02:00
|
|
|
fence: require('./MdToHtml/rules/fence').default,
|
|
|
|
sanitize_html: require('./MdToHtml/rules/sanitize_html').default,
|
2020-10-21 01:23:55 +02:00
|
|
|
image: require('./MdToHtml/rules/image').default,
|
2020-03-23 02:47:25 +02:00
|
|
|
checkbox: require('./MdToHtml/rules/checkbox').default,
|
2020-10-21 01:23:55 +02:00
|
|
|
katex: require('./MdToHtml/rules/katex').default,
|
|
|
|
link_open: require('./MdToHtml/rules/link_open').default,
|
2020-12-09 23:30:51 +02:00
|
|
|
link_close: require('./MdToHtml/rules/link_close').default,
|
2020-10-21 01:23:55 +02:00
|
|
|
html_image: require('./MdToHtml/rules/html_image').default,
|
|
|
|
highlight_keywords: require('./MdToHtml/rules/highlight_keywords').default,
|
|
|
|
code_inline: require('./MdToHtml/rules/code_inline').default,
|
|
|
|
fountain: require('./MdToHtml/rules/fountain').default,
|
2020-02-12 00:27:34 +02:00
|
|
|
mermaid: require('./MdToHtml/rules/mermaid').default,
|
2021-11-03 14:10:46 +02:00
|
|
|
source_map: require('./MdToHtml/rules/source_map').default,
|
2024-03-25 13:27:48 +02:00
|
|
|
tableHorizontallyScrollable: require('./MdToHtml/rules/tableHorizontallyScrollable').default,
|
2020-01-30 23:05:23 +02:00
|
|
|
};
|
2020-03-23 02:47:25 +02:00
|
|
|
|
2021-12-20 17:08:43 +02:00
|
|
|
const uslug = require('@joplin/fork-uslug');
|
2020-01-30 23:05:23 +02:00
|
|
|
const markdownItAnchor = require('markdown-it-anchor');
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2020-01-30 23:05:23 +02:00
|
|
|
// The keys must match the corresponding entry in Setting.js
|
2020-11-12 21:13:28 +02:00
|
|
|
const plugins: RendererPlugins = {
|
2020-01-30 23:05:23 +02:00
|
|
|
mark: { module: require('markdown-it-mark') },
|
|
|
|
footnote: { module: require('markdown-it-footnote') },
|
|
|
|
sub: { module: require('markdown-it-sub') },
|
|
|
|
sup: { module: require('markdown-it-sup') },
|
|
|
|
deflist: { module: require('markdown-it-deflist') },
|
|
|
|
abbr: { module: require('markdown-it-abbr') },
|
|
|
|
emoji: { module: require('markdown-it-emoji') },
|
|
|
|
insert: { module: require('markdown-it-ins') },
|
|
|
|
multitable: { module: require('markdown-it-multimd-table'), options: { multiline: true, rowspan: true, headerless: true } },
|
2024-01-04 17:14:52 +02:00
|
|
|
toc: { module: require('markdown-it-toc-done-right'), options: { listType: 'ul', slugify: slugify, uniqueSlugStartIndex: 2 } },
|
2020-02-06 00:15:40 +02:00
|
|
|
expand_tabs: { module: require('markdown-it-expand-tabs'), options: { tabWidth: 4 } },
|
2020-01-30 23:05:23 +02:00
|
|
|
};
|
|
|
|
const defaultNoteStyle = require('./defaultNoteStyle');
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function slugify(s: string): string {
|
2020-10-16 23:55:48 +02:00
|
|
|
return uslug(s);
|
2020-01-30 23:05:23 +02:00
|
|
|
}
|
|
|
|
|
2020-10-16 17:26:19 +02:00
|
|
|
// Share across all instances of MdToHtml
|
|
|
|
const inMemoryCache = new InMemoryCache(20);
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
export interface ExtraRendererRule {
|
2020-11-19 14:34:49 +02:00
|
|
|
id: string;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-19 14:34:49 +02:00
|
|
|
module: any;
|
|
|
|
assetPath: string;
|
2023-11-03 21:45:21 +02:00
|
|
|
pluginId: string;
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Options {
|
2020-11-12 21:29:22 +02:00
|
|
|
resourceBaseUrl?: string;
|
2024-01-18 13:20:10 +02:00
|
|
|
ResourceModel?: OptionsResourceModel;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
pluginOptions?: any;
|
|
|
|
tempDir?: string;
|
2024-01-18 13:20:10 +02:00
|
|
|
fsDriver?: FsDriver;
|
2020-11-12 21:29:22 +02:00
|
|
|
extraRendererRules?: ExtraRendererRule[];
|
2021-05-19 15:00:16 +02:00
|
|
|
customCss?: string;
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface PluginAsset {
|
2024-06-04 00:49:09 +02:00
|
|
|
source?: string;
|
2020-11-12 21:29:22 +02:00
|
|
|
mime?: string;
|
|
|
|
inline?: boolean;
|
|
|
|
name?: string;
|
|
|
|
text?: string;
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Types are a bit of a mess when it comes to plugin assets. Something
|
2024-02-26 12:16:23 +02:00
|
|
|
// called "pluginAsset" in this class might refer to subtly different
|
2020-10-21 01:23:55 +02:00
|
|
|
// types. The logic should be cleaned up before types are added.
|
|
|
|
interface PluginAssets {
|
2020-11-12 21:13:28 +02:00
|
|
|
[pluginName: string]: PluginAsset[];
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-09 23:30:51 +02:00
|
|
|
export interface Link {
|
|
|
|
href: string;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-12-09 23:30:51 +02:00
|
|
|
resource: any;
|
|
|
|
resourceReady: boolean;
|
|
|
|
resourceFullPath: string;
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
interface PluginContext {
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
css: any;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
pluginAssets: any;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
cache: any;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
userData: any;
|
2020-12-09 23:30:51 +02:00
|
|
|
currentLinks: Link[];
|
2024-06-04 00:49:09 +02:00
|
|
|
|
|
|
|
// This must be set by the plugin to indicate whether the document contains markup that was
|
|
|
|
// processed by the plugin or not. Currently this information is then used to remove unnecessary
|
|
|
|
// plugin assets from the rendered document. This is particularly useful when exporting as HTML
|
|
|
|
// since it can reduce the size from several MB to a few KB.
|
|
|
|
pluginWasUsed: {
|
|
|
|
mermaid: boolean;
|
|
|
|
katex: boolean;
|
|
|
|
};
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface RuleOptions {
|
2020-11-12 21:29:22 +02:00
|
|
|
context: PluginContext;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
theme: any;
|
|
|
|
postMessageSyntax: string;
|
2024-01-18 13:20:10 +02:00
|
|
|
ResourceModel: OptionsResourceModel;
|
2020-11-12 21:29:22 +02:00
|
|
|
resourceBaseUrl: string;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
resources: any; // resourceId: Resource
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
// Used by checkboxes to specify how it should be rendered
|
2020-11-12 21:29:22 +02:00
|
|
|
checkboxRenderingType?: number;
|
2022-04-05 16:42:06 +02:00
|
|
|
checkboxDisabled?: boolean;
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
// Used by the keyword highlighting plugin (mobile only)
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:29:22 +02:00
|
|
|
highlightedKeywords?: any[];
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
// Use by resource-rendering logic to signify that it should be rendered
|
|
|
|
// as a plain HTML string without any attached JavaScript. Used for example
|
|
|
|
// when exporting to HTML.
|
2020-11-12 21:29:22 +02:00
|
|
|
plainResourceRendering?: boolean;
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
// Use in mobile app to enable long-pressing an image or a linkg
|
|
|
|
// to display a context menu. Used in `image.ts` and `link_open.ts`
|
2020-11-12 21:29:22 +02:00
|
|
|
enableLongPress?: boolean;
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
// Use by `link_open` rule.
|
|
|
|
// linkRenderingType = 1 is the regular rendering and clicking on it is handled via embedded JS (in onclick attribute)
|
|
|
|
// linkRenderingType = 2 gives a plain link with no JS. Caller needs to handle clicking on the link.
|
2020-11-12 21:29:22 +02:00
|
|
|
linkRenderingType?: number;
|
2020-12-09 23:30:51 +02:00
|
|
|
|
2023-10-02 16:15:51 +02:00
|
|
|
// A list of MIME types for which an edit button appears on tap/hover.
|
|
|
|
// Used by the image editor in the mobile app.
|
|
|
|
editPopupFiletypes?: string[];
|
|
|
|
|
2024-02-26 12:16:23 +02:00
|
|
|
// Should be the string representation a function that accepts two arguments:
|
2023-10-02 16:15:51 +02:00
|
|
|
// the target element to have the popup shown for and the id of the resource to edit.
|
|
|
|
createEditPopupSyntax?: string;
|
|
|
|
destroyEditPopupSyntax?: string;
|
|
|
|
|
2020-12-09 23:30:51 +02:00
|
|
|
audioPlayerEnabled: boolean;
|
|
|
|
videoPlayerEnabled: boolean;
|
|
|
|
pdfViewerEnabled: boolean;
|
2022-08-04 11:12:22 +02:00
|
|
|
useCustomPdfViewer: boolean;
|
2022-08-27 14:32:20 +02:00
|
|
|
noteId?: string;
|
|
|
|
vendorDir?: string;
|
2021-01-29 20:45:11 +02:00
|
|
|
itemIdToUrl?: ItemIdToUrlHandler;
|
2023-03-30 17:58:48 +02:00
|
|
|
|
2023-12-06 21:17:16 +02:00
|
|
|
// Passed to the HTML sanitizer: Allows file:// URLs with
|
|
|
|
// paths with the included prefixes.
|
|
|
|
allowedFilePrefixes?: string[];
|
|
|
|
|
2023-03-30 17:58:48 +02:00
|
|
|
platformName?: string;
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
2024-01-18 13:20:10 +02:00
|
|
|
export default class MdToHtml implements MarkupRenderer {
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
private resourceBaseUrl_: string;
|
2024-01-18 13:20:10 +02:00
|
|
|
private ResourceModel_: OptionsResourceModel;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
private contextCache_: any;
|
2024-01-18 13:20:10 +02:00
|
|
|
private fsDriver_: FsDriver;
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
private cachedOutputs_: any = {};
|
|
|
|
private lastCodeHighlightCacheKey_: string = null;
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
private cachedHighlightedCode_: any = {};
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
// Markdown-It plugin options (not Joplin plugin options)
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
private pluginOptions_: any = {};
|
|
|
|
private extraRendererRules_: RendererRules = {};
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
private allProcessedAssets_: any = {};
|
2023-06-30 10:07:03 +02:00
|
|
|
private customCss_ = '';
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
public constructor(options: Options = null) {
|
2020-01-30 23:05:23 +02:00
|
|
|
if (!options) options = {};
|
|
|
|
|
|
|
|
// Must include last "/"
|
|
|
|
this.resourceBaseUrl_ = 'resourceBaseUrl' in options ? options.resourceBaseUrl : null;
|
|
|
|
|
|
|
|
this.ResourceModel_ = options.ResourceModel;
|
|
|
|
this.pluginOptions_ = options.pluginOptions ? options.pluginOptions : {};
|
2020-10-16 17:26:19 +02:00
|
|
|
this.contextCache_ = inMemoryCache;
|
2020-03-10 01:24:57 +02:00
|
|
|
|
|
|
|
this.fsDriver_ = {
|
|
|
|
writeFile: (/* path, content, encoding = 'base64'*/) => { throw new Error('writeFile not set'); },
|
|
|
|
exists: (/* path*/) => { throw new Error('exists not set'); },
|
|
|
|
cacheCssToFile: (/* cssStrings*/) => { throw new Error('cacheCssToFile not set'); },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (options.fsDriver) {
|
|
|
|
if (options.fsDriver.writeFile) this.fsDriver_.writeFile = options.fsDriver.writeFile;
|
|
|
|
if (options.fsDriver.exists) this.fsDriver_.exists = options.fsDriver.exists;
|
|
|
|
if (options.fsDriver.cacheCssToFile) this.fsDriver_.cacheCssToFile = options.fsDriver.cacheCssToFile;
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
if (options.extraRendererRules) {
|
|
|
|
for (const rule of options.extraRendererRules) {
|
2023-11-03 21:45:21 +02:00
|
|
|
this.loadExtraRendererRule(rule.id, rule.assetPath, rule.module, rule.pluginId);
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-19 15:00:16 +02:00
|
|
|
|
|
|
|
this.customCss_ = options.customCss || '';
|
2020-03-10 01:24:57 +02:00
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
private fsDriver() {
|
|
|
|
return this.fsDriver_;
|
2020-01-30 23:05:23 +02:00
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
public static pluginNames() {
|
2020-03-23 02:47:25 +02:00
|
|
|
const output = [];
|
|
|
|
for (const n in rules) output.push(n);
|
|
|
|
for (const n in plugins) output.push(n);
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
private pluginOptions(name: string) {
|
2020-12-09 23:30:51 +02:00
|
|
|
// Currently link_close is only used to append the media player to
|
|
|
|
// the resource links so we use the mediaPlayers plugin options for
|
|
|
|
// it.
|
|
|
|
if (name === 'link_close') name = 'mediaPlayers';
|
|
|
|
|
2020-01-30 23:05:23 +02:00
|
|
|
let o = this.pluginOptions_[name] ? this.pluginOptions_[name] : {};
|
2023-06-01 13:02:36 +02:00
|
|
|
o = { enabled: true, ...o };
|
2020-12-09 23:30:51 +02:00
|
|
|
|
2020-01-30 23:05:23 +02:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
private pluginEnabled(name: string) {
|
2020-01-30 23:05:23 +02:00
|
|
|
return this.pluginOptions(name).enabled;
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
// `module` is a file that has already been `required()`
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-11-03 21:45:21 +02:00
|
|
|
public loadExtraRendererRule(id: string, assetPath: string, module: any, pluginId: string) {
|
2020-10-21 01:23:55 +02:00
|
|
|
if (this.extraRendererRules_[id]) throw new Error(`A renderer rule with this ID has already been loaded: ${id}`);
|
2023-11-03 21:45:21 +02:00
|
|
|
|
2020-12-10 18:09:31 +02:00
|
|
|
this.extraRendererRules_[id] = {
|
|
|
|
...module,
|
|
|
|
assetPath,
|
2023-11-03 21:45:21 +02:00
|
|
|
pluginId: pluginId,
|
2021-02-05 23:27:19 +02:00
|
|
|
assetPathIsAbsolute: true,
|
2020-12-10 18:09:31 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private ruleByKey(key: string): RendererRule {
|
|
|
|
if (rules[key]) return rules[key];
|
|
|
|
if (this.extraRendererRules_[key]) return this.extraRendererRules_[key];
|
|
|
|
if (key === 'highlight.js') return null;
|
|
|
|
throw new Error(`No such rule: ${key}`);
|
2020-10-21 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
private processPluginAssets(pluginAssets: PluginAssets): RenderResult {
|
|
|
|
const files: RenderResultPluginAsset[] = [];
|
2020-01-30 23:05:23 +02:00
|
|
|
const cssStrings = [];
|
|
|
|
for (const pluginName in pluginAssets) {
|
2020-12-10 18:09:31 +02:00
|
|
|
|
|
|
|
const rule = this.ruleByKey(pluginName);
|
|
|
|
|
2020-01-30 23:05:23 +02:00
|
|
|
for (const asset of pluginAssets[pluginName]) {
|
|
|
|
let mime = asset.mime;
|
|
|
|
|
|
|
|
if (!mime && asset.inline) throw new Error('Mime type is required for inline assets');
|
|
|
|
|
|
|
|
if (!mime) {
|
|
|
|
const ext = fileExtension(asset.name).toLowerCase();
|
|
|
|
// For now it's only useful to support CSS and JS because that's what needs to be added
|
|
|
|
// by the caller with <script> or <style> tags. Everything, like fonts, etc. is loaded
|
|
|
|
// via CSS or some other ways.
|
|
|
|
mime = 'application/octet-stream';
|
|
|
|
if (ext === 'css') mime = 'text/css';
|
|
|
|
if (ext === 'js') mime = 'application/javascript';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset.inline) {
|
|
|
|
if (mime === 'text/css') {
|
|
|
|
cssStrings.push(asset.text);
|
|
|
|
} else {
|
|
|
|
throw new Error(`Unsupported inline mime type: ${mime}`);
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-10 18:09:31 +02:00
|
|
|
// TODO: we should resolve the path using
|
|
|
|
// resolveRelativePathWithinDir() for increased
|
|
|
|
// security, but the shim is not accessible from the
|
|
|
|
// renderer, and React Native doesn't have this
|
|
|
|
// function, so for now use the provided path as-is.
|
|
|
|
|
2020-03-23 02:47:25 +02:00
|
|
|
const name = `${pluginName}/${asset.name}`;
|
2020-12-10 18:09:31 +02:00
|
|
|
const assetPath = rule?.assetPath ? `${rule.assetPath}/${asset.name}` : `pluginAssets/${name}`;
|
|
|
|
|
2024-06-04 00:49:09 +02:00
|
|
|
files.push({
|
|
|
|
...asset,
|
|
|
|
source: asset.source,
|
|
|
|
name: name,
|
2020-12-10 18:09:31 +02:00
|
|
|
path: assetPath,
|
2021-02-05 23:27:19 +02:00
|
|
|
pathIsAbsolute: !!rule && !!rule.assetPathIsAbsolute,
|
2024-06-04 00:49:09 +02:00
|
|
|
mime: mime,
|
|
|
|
});
|
2020-01-30 23:05:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2020-10-21 01:23:55 +02:00
|
|
|
html: '',
|
2020-03-23 02:47:25 +02:00
|
|
|
pluginAssets: files,
|
2020-01-30 23:05:23 +02:00
|
|
|
cssStrings: cssStrings,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
// This return all the assets for all the plugins. Since it is called
|
|
|
|
// on each render, the result is cached.
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-12-10 18:09:31 +02:00
|
|
|
private allProcessedAssets(rules: RendererRules, theme: any, codeTheme: string) {
|
2020-11-12 21:13:28 +02:00
|
|
|
const cacheKey: string = theme.cacheKey + codeTheme;
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
if (this.allProcessedAssets_[cacheKey]) return this.allProcessedAssets_[cacheKey];
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2024-06-04 00:49:09 +02:00
|
|
|
const assets: PluginAssets = {};
|
2020-03-23 02:47:25 +02:00
|
|
|
for (const key in rules) {
|
|
|
|
if (!this.pluginEnabled(key)) continue;
|
|
|
|
const rule = rules[key];
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
if (rule.assets) {
|
|
|
|
assets[key] = rule.assets(theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assets['highlight.js'] = [{ name: codeTheme }];
|
|
|
|
|
|
|
|
const output = this.processPluginAssets(assets);
|
|
|
|
|
|
|
|
this.allProcessedAssets_ = {
|
|
|
|
[cacheKey]: output,
|
|
|
|
};
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is similar to allProcessedAssets() but used only by the Rich Text editor
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2021-08-14 13:19:53 +02:00
|
|
|
public async allAssets(theme: any, noteStyleOptions: NoteStyleOptions = null) {
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
const assets: any = {};
|
2020-10-21 01:23:55 +02:00
|
|
|
for (const key in rules) {
|
|
|
|
if (!this.pluginEnabled(key)) continue;
|
|
|
|
const rule = rules[key];
|
|
|
|
|
|
|
|
if (rule.assets) {
|
|
|
|
assets[key] = rule.assets(theme);
|
2020-03-23 02:47:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const processedAssets = this.processPluginAssets(assets);
|
2021-08-14 13:19:53 +02:00
|
|
|
processedAssets.cssStrings.splice(0, 0, noteStyle(theme, noteStyleOptions).join('\n'));
|
2021-05-19 15:00:16 +02:00
|
|
|
if (this.customCss_) processedAssets.cssStrings.push(this.customCss_);
|
2020-03-23 02:47:25 +02:00
|
|
|
const output = await this.outputAssetsToExternalAssets_(processedAssets);
|
|
|
|
return output.pluginAssets;
|
|
|
|
}
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
private async outputAssetsToExternalAssets_(output: any) {
|
2020-03-23 02:47:25 +02:00
|
|
|
for (const cssString of output.cssStrings) {
|
2021-05-19 15:00:16 +02:00
|
|
|
const filePath = await this.fsDriver().cacheCssToFile(cssString);
|
|
|
|
output.pluginAssets.push(filePath);
|
2020-03-23 02:47:25 +02:00
|
|
|
}
|
|
|
|
delete output.cssStrings;
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
// The string we are looking for is: <p></p>\n
|
2020-11-12 21:13:28 +02:00
|
|
|
private removeMarkdownItWrappingParagraph_(html: string) {
|
2020-07-04 13:17:30 +02:00
|
|
|
if (html.length < 8) return html;
|
2020-11-05 18:58:23 +02:00
|
|
|
|
|
|
|
// If there are multiple <p> tags, we keep them because it's multiple lines
|
|
|
|
// and removing the first and last tag will result in invalid HTML.
|
|
|
|
if ((html.match(/<\/p>/g) || []).length > 1) return html;
|
|
|
|
|
2020-07-04 13:17:30 +02:00
|
|
|
if (html.substr(0, 3) !== '<p>') return html;
|
|
|
|
if (html.slice(-5) !== '</p>\n') return html;
|
|
|
|
return html.substring(3, html.length - 5);
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
public clearCache() {
|
2020-10-16 17:26:19 +02:00
|
|
|
this.cachedOutputs_ = {};
|
|
|
|
}
|
|
|
|
|
2021-10-30 18:47:16 +02:00
|
|
|
private removeLastNewLine(s: string): string {
|
|
|
|
if (s[s.length - 1] === '\n') {
|
|
|
|
return s.substr(0, s.length - 1);
|
|
|
|
} else {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rendering large code blocks can freeze the app so we disable it in
|
|
|
|
// certain cases:
|
|
|
|
// https://github.com/laurent22/joplin/issues/5593#issuecomment-947374218
|
|
|
|
private shouldSkipHighlighting(str: string, lang: string): boolean {
|
|
|
|
if (lang && !hljs.getLanguage(lang)) lang = '';
|
|
|
|
if (str.length >= 1000 && !lang) return true;
|
|
|
|
if (str.length >= 512000 && lang) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-16 17:26:19 +02:00
|
|
|
// "theme" is the theme as returned by themeStyle()
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2021-08-14 13:19:53 +02:00
|
|
|
public async render(body: string, theme: any = null, options: RenderOptions = null): Promise<RenderResult> {
|
|
|
|
|
|
|
|
options = {
|
2020-03-23 02:47:25 +02:00
|
|
|
// In bodyOnly mode, the rendered Markdown is returned without the wrapper DIV
|
2020-03-10 01:24:57 +02:00
|
|
|
bodyOnly: false,
|
2020-03-23 02:47:25 +02:00
|
|
|
// In splitted mode, the CSS and HTML will be returned in separate properties.
|
|
|
|
// In non-splitted mode, CSS and HTML will be merged in the same document.
|
2020-03-10 01:24:57 +02:00
|
|
|
splitted: false,
|
2020-03-23 02:47:25 +02:00
|
|
|
// When this is true, all assets such as CSS or JS are returned as external
|
|
|
|
// files. Otherwise some of them might be in the cssStrings property.
|
2020-03-10 01:24:57 +02:00
|
|
|
externalAssetsOnly: false,
|
|
|
|
postMessageSyntax: 'postMessage',
|
|
|
|
highlightedKeywords: [],
|
|
|
|
codeTheme: 'atom-one-light.css',
|
2023-06-01 13:02:36 +02:00
|
|
|
theme: { ...defaultNoteStyle, ...theme },
|
2020-03-23 02:47:25 +02:00
|
|
|
plugins: {},
|
2020-12-09 23:30:51 +02:00
|
|
|
|
|
|
|
audioPlayerEnabled: this.pluginEnabled('audioPlayer'),
|
|
|
|
videoPlayerEnabled: this.pluginEnabled('videoPlayer'),
|
|
|
|
pdfViewerEnabled: this.pluginEnabled('pdfViewer'),
|
2021-08-14 13:19:53 +02:00
|
|
|
|
|
|
|
contentMaxWidth: 0,
|
2023-11-03 21:45:21 +02:00
|
|
|
settingValue: (_pluginId: string, _key: string) => { throw new Error('settingValue is not implemented'); },
|
2021-08-14 13:19:53 +02:00
|
|
|
...options,
|
|
|
|
};
|
2020-01-30 23:05:23 +02:00
|
|
|
|
|
|
|
// The "codeHighlightCacheKey" option indicates what set of cached object should be
|
|
|
|
// associated with this particular Markdown body. It is only used to allow us to
|
|
|
|
// clear the cache whenever switching to a different note.
|
|
|
|
// If "codeHighlightCacheKey" is not specified, code highlighting won't be cached.
|
|
|
|
if (options.codeHighlightCacheKey !== this.lastCodeHighlightCacheKey_ || !options.codeHighlightCacheKey) {
|
|
|
|
this.cachedHighlightedCode_ = {};
|
|
|
|
this.lastCodeHighlightCacheKey_ = options.codeHighlightCacheKey;
|
|
|
|
}
|
|
|
|
|
2021-07-23 12:05:21 +02:00
|
|
|
const cacheKey = md5(escape(body + this.customCss_ + JSON.stringify(options) + JSON.stringify(options.theme)));
|
2020-01-30 23:05:23 +02:00
|
|
|
const cachedOutput = this.cachedOutputs_[cacheKey];
|
|
|
|
if (cachedOutput) return cachedOutput;
|
|
|
|
|
2023-11-03 21:45:21 +02:00
|
|
|
const ruleOptions = {
|
|
|
|
...options,
|
|
|
|
resourceBaseUrl: this.resourceBaseUrl_,
|
|
|
|
ResourceModel: this.ResourceModel_,
|
|
|
|
};
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const context: PluginContext = {
|
2020-10-21 01:23:55 +02:00
|
|
|
css: {},
|
|
|
|
pluginAssets: {},
|
|
|
|
cache: this.contextCache_,
|
|
|
|
userData: {},
|
2020-12-09 23:30:51 +02:00
|
|
|
currentLinks: [],
|
2024-06-04 00:49:09 +02:00
|
|
|
pluginWasUsed: {
|
|
|
|
mermaid: false,
|
|
|
|
katex: false,
|
|
|
|
},
|
2020-10-21 01:23:55 +02:00
|
|
|
};
|
|
|
|
|
2023-11-03 21:45:21 +02:00
|
|
|
const markdownIt: MarkdownIt = new MarkdownIt({
|
2020-01-30 23:05:23 +02:00
|
|
|
breaks: !this.pluginEnabled('softbreaks'),
|
|
|
|
typographer: this.pluginEnabled('typographer'),
|
2020-12-09 23:52:52 +02:00
|
|
|
linkify: this.pluginEnabled('linkify'),
|
2020-01-30 23:05:23 +02:00
|
|
|
html: true,
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-11-03 21:45:21 +02:00
|
|
|
highlight: (str: string, lang: string, _attrs: any): any => {
|
2020-03-10 01:24:57 +02:00
|
|
|
let outputCodeHtml = '';
|
|
|
|
|
|
|
|
// The strings includes the last \n that is part of the fence,
|
|
|
|
// so we remove it because we need the exact code in the source block
|
2021-10-30 18:47:16 +02:00
|
|
|
const trimmedStr = this.removeLastNewLine(str);
|
2022-11-14 19:16:59 +02:00
|
|
|
const sourceBlockHtml = `<pre class="joplin-source" data-joplin-language="${htmlentities(lang)}" data-joplin-source-open="\`\`\`${htmlentities(lang)} " data-joplin-source-close=" \`\`\`">${markdownIt.utils.escapeHtml(trimmedStr)}</pre>`;
|
2020-03-10 01:24:57 +02:00
|
|
|
|
2021-10-30 18:47:16 +02:00
|
|
|
if (this.shouldSkipHighlighting(trimmedStr, lang)) {
|
|
|
|
outputCodeHtml = markdownIt.utils.escapeHtml(trimmedStr);
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
let hlCode = '';
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2021-10-30 18:47:16 +02:00
|
|
|
const cacheKey = md5(`${str}_${lang}`);
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2023-03-07 19:51:29 +02:00
|
|
|
if (options.codeHighlightCacheKey && cacheKey in this.cachedHighlightedCode_) {
|
2021-10-30 18:47:16 +02:00
|
|
|
hlCode = this.cachedHighlightedCode_[cacheKey];
|
2020-01-30 23:05:23 +02:00
|
|
|
} else {
|
2021-10-30 18:47:16 +02:00
|
|
|
if (lang && hljs.getLanguage(lang)) {
|
|
|
|
hlCode = hljs.highlight(trimmedStr, { language: lang, ignoreIllegals: true }).value;
|
|
|
|
} else {
|
|
|
|
hlCode = hljs.highlightAuto(trimmedStr).value;
|
|
|
|
}
|
|
|
|
this.cachedHighlightedCode_[cacheKey] = hlCode;
|
2020-01-30 23:05:23 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 18:47:16 +02:00
|
|
|
outputCodeHtml = hlCode;
|
|
|
|
} catch (error) {
|
|
|
|
outputCodeHtml = markdownIt.utils.escapeHtml(trimmedStr);
|
|
|
|
}
|
2020-01-30 23:05:23 +02:00
|
|
|
}
|
2020-03-10 01:24:57 +02:00
|
|
|
|
2020-11-23 18:26:34 +02:00
|
|
|
const html = `<div class="joplin-editable">${sourceBlockHtml}<pre class="hljs"><code>${outputCodeHtml}</code></pre></div>`;
|
|
|
|
|
|
|
|
if (rules.fence) {
|
|
|
|
return {
|
|
|
|
wrapCode: false,
|
|
|
|
html: html,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return html;
|
|
|
|
}
|
2020-01-30 23:05:23 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// To add a plugin, there are three options:
|
|
|
|
//
|
|
|
|
// 1. If the plugin does not need any application specific data, use the standard way:
|
|
|
|
//
|
|
|
|
// const someMarkdownPlugin = require('someMarkdownPlugin');
|
|
|
|
// markdownIt.use(someMarkdownPlugin);
|
|
|
|
//
|
|
|
|
// 2. If the plugin does not need any application specific data, and you want the user
|
|
|
|
// to be able to toggle the plugin:
|
|
|
|
//
|
|
|
|
// Add the plugin to the plugins object
|
|
|
|
// const plugins = {
|
|
|
|
// plugin: require('someMarkdownPlugin'),
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// And add a corresponding entry into Setting.js
|
|
|
|
// 'markdown.plugin.mark': {value: true, type: Setting.TYPE_BOOL, section: 'plugins', public: true, appTypes: ['mobile', 'desktop'], label: () => _('Enable ==mark== syntax')},
|
|
|
|
//
|
|
|
|
// 3. If the plugin needs application data (in ruleOptions) or needs to pass data (CSS, files to load, etc.) back
|
|
|
|
// to the application (using the context object), use the application-specific way:
|
|
|
|
//
|
|
|
|
// const imagePlugin = require('./MdToHtml/rules/image');
|
|
|
|
// markdownIt.use(imagePlugin(context, ruleOptions));
|
|
|
|
//
|
|
|
|
// Using the `context` object, a plugin can define what additional assets they need (css, fonts, etc.) using context.pluginAssets.
|
|
|
|
// The calling application will need to handle loading these assets.
|
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const allRules = { ...rules, ...this.extraRendererRules_ };
|
2020-10-21 01:23:55 +02:00
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2024-03-20 13:01:09 +02:00
|
|
|
const loadPlugin = (plugin: any, options: any) => {
|
|
|
|
// Handle the case where we're bundling with webpack --
|
|
|
|
// some modules that are commonjs imports in nodejs
|
|
|
|
// act like ES6 imports.
|
|
|
|
if (typeof plugin !== 'function' && plugin.default) {
|
|
|
|
plugin = plugin.default;
|
|
|
|
}
|
|
|
|
|
|
|
|
markdownIt.use(plugin, options);
|
|
|
|
};
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
for (const key in allRules) {
|
2020-03-23 02:47:25 +02:00
|
|
|
if (!this.pluginEnabled(key)) continue;
|
2020-10-21 01:23:55 +02:00
|
|
|
|
|
|
|
const rule = allRules[key];
|
|
|
|
|
2024-03-20 13:01:09 +02:00
|
|
|
loadPlugin(rule.plugin, {
|
2020-10-21 01:23:55 +02:00
|
|
|
context: context,
|
|
|
|
...ruleOptions,
|
|
|
|
...(ruleOptions.plugins[key] ? ruleOptions.plugins[key] : {}),
|
2023-11-03 21:45:21 +02:00
|
|
|
settingValue: (key: string) => {
|
|
|
|
return options.settingValue(rule.pluginId, key);
|
|
|
|
},
|
2020-10-21 01:23:55 +02:00
|
|
|
});
|
2020-03-23 02:47:25 +02:00
|
|
|
}
|
|
|
|
|
2024-03-20 13:01:09 +02:00
|
|
|
loadPlugin(markdownItAnchor, { slugify: slugify });
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const key in plugins) {
|
2020-10-09 19:35:46 +02:00
|
|
|
if (this.pluginEnabled(key)) {
|
2024-03-20 13:01:09 +02:00
|
|
|
loadPlugin(plugins[key].module, plugins[key].options);
|
2020-10-09 19:35:46 +02:00
|
|
|
}
|
2020-01-30 23:05:23 +02:00
|
|
|
}
|
|
|
|
|
2021-01-02 18:53:59 +02:00
|
|
|
markdownIt.validateLink = validateLinks;
|
|
|
|
|
2020-12-09 23:52:52 +02:00
|
|
|
if (this.pluginEnabled('linkify')) setupLinkify(markdownIt);
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
const renderedBody = markdownIt.render(body, context);
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2021-08-14 13:19:53 +02:00
|
|
|
let cssStrings = noteStyle(options.theme, {
|
|
|
|
contentMaxWidth: options.contentMaxWidth,
|
|
|
|
});
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2024-06-04 00:49:09 +02:00
|
|
|
let output: RenderResult = { ...this.allProcessedAssets(allRules, options.theme, options.codeTheme) };
|
|
|
|
|
|
|
|
output.pluginAssets = output.pluginAssets.filter(pa => {
|
|
|
|
if (!context.pluginWasUsed.mermaid && pa.source === 'mermaid') return false;
|
|
|
|
if (!context.pluginWasUsed.katex && pa.source === 'katex') return false;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2020-03-23 02:47:25 +02:00
|
|
|
cssStrings = cssStrings.concat(output.cssStrings);
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2021-05-19 15:00:16 +02:00
|
|
|
if (this.customCss_) cssStrings.push(this.customCss_);
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2020-02-14 11:43:22 +02:00
|
|
|
if (options.bodyOnly) {
|
2020-07-04 13:17:30 +02:00
|
|
|
// Markdown-it wraps any content in <p></p> by default. There's a function to parse without
|
|
|
|
// adding these tags (https://github.com/markdown-it/markdown-it/issues/540#issuecomment-471123983)
|
|
|
|
// however when using it, it seems the loaded plugins are not used. In my tests, just changing
|
|
|
|
// render() to renderInline() means the checkboxes would not longer be rendered. So instead
|
|
|
|
// of using this function, we manually remove the <p></p> tags.
|
|
|
|
output.html = this.removeMarkdownItWrappingParagraph_(renderedBody);
|
2020-03-10 01:24:57 +02:00
|
|
|
output.cssStrings = cssStrings;
|
2020-03-23 02:47:25 +02:00
|
|
|
} else {
|
|
|
|
const styleHtml = `<style>${cssStrings.join('\n')}</style>`;
|
|
|
|
output.html = `${styleHtml}<div id="rendered-md">${renderedBody}</div>`;
|
2020-03-10 01:24:57 +02:00
|
|
|
|
2020-03-23 02:47:25 +02:00
|
|
|
if (options.splitted) {
|
|
|
|
output.cssStrings = cssStrings;
|
|
|
|
output.html = `<div id="rendered-md">${renderedBody}</div>`;
|
2020-03-10 01:24:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-23 02:47:25 +02:00
|
|
|
if (options.externalAssetsOnly) output = await this.outputAssetsToExternalAssets_(output);
|
|
|
|
|
2020-01-30 23:05:23 +02:00
|
|
|
// Fow now, we keep only the last entry in the cache
|
|
|
|
this.cachedOutputs_ = {};
|
|
|
|
this.cachedOutputs_[cacheKey] = output;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|