1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Chore: Refactor renderer package: Limit dependency on @joplin/lib and improve type safety (#9701)

This commit is contained in:
Henry Heino
2024-01-18 03:20:10 -08:00
committed by GitHub
parent 352ee6496e
commit f5e1e45f6f
32 changed files with 457 additions and 393 deletions

View File

@@ -1,11 +1,10 @@
import InMemoryCache from './InMemoryCache';
import noteStyle from './noteStyle';
import { fileExtension } from './pathUtils';
import { fileExtension } from '@joplin/utils/path';
import setupLinkify from './MdToHtml/setupLinkify';
import validateLinks from './MdToHtml/validateLinks';
import { ItemIdToUrlHandler } from './utils';
import { RenderResult, RenderResultPluginAsset } from './MarkupToHtml';
import { Options as NoteStyleOptions } from './noteStyle';
import { FsDriver, ItemIdToUrlHandler, MarkupRenderer, OptionsResourceModel, RenderOptions, RenderResult, RenderResultPluginAsset } from './types';
import hljs from './highlight';
import * as MarkdownIt from 'markdown-it';
@@ -13,28 +12,6 @@ const Entities = require('html-entities').AllHtmlEntities;
const htmlentities = new Entities().encode;
const md5 = require('md5');
export interface RenderOptions {
contentMaxWidth?: number;
bodyOnly?: boolean;
splitted?: boolean;
externalAssetsOnly?: boolean;
postMessageSyntax?: string;
highlightedKeywords?: string[];
codeTheme?: string;
theme?: any;
plugins?: Record<string, any>;
audioPlayerEnabled?: boolean;
videoPlayerEnabled?: boolean;
pdfViewerEnabled?: boolean;
codeHighlightCacheKey?: string;
plainResourceRendering?: boolean;
mapsToLine?: boolean;
useCustomPdfViewer?: boolean;
noteId?: string;
vendorDir?: string;
settingValue?: (pluginId: string, key: string)=> any;
}
interface RendererRule {
install(context: any, ruleOptions: any): any;
assets?(theme: any): any;
@@ -109,10 +86,10 @@ export interface ExtraRendererRule {
export interface Options {
resourceBaseUrl?: string;
ResourceModel?: any;
ResourceModel?: OptionsResourceModel;
pluginOptions?: any;
tempDir?: string;
fsDriver?: any;
fsDriver?: FsDriver;
extraRendererRules?: ExtraRendererRule[];
customCss?: string;
}
@@ -150,7 +127,7 @@ export interface RuleOptions {
context: PluginContext;
theme: any;
postMessageSyntax: string;
ResourceModel: any;
ResourceModel: OptionsResourceModel;
resourceBaseUrl: string;
resources: any; // resourceId: Resource
@@ -199,12 +176,12 @@ export interface RuleOptions {
platformName?: string;
}
export default class MdToHtml {
export default class MdToHtml implements MarkupRenderer {
private resourceBaseUrl_: string;
private ResourceModel_: any;
private ResourceModel_: OptionsResourceModel;
private contextCache_: any;
private fsDriver_: any;
private fsDriver_: FsDriver;
private cachedOutputs_: any = {};
private lastCodeHighlightCacheKey_: string = null;