| const editor = new Editor({
// ...
events: {
change: this .handleContentChange.bind( this )
}, }); methods: {
handleContentChange () {
const mdText = this .editor.mdEditor.getMarkdown()
this .parseMdTitle(mdText)
},
parseMdTitle (mdText) { // 解析markdown title
const pattern = /^( #+)\s+(.+)/mg
let result = mdText.match(pattern)
if (!result) return
const catalogList = result.map((vv, index) => {
const levelText = vv.match(/^( #+)/)
return {
level: levelText[0].length, // 目录级别
index,
cls: `heading-${levelText[0].length}`,
content: vv.slice(levelText[0].length).trim(), // 内容
}
})
this .catalogList = catalogList |