/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/muyajs/lib/utils/turndownService.js
63 строки
2 KB
Ran Luo
chore: convert repo to pnpm monorepo (packages/desktop, muyajs, website) (#4302)
29 май 2026, 05:25
Не верифицирован
29 май 2026, 05:25
565bfcd
Код
Авторство
О чём код?
import TurndownService from 'turndown' import { identity } from './index' import { gfm } from 'joplin-turndown-plugin-gfm' export const usePluginAddRules = (turndownService, keeps) => { // Use the gfm plugin turndownService.use(gfm) // We need a extra strikethrough rule because the strikethrough rule in gfm is single `~`. turndownService.addRule('strikethrough', { filter: ['del', 's', 'strike'], replacement(content) { return '~~' + content + '~~' } }) turndownService.addRule('paragraph', { filter: 'p', replacement: function(content, node) { const isTaskListItemParagraph = node.previousElementSibling && node.previousElementSibling.tagName === 'INPUT' return isTaskListItemParagraph ? content + '\n\n' : '\n\n' + content + '\n\n' } }) turndownService.addRule('listItem', { filter: 'li', replacement: function(content, node, options) { content = content .replace(/^\n+/, '') // remove leading newlines .replace(/\n+$/, '\n') // replace trailing newlines with just a single one .replace(/\n/gm, '\n ') // indent let prefix = options.bulletListMarker + ' ' const parent = node.parentNode if (parent.nodeName === 'OL') { const start = parent.getAttribute('start') const index = Array.prototype.indexOf.call(parent.children, node) prefix = (start ? Number(start) + index : index + 1) + '. ' } return ( prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '') ) } }) // Handle multiple math lines turndownService.addRule('multiplemath', { filter(node, options) { return node.nodeName === 'PRE' && node.classList.contains('multiple-math') }, replacement(content, node, options) { return `$$\n${content}\n$$` } }) turndownService.escape = identity turndownService.keep(keeps) } export default TurndownService