|
| 1 | +'use strict'; |
| 2 | +Object.defineProperty(exports, '__esModule', { value: true }); |
| 3 | +const react_1 = require('react'); |
| 4 | +const markupLanguageUtils_1 = require('@joplin/lib/utils/markupLanguageUtils'); |
| 5 | +const Setting_1 = require('@joplin/lib/models/Setting'); |
| 6 | +const shim_1 = require('@joplin/lib/shim'); |
| 7 | +const { themeStyle } = require('@joplin/lib/theme'); |
| 8 | +const Note_1 = require('@joplin/lib/models/Note'); |
| 9 | +const resourceUtils_1 = require('@joplin/lib/models/utils/resourceUtils'); |
| 10 | +function useMarkupToHtml(deps) { |
| 11 | + const { themeId, customCss, plugins, whiteBackgroundNoteRendering } = deps; |
| 12 | + const resourceBaseUrl = (0, react_1.useMemo)(() => { |
| 13 | + return `joplin-content://note-viewer/${Setting_1.default.value('resourceDir')}/`; |
| 14 | + }, []); |
| 15 | + const markupToHtml = (0, react_1.useMemo)(() => { |
| 16 | + return markupLanguageUtils_1.default.newMarkupToHtml(plugins, { |
| 17 | + resourceBaseUrl, |
| 18 | + customCss: customCss || '', |
| 19 | + }); |
| 20 | + }, [plugins, customCss, resourceBaseUrl]); |
| 21 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied |
| 22 | + return (0, react_1.useCallback)(async (markupLanguage, md, options = null) => { |
| 23 | + options = { replaceResourceInternalToExternalLinks: false, resourceInfos: {}, platformName: shim_1.default.platformName(), ...options }; |
| 24 | + md = md || ''; |
| 25 | + const theme = themeStyle(themeId); |
| 26 | + let resources = {}; |
| 27 | + if (options.replaceResourceInternalToExternalLinks) { |
| 28 | + md = await Note_1.default.replaceResourceInternalToExternalLinks(md, { useAbsolutePaths: true }); |
| 29 | + } else { |
| 30 | + resources = options.resourceInfos; |
| 31 | + } |
| 32 | + delete options.replaceResourceInternalToExternalLinks; |
| 33 | + const result = await markupToHtml.render(markupLanguage, md, theme, { codeTheme: theme.codeThemeCss, resources: resources, postMessageSyntax: 'ipcProxySendToHost', splitted: true, externalAssetsOnly: true, codeHighlightCacheKey: 'useMarkupToHtml', settingValue: deps.settingValue, whiteBackgroundNoteRendering, itemIdToUrl: (id, urlParameters = '') => { |
| 34 | + if (!(id in resources) || !resources[id]) { |
| 35 | + return null; |
| 36 | + } |
| 37 | + return (0, resourceUtils_1.resourceFullPath)(resources[id].item, resourceBaseUrl) + urlParameters; |
| 38 | + }, ...options }); |
| 39 | + return result; |
| 40 | + }, [themeId, markupToHtml, whiteBackgroundNoteRendering, resourceBaseUrl, deps.settingValue]); |
| 41 | +} |
| 42 | +exports.default = useMarkupToHtml; |
| 43 | +// # sourceMappingURL=useMarkupToHtml.js.map |
0 commit comments