-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugins: Added a renderMarkup command to render MD or HTML markup to …
…HTML
- Loading branch information
Showing
14 changed files
with
91 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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 { MarkupLanguage } from '@joplin/renderer'; | ||
|
||
export const declaration: CommandDeclaration = { | ||
name: 'renderMarkup', | ||
}; | ||
|
||
const getMarkupToHtml = () => { | ||
const resourceBaseUrl = `joplin-content://note-viewer/${Setting.value('resourceDir')}/`; | ||
|
||
return markupLanguageUtils.newMarkupToHtml({}, { | ||
resourceBaseUrl, | ||
customCss: '', | ||
}); | ||
}; | ||
|
||
export const runtime = (): CommandRuntime => { | ||
return { | ||
execute: async (_context: CommandContext, markupLanguage: MarkupLanguage, markup: string) => { | ||
const markupToHtml = getMarkupToHtml(); | ||
const html = await markupToHtml.render(markupLanguage, markup, themeStyle(Setting.value('theme')), { | ||
resources: await attachedResources(markup), | ||
splitted: true, | ||
}); | ||
return html; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import BaseModel from '../BaseModel'; | ||
import Note from '../models/Note'; | ||
import Resource from '../models/Resource'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied | ||
let resourceCache_: any = {}; | ||
|
||
export function clearResourceCache() { | ||
resourceCache_ = {}; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied | ||
export default async function attachedResources(noteBody: string): Promise<any> { | ||
if (!noteBody) return {}; | ||
const resourceIds = await Note.linkedItemIdsByType(BaseModel.TYPE_RESOURCE, noteBody); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied | ||
const output: any = {}; | ||
for (let i = 0; i < resourceIds.length; i++) { | ||
const id = resourceIds[i]; | ||
|
||
if (resourceCache_[id]) { | ||
output[id] = resourceCache_[id]; | ||
} else { | ||
const resource = await Resource.load(id); | ||
const localState = await Resource.localState(resource); | ||
|
||
const o = { | ||
item: resource, | ||
localState: localState, | ||
}; | ||
|
||
// eslint-disable-next-line require-atomic-updates | ||
resourceCache_[id] = o; | ||
output[id] = o; | ||
} | ||
} | ||
|
||
return output; | ||
} |
6 changes: 3 additions & 3 deletions
6
.../app-desktop/utils/markupLanguageUtils.ts → packages/lib/utils/markupLanguageUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters