mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 16:11:24 +08:00

* add bullet list marker to preference file * list marker * update change log * update change log * code style and remove debug codes
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import TurndownService from 'turndown'
|
|
import { CLASS_OR_ID, LINE_BREAK } from '../config'
|
|
|
|
const turndownPluginGfm = require('turndown-plugin-gfm')
|
|
|
|
export const usePluginAddRules = turndownService => {
|
|
// Use the gfm plugin
|
|
const { gfm } = turndownPluginGfm
|
|
turndownService.use(gfm)
|
|
// because the strikethrough rule in gfm is single `~`, So need rewrite the strikethrough rule.
|
|
turndownService.addRule('strikethrough', {
|
|
filter: ['del', 's', 'strike'],
|
|
replacement (content) {
|
|
return '~~' + content + '~~'
|
|
}
|
|
})
|
|
|
|
// handle `soft line break` and `hard line break`
|
|
// add `LINE_BREAK` to the end of soft line break and hard line break.
|
|
turndownService.addRule('lineBreak', {
|
|
filter (node, options) {
|
|
return node.nodeName === 'SPAN' && node.classList.contains(CLASS_OR_ID['AG_LINE']) && node.nextElementSibling
|
|
},
|
|
replacement (content, node, options) {
|
|
return content + LINE_BREAK
|
|
}
|
|
})
|
|
|
|
// remove `\` in text when paste
|
|
turndownService.addRule('normalText', {
|
|
filter (node, options) {
|
|
return (node.nodeName === 'SPAN' &&
|
|
node.classList.contains(CLASS_OR_ID['AG_EMOJI_MARKED_TEXT'])) ||
|
|
node.classList.contains('plain-text')
|
|
},
|
|
replacement (content, node, options) {
|
|
return content.replace(/\\(?!\\)/g, '')
|
|
}
|
|
})
|
|
}
|
|
|
|
export default TurndownService
|