You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
Mobile: Performance: Improve Rich Text Editor startup performance (#12819)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { FsDriver as RendererFsDriver, RenderResult, ResourceInfos } from '@joplin/renderer/types';
|
||||
import type { MarkupLanguage, FsDriver as RendererFsDriver, RenderResult, ResourceInfos } from '@joplin/renderer/types';
|
||||
import type Renderer from './contentScript/Renderer';
|
||||
import { MarkupLanguage, PluginOptions } from '@joplin/renderer/MarkupToHtml';
|
||||
import { PluginOptions } from '@joplin/renderer/MarkupToHtml';
|
||||
|
||||
// Joplin settings (as from Setting.value(...)) that should
|
||||
// remain constant during editing.
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
const TurndownService = require('@joplin/turndown');
|
||||
const turndownPluginGfm = require('@joplin/turndown-plugin-gfm').gfm;
|
||||
|
||||
// Avoid using @joplin/lib/HtmlToMd here. HtmlToMd may cause several megabytes
|
||||
// of additional JavaScript and supporting data to be included.
|
||||
|
||||
const convertHtmlToMarkdown = (html: string|HTMLElement) => {
|
||||
const turndownOpts = {
|
||||
headingStyle: 'atx',
|
||||
codeBlockStyle: 'fenced',
|
||||
preserveImageTagsWithSize: true,
|
||||
preserveNestedTables: true,
|
||||
preserveColorStyles: true,
|
||||
bulletListMarker: '-',
|
||||
emDelimiter: '*',
|
||||
strongDelimiter: '**',
|
||||
allowResourcePlaceholders: true,
|
||||
|
||||
// If soft-breaks are enabled, lines need to end with two or more spaces for
|
||||
// trailing <br/>s to render. See
|
||||
// https://github.com/laurent22/joplin/issues/8430
|
||||
br: ' ',
|
||||
};
|
||||
const turndown = new TurndownService(turndownOpts);
|
||||
turndown.use(turndownPluginGfm);
|
||||
turndown.remove('script');
|
||||
turndown.remove('style');
|
||||
const md = turndown.turndown(html);
|
||||
return md;
|
||||
};
|
||||
|
||||
export default convertHtmlToMarkdown;
|
||||
@@ -1,12 +1,12 @@
|
||||
import '../utils/polyfills';
|
||||
import '../../utils/polyfills';
|
||||
import { createEditor } from '@joplin/editor/ProseMirror';
|
||||
import { EditorProcessApi, EditorProps, MainProcessApi } from './types';
|
||||
import WebViewToRNMessenger from '../../utils/ipc/WebViewToRNMessenger';
|
||||
import { MarkupLanguage } from '@joplin/renderer';
|
||||
import { EditorProcessApi, EditorProps, MainProcessApi } from '../types';
|
||||
import WebViewToRNMessenger from '../../../utils/ipc/WebViewToRNMessenger';
|
||||
import { MarkupLanguage } from '@joplin/renderer/types';
|
||||
import '@joplin/editor/ProseMirror/styles';
|
||||
import HtmlToMd from '@joplin/lib/HtmlToMd';
|
||||
import readFileToBase64 from '../utils/readFileToBase64';
|
||||
import readFileToBase64 from '../../utils/readFileToBase64';
|
||||
import { EditorLanguageType } from '@joplin/editor/types';
|
||||
import convertHtmlToMarkdown from './convertHtmlToMarkdown';
|
||||
|
||||
const postprocessHtml = (html: HTMLElement) => {
|
||||
// Fix resource URLs
|
||||
@@ -45,11 +45,10 @@ const wrapHtmlForMarkdownConversion = (html: HTMLElement) => {
|
||||
};
|
||||
|
||||
|
||||
const htmlToMd = new HtmlToMd();
|
||||
const htmlToMarkdown = (html: HTMLElement): string => {
|
||||
html = postprocessHtml(html);
|
||||
|
||||
return htmlToMd.parse(html, { preserveColorStyles: true });
|
||||
return convertHtmlToMarkdown(html);
|
||||
};
|
||||
|
||||
export const initialize = async ({
|
||||
@@ -127,5 +126,5 @@ export const initialize = async ({
|
||||
return editor;
|
||||
};
|
||||
|
||||
export { default as setUpLogger } from '../utils/setUpLogger';
|
||||
export { default as setUpLogger } from '../../utils/setUpLogger';
|
||||
|
||||
Reference in New Issue
Block a user