diff --git a/.eslintignore b/.eslintignore index fb2f23ece..d6c33847f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -845,6 +845,7 @@ packages/plugins/ToggleSidebars/api/index.js packages/plugins/ToggleSidebars/api/types.js packages/plugins/ToggleSidebars/src/index.js packages/react-native-saf-x/src/index.js +packages/renderer/HtmlToHtml.test.js packages/renderer/HtmlToHtml.js packages/renderer/InMemoryCache.js packages/renderer/MarkupToHtml.js diff --git a/.gitignore b/.gitignore index ec6be3b52..61ffca103 100644 --- a/.gitignore +++ b/.gitignore @@ -830,6 +830,7 @@ packages/plugins/ToggleSidebars/api/index.js packages/plugins/ToggleSidebars/api/types.js packages/plugins/ToggleSidebars/src/index.js packages/react-native-saf-x/src/index.js +packages/renderer/HtmlToHtml.test.js packages/renderer/HtmlToHtml.js packages/renderer/InMemoryCache.js packages/renderer/MarkupToHtml.js diff --git a/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts b/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts index e742e9be4..1d9a290cd 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts @@ -3,7 +3,7 @@ import { FormNote, defaultFormNote, ResourceInfos } from './types'; import { clearResourceCache, attachedResources } from './resourceHandling'; import AsyncActionQueue from '@joplin/lib/AsyncActionQueue'; import { handleResourceDownloadMode } from './resourceHandling'; -import HtmlToHtml from '@joplin/renderer/HtmlToHtml'; +import { splitHtml } from '@joplin/renderer/HtmlToHtml'; import Setting from '@joplin/lib/models/Setting'; import usePrevious from '../../hooks/usePrevious'; import ResourceEditWatcher from '@joplin/lib/services/ResourceEditWatcher/index'; @@ -73,8 +73,7 @@ export default function useFormNote(dependencies: HookDependencies) { let originalCss = ''; if (n.markup_language === MarkupToHtml.MARKUP_LANGUAGE_HTML) { - const htmlToHtml = new HtmlToHtml(); - const splitted = htmlToHtml.splitHtml(n.body); + const splitted = splitHtml(n.body); originalCss = splitted.css; } diff --git a/packages/renderer/HtmlToHtml.test.ts b/packages/renderer/HtmlToHtml.test.ts new file mode 100644 index 000000000..6f0e1648b --- /dev/null +++ b/packages/renderer/HtmlToHtml.test.ts @@ -0,0 +1,44 @@ +import { splitHtml, SplittedHtml } from './HtmlToHtml'; + +describe('HtmlToHtml', () => { + + test('should split an HTML string into HTML and CSS', () => { + const testCases: [string, SplittedHtml][] = [ + [ + '', + { + html: '', + css: '', + }, + ], + [ + '\n
another line
', + { + html: '\nanother line
', + css: 'b { font-weight: bold; }', + }, + ], + [ + '\n