-
-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab4c6ea
commit 138d10e
Showing
7 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ export class Preview { | |
} | ||
} | ||
|
||
public render(vditor: IVditor, value?: string) { | ||
public async render(vditor: IVditor, value?: string) { | ||
if (this.element.style.display === "none") { | ||
return; | ||
} | ||
|
@@ -55,7 +55,33 @@ export class Preview { | |
})); | ||
}, vditor.options.preview.delay); | ||
} else { | ||
this.element.innerHTML = vditor.editor.element.value; | ||
const {default: MarkdownIt} = await import(/* webpackChunkName: "markdown-it" */ "markdown-it"); | ||
const hljsOpt: IHljsOptions = { | ||
html: true, | ||
linkify: true, | ||
typographer: true, | ||
} | ||
if (vditor.options.preview.hljs.style) { | ||
if (!document.getElementById('vditorHljsStyle')){ | ||
const hljsStyle = document.createElement("link") | ||
hljsStyle.id = 'vditorHljsStyle' | ||
hljsStyle.setAttribute("rel", "stylesheet") | ||
hljsStyle.setAttribute("type", "text/css") | ||
hljsStyle.setAttribute("href", `https://cdn.jsdelivr.net/npm/[email protected]/styles/${vditor.options.preview.hljs.style}.min.css`) | ||
document.getElementsByTagName('head')[0].appendChild(hljsStyle) | ||
} | ||
} | ||
if (vditor.options.preview.hljs.enable) { | ||
const {default: hljs} = await import(/* webpackChunkName: "highlight.js" */ "highlight.js"); | ||
hljsOpt.highlight = (str: string, lang: string) => { | ||
if (lang && hljs.getLanguage(lang)) { | ||
return hljs.highlight(lang, str, true).value | ||
} | ||
return hljs.highlightAuto(str).value; | ||
} | ||
} | ||
const md = new MarkdownIt(hljsOpt); | ||
this.element.innerHTML = md.render(vditor.editor.element.value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters