From 815b9229883cf76b5042a40ec4c7a66d9a1ecf92 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Fri, 13 Dec 2024 04:55:51 -0800 Subject: [PATCH] Mobile: Plugin API: Add support for the renderMarkup command (#11494) --- .eslintignore | 4 ++-- .gitignore | 4 ++-- packages/app-desktop/commands/index.ts | 2 -- packages/app-mobile/web/webpack.config.js | 2 ++ packages/lib/commands/index.ts | 2 ++ .../commands/renderMarkup.test.ts | 10 +++++----- .../{app-desktop => lib}/commands/renderMarkup.ts | 14 ++++++-------- 7 files changed, 19 insertions(+), 19 deletions(-) rename packages/{app-desktop => lib}/commands/renderMarkup.test.ts (86%) rename packages/{app-desktop => lib}/commands/renderMarkup.ts (70%) diff --git a/.eslintignore b/.eslintignore index c78c41902..9714669e5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -159,8 +159,6 @@ packages/app-desktop/commands/focusElement.js packages/app-desktop/commands/index.js packages/app-desktop/commands/openNoteInNewWindow.js packages/app-desktop/commands/openProfileDirectory.js -packages/app-desktop/commands/renderMarkup.test.js -packages/app-desktop/commands/renderMarkup.js packages/app-desktop/commands/replaceMisspelling.js packages/app-desktop/commands/restoreNoteRevision.js packages/app-desktop/commands/startExternalEditing.js @@ -995,6 +993,8 @@ packages/lib/commands/historyForward.js packages/lib/commands/index.js packages/lib/commands/openMasterPasswordDialog.js packages/lib/commands/permanentlyDeleteNote.js +packages/lib/commands/renderMarkup.test.js +packages/lib/commands/renderMarkup.js packages/lib/commands/synchronize.js packages/lib/components/EncryptionConfigScreen/utils.test.js packages/lib/components/EncryptionConfigScreen/utils.js diff --git a/.gitignore b/.gitignore index aac04cbea..18154eb43 100644 --- a/.gitignore +++ b/.gitignore @@ -135,8 +135,6 @@ packages/app-desktop/commands/focusElement.js packages/app-desktop/commands/index.js packages/app-desktop/commands/openNoteInNewWindow.js packages/app-desktop/commands/openProfileDirectory.js -packages/app-desktop/commands/renderMarkup.test.js -packages/app-desktop/commands/renderMarkup.js packages/app-desktop/commands/replaceMisspelling.js packages/app-desktop/commands/restoreNoteRevision.js packages/app-desktop/commands/startExternalEditing.js @@ -971,6 +969,8 @@ packages/lib/commands/historyForward.js packages/lib/commands/index.js packages/lib/commands/openMasterPasswordDialog.js packages/lib/commands/permanentlyDeleteNote.js +packages/lib/commands/renderMarkup.test.js +packages/lib/commands/renderMarkup.js packages/lib/commands/synchronize.js packages/lib/components/EncryptionConfigScreen/utils.test.js packages/lib/components/EncryptionConfigScreen/utils.js diff --git a/packages/app-desktop/commands/index.ts b/packages/app-desktop/commands/index.ts index a05e803d4..60d3a9439 100644 --- a/packages/app-desktop/commands/index.ts +++ b/packages/app-desktop/commands/index.ts @@ -8,7 +8,6 @@ import * as exportNotes from './exportNotes'; import * as focusElement from './focusElement'; import * as openNoteInNewWindow from './openNoteInNewWindow'; import * as openProfileDirectory from './openProfileDirectory'; -import * as renderMarkup from './renderMarkup'; import * as replaceMisspelling from './replaceMisspelling'; import * as restoreNoteRevision from './restoreNoteRevision'; import * as startExternalEditing from './startExternalEditing'; @@ -30,7 +29,6 @@ const index: any[] = [ focusElement, openNoteInNewWindow, openProfileDirectory, - renderMarkup, replaceMisspelling, restoreNoteRevision, startExternalEditing, diff --git a/packages/app-mobile/web/webpack.config.js b/packages/app-mobile/web/webpack.config.js index d43d17b54..23255cb3c 100644 --- a/packages/app-mobile/web/webpack.config.js +++ b/packages/app-mobile/web/webpack.config.js @@ -15,6 +15,8 @@ const babelLoaderConfiguration = { // Compiling these libraries with babel cause build errors. /.*node_modules[/\\]@babel.*/, /.*node_modules[/\\]@sqlite\.org[/\\].*/, + /.*node_modules[/\\]markdown-it-anchor[/\\].*/, + /.*node_modules[/\\]markdown-it-toc-done-right[/\\].*/, ], use: { diff --git a/packages/lib/commands/index.ts b/packages/lib/commands/index.ts index 334f5e100..4789aab07 100644 --- a/packages/lib/commands/index.ts +++ b/packages/lib/commands/index.ts @@ -4,6 +4,7 @@ import * as historyBackward from './historyBackward'; import * as historyForward from './historyForward'; import * as openMasterPasswordDialog from './openMasterPasswordDialog'; import * as permanentlyDeleteNote from './permanentlyDeleteNote'; +import * as renderMarkup from './renderMarkup'; import * as synchronize from './synchronize'; const index: any[] = [ @@ -12,6 +13,7 @@ const index: any[] = [ historyForward, openMasterPasswordDialog, permanentlyDeleteNote, + renderMarkup, synchronize, ]; diff --git a/packages/app-desktop/commands/renderMarkup.test.ts b/packages/lib/commands/renderMarkup.test.ts similarity index 86% rename from packages/app-desktop/commands/renderMarkup.test.ts rename to packages/lib/commands/renderMarkup.test.ts index 101801b8f..44923b058 100644 --- a/packages/app-desktop/commands/renderMarkup.test.ts +++ b/packages/lib/commands/renderMarkup.test.ts @@ -1,7 +1,7 @@ -import shim from '@joplin/lib/shim'; -import Resource from '@joplin/lib/models/Resource'; -import Note from '@joplin/lib/models/Note'; -import { setupDatabaseAndSynchronizer, supportDir, switchClient } from '@joplin/lib/testing/test-utils'; +import shim from '../shim'; +import Resource from '../models/Resource'; +import Note from '../models/Note'; +import { setupDatabaseAndSynchronizer, supportDir, switchClient } from '../testing/test-utils'; import { runtime } from './renderMarkup'; import { MarkupLanguage } from '@joplin/renderer'; const testImagePath = `${supportDir}/photo.jpg`; @@ -38,7 +38,7 @@ describe('renderMarkup', () => { const resource = (await Resource.all())[0]; const noteBody = (await Note.load(note.id)).body; const renderedNote = await await command.execute(null, MarkupLanguage.Markdown, noteBody); - expect(renderedNote.html).toContain(`

photo.jpg

'); } diff --git a/packages/app-desktop/commands/renderMarkup.ts b/packages/lib/commands/renderMarkup.ts similarity index 70% rename from packages/app-desktop/commands/renderMarkup.ts rename to packages/lib/commands/renderMarkup.ts index 44bfcfe24..0fb7a213f 100644 --- a/packages/app-desktop/commands/renderMarkup.ts +++ b/packages/lib/commands/renderMarkup.ts @@ -1,8 +1,8 @@ -import markupLanguageUtils from '@joplin/lib/markupLanguageUtils'; -import Setting from '@joplin/lib/models/Setting'; -import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService'; -import { themeStyle } from '@joplin/lib/theme'; -import attachedResources from '@joplin/lib/utils/attachedResources'; +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'; @@ -12,10 +12,8 @@ export const declaration: CommandDeclaration = { }; const getMarkupToHtml = () => { - const resourceBaseUrl = `joplin-content://note-viewer/${Setting.value('resourceDir')}/`; - return markupLanguageUtils.newMarkupToHtml({}, { - resourceBaseUrl, + resourceBaseUrl: `file://${Setting.value('resourceDir')}/`, customCss: '', }); };