diff --git a/.eslintignore b/.eslintignore index abb29d655..77acd0806 100644 --- a/.eslintignore +++ b/.eslintignore @@ -155,6 +155,7 @@ packages/app-desktop/commands/exportNotes.js packages/app-desktop/commands/focusElement.js packages/app-desktop/commands/index.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 diff --git a/.gitignore b/.gitignore index 7beb12af8..c61785aad 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,7 @@ packages/app-desktop/commands/exportNotes.js packages/app-desktop/commands/focusElement.js packages/app-desktop/commands/index.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 diff --git a/packages/app-desktop/commands/renderMarkup.test.ts b/packages/app-desktop/commands/renderMarkup.test.ts new file mode 100644 index 000000000..83dc3f6ca --- /dev/null +++ b/packages/app-desktop/commands/renderMarkup.test.ts @@ -0,0 +1,47 @@ +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 { runtime } from './renderMarkup'; +import { MarkupLanguage } from '@joplin/renderer'; +const testImagePath = `${supportDir}/photo.jpg`; + +const command = runtime(); + +describe('renderMarkup', () => { + + beforeEach(async () => { + await setupDatabaseAndSynchronizer(1); + await switchClient(1); + }); + + test('should return the rendered note as HTML', async () => { + { + const renderedNote = await command.execute(null, MarkupLanguage.Markdown, 'hello **strong**'); + expect(renderedNote.html).toBe('

hello strong

\n
'); + expect(!!renderedNote.pluginAssets).toBe(true); + expect(!!renderedNote.cssStrings).toBe(true); + } + + { + const renderedNote = await await command.execute(null, MarkupLanguage.Markdown, '- [ ] Beer\n- [x] Milk\n- [ ] Eggs'); + expect(renderedNote.html).toContain('checkbox-label-unchecked">Beer'); + expect(renderedNote.html).toContain('checkbox-label-checked">Milk'); + expect(renderedNote.html).toContain('checkbox-label-unchecked">Eggs'); + expect(!!renderedNote.pluginAssets).toBe(true); + expect(!!renderedNote.cssStrings).toBe(true); + } + + { + const note = await Note.save({ }); + await shim.attachFileToNote(note, testImagePath, null, { resizeLargeImages: 'never' }); + 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/lib/shim.ts b/packages/lib/shim.ts index 8cf494471..4b831904c 100644 --- a/packages/lib/shim.ts +++ b/packages/lib/shim.ts @@ -309,7 +309,7 @@ const shim = { detectAndSetLocale: null as Function, // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied - attachFileToNote: async (_note: any, _filePath: string): Promise => { + attachFileToNote: async (_note: any, _filePath: string, _position: number, _options: any): Promise => { throw new Error('Not implemented: attachFileToNote'); },