1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Mobile: Performance: Improve Rich Text Editor startup performance (#12819)

This commit is contained in:
Henry Heino
2025-07-30 02:52:57 -07:00
committed by GitHub
parent 4c3eca1f18
commit 5e70bce2c3
10 changed files with 59 additions and 25 deletions

View File

@@ -873,7 +873,8 @@ packages/app-mobile/contentScripts/rendererBundle/useWebViewSetup.js
packages/app-mobile/contentScripts/rendererBundle/utils/useContentScripts.js packages/app-mobile/contentScripts/rendererBundle/utils/useContentScripts.js
packages/app-mobile/contentScripts/rendererBundle/utils/useEditPopup.test.js packages/app-mobile/contentScripts/rendererBundle/utils/useEditPopup.test.js
packages/app-mobile/contentScripts/rendererBundle/utils/useEditPopup.js packages/app-mobile/contentScripts/rendererBundle/utils/useEditPopup.js
packages/app-mobile/contentScripts/richTextEditorBundle/contentScript.js packages/app-mobile/contentScripts/richTextEditorBundle/contentScript/convertHtmlToMarkdown.js
packages/app-mobile/contentScripts/richTextEditorBundle/contentScript/index.js
packages/app-mobile/contentScripts/richTextEditorBundle/types.js packages/app-mobile/contentScripts/richTextEditorBundle/types.js
packages/app-mobile/contentScripts/richTextEditorBundle/useWebViewSetup.js packages/app-mobile/contentScripts/richTextEditorBundle/useWebViewSetup.js
packages/app-mobile/contentScripts/types.js packages/app-mobile/contentScripts/types.js

3
.gitignore vendored
View File

@@ -846,7 +846,8 @@ packages/app-mobile/contentScripts/rendererBundle/useWebViewSetup.js
packages/app-mobile/contentScripts/rendererBundle/utils/useContentScripts.js packages/app-mobile/contentScripts/rendererBundle/utils/useContentScripts.js
packages/app-mobile/contentScripts/rendererBundle/utils/useEditPopup.test.js packages/app-mobile/contentScripts/rendererBundle/utils/useEditPopup.test.js
packages/app-mobile/contentScripts/rendererBundle/utils/useEditPopup.js packages/app-mobile/contentScripts/rendererBundle/utils/useEditPopup.js
packages/app-mobile/contentScripts/richTextEditorBundle/contentScript.js packages/app-mobile/contentScripts/richTextEditorBundle/contentScript/convertHtmlToMarkdown.js
packages/app-mobile/contentScripts/richTextEditorBundle/contentScript/index.js
packages/app-mobile/contentScripts/richTextEditorBundle/types.js packages/app-mobile/contentScripts/richTextEditorBundle/types.js
packages/app-mobile/contentScripts/richTextEditorBundle/useWebViewSetup.js packages/app-mobile/contentScripts/richTextEditorBundle/useWebViewSetup.js
packages/app-mobile/contentScripts/types.js packages/app-mobile/contentScripts/types.js

View File

@@ -1,6 +1,6 @@
import MarkupToHtml, { MarkupLanguage } from '@joplin/renderer/MarkupToHtml'; import MarkupToHtml from '@joplin/renderer/MarkupToHtml';
import { RenderResult } from '@joplin/renderer/types'; import { RenderResult, MarkupLanguage } from '@joplin/renderer/types';
describe('MarkupToHtml', () => { describe('MarkupToHtml', () => {

View File

@@ -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 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 // Joplin settings (as from Setting.value(...)) that should
// remain constant during editing. // remain constant during editing.

View File

@@ -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;

View File

@@ -1,12 +1,12 @@
import '../utils/polyfills'; import '../../utils/polyfills';
import { createEditor } from '@joplin/editor/ProseMirror'; import { createEditor } from '@joplin/editor/ProseMirror';
import { EditorProcessApi, EditorProps, MainProcessApi } from './types'; import { EditorProcessApi, EditorProps, MainProcessApi } from '../types';
import WebViewToRNMessenger from '../../utils/ipc/WebViewToRNMessenger'; import WebViewToRNMessenger from '../../../utils/ipc/WebViewToRNMessenger';
import { MarkupLanguage } from '@joplin/renderer'; import { MarkupLanguage } from '@joplin/renderer/types';
import '@joplin/editor/ProseMirror/styles'; 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 { EditorLanguageType } from '@joplin/editor/types';
import convertHtmlToMarkdown from './convertHtmlToMarkdown';
const postprocessHtml = (html: HTMLElement) => { const postprocessHtml = (html: HTMLElement) => {
// Fix resource URLs // Fix resource URLs
@@ -45,11 +45,10 @@ const wrapHtmlForMarkdownConversion = (html: HTMLElement) => {
}; };
const htmlToMd = new HtmlToMd();
const htmlToMarkdown = (html: HTMLElement): string => { const htmlToMarkdown = (html: HTMLElement): string => {
html = postprocessHtml(html); html = postprocessHtml(html);
return htmlToMd.parse(html, { preserveColorStyles: true }); return convertHtmlToMarkdown(html);
}; };
export const initialize = async ({ export const initialize = async ({
@@ -127,5 +126,5 @@ export const initialize = async ({
return editor; return editor;
}; };
export { default as setUpLogger } from '../utils/setUpLogger'; export { default as setUpLogger } from '../../utils/setUpLogger';

View File

@@ -1,11 +1,12 @@
import markdownUtils from './markdownUtils'; import markdownUtils from './markdownUtils';
import Setting from './models/Setting'; import Setting from './models/Setting';
import shim from './shim'; import shim from './shim';
import MarkupToHtml, { MarkupLanguage, Options } from '@joplin/renderer/MarkupToHtml'; import MarkupToHtml, { Options } from '@joplin/renderer/MarkupToHtml';
import htmlUtils from './htmlUtils'; import htmlUtils from './htmlUtils';
import Resource from './models/Resource'; import Resource from './models/Resource';
import { PluginStates } from './services/plugins/reducer'; import { PluginStates } from './services/plugins/reducer';
import { MarkupLanguage } from '@joplin/renderer';
export class MarkupLanguageUtils { export class MarkupLanguageUtils {

View File

@@ -3,16 +3,10 @@ import HtmlToHtml from './HtmlToHtml';
import htmlUtils from './htmlUtils'; import htmlUtils from './htmlUtils';
import { Options as NoteStyleOptions } from './noteStyle'; import { Options as NoteStyleOptions } from './noteStyle';
import { AllHtmlEntities } from 'html-entities'; import { AllHtmlEntities } from 'html-entities';
import { FsDriver, MarkupRenderer, MarkupToHtmlConverter, OptionsResourceModel, RenderOptions, RenderResult } from './types'; import { FsDriver, MarkupLanguage, MarkupRenderer, MarkupToHtmlConverter, OptionsResourceModel, RenderOptions, RenderResult } from './types';
import defaultResourceModel from './defaultResourceModel'; import defaultResourceModel from './defaultResourceModel';
const MarkdownIt = require('markdown-it'); const MarkdownIt = require('markdown-it');
export enum MarkupLanguage {
Markdown = 1,
Html = 2,
Any = 3,
}
export interface PluginOptions { export interface PluginOptions {
[id: string]: { enabled: boolean }; [id: string]: { enabled: boolean };
} }

View File

@@ -1,4 +1,4 @@
import MarkupToHtml, { MarkupLanguage } from './MarkupToHtml'; import MarkupToHtml from './MarkupToHtml';
import MdToHtml from './MdToHtml'; import MdToHtml from './MdToHtml';
import HtmlToHtml from './HtmlToHtml'; import HtmlToHtml from './HtmlToHtml';
import * as utils from './utils'; import * as utils from './utils';
@@ -6,6 +6,7 @@ import setupLinkify from './MdToHtml/setupLinkify';
import validateLinks from './MdToHtml/validateLinks'; import validateLinks from './MdToHtml/validateLinks';
import headerAnchor from './headerAnchor'; import headerAnchor from './headerAnchor';
import assetsToHeaders from './assetsToHeaders'; import assetsToHeaders from './assetsToHeaders';
import { MarkupLanguage } from './types';
export { export {
MarkupToHtml, MarkupToHtml,

View File

@@ -1,6 +1,11 @@
import { MarkupLanguage } from './MarkupToHtml';
import { Options as NoteStyleOptions } from './noteStyle'; import { Options as NoteStyleOptions } from './noteStyle';
export enum MarkupLanguage {
Markdown = 1,
Html = 2,
Any = 3,
}
export type ItemIdToUrlHandler = (resourceId: string, urlParameters?: string)=> string; export type ItemIdToUrlHandler = (resourceId: string, urlParameters?: string)=> string;
interface ResourceEntity { interface ResourceEntity {