Skip to content

Commit

Permalink
feat: monaco codeblock accepts extract options
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 21, 2021
1 parent 3dadfa1 commit e277e9e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/slidev/node/plugins/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export async function createMarkdownPlugin(

export function transformMarkdownMonaco(md: string) {
// transform monaco
md = md.replace(/^```(\w+?)\s*{monaco([\w:,-]*)}[\s\n]*([\s\S]+?)^```/mg, (full, lang = 'ts', options: string, code: string) => {
options = options || ''
md = md.replace(/^```(\w+?)\s*{monaco}\s*?({.*?})?\s*?\n([\s\S]+?)^```/mg, (full, lang = 'ts', options = '{}', code: string) => {
lang = lang.trim()
options = options.trim() || '{}'
const encoded = base64.encode(code, true)
return `<Monaco :code="'${encoded}'" lang="${lang}" :readonly="${options.includes('readonly')}" />`
return `<Monaco :code="'${encoded}'" lang="${lang}" v-bind="${options}" />`
})

return md
Expand Down

0 comments on commit e277e9e

Please sign in to comment.