|
@@ -5,6 +5,10 @@ export class Markdown {
|
|
this.element = document.createElement('div')
|
|
this.element = document.createElement('div')
|
|
this.element.className = 'vditor-preview' +
|
|
this.element.className = 'vditor-preview' +
|
|
(vditor.options.classes.preview ? ' ' + vditor.options.classes.preview : '')
|
|
(vditor.options.classes.preview ? ' ' + vditor.options.classes.preview : '')
|
|
|
|
+
|
|
|
|
+ if (this.element.style.display !== 'none') {
|
|
|
|
+ this.render(vditor)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
render(vditor: Vditor, value?: string) {
|
|
render(vditor: Vditor, value?: string) {
|
|
@@ -14,18 +18,18 @@ export class Markdown {
|
|
|
|
|
|
if (value) {
|
|
if (value) {
|
|
this.element.innerHTML = value
|
|
this.element.innerHTML = value
|
|
- } else if (vditor.options.markdownUrl) {
|
|
|
|
|
|
+ } else if (vditor.options.preview.url) {
|
|
clearTimeout(vditor.mdTimeoutId)
|
|
clearTimeout(vditor.mdTimeoutId)
|
|
vditor.mdTimeoutId = setTimeout(() => {
|
|
vditor.mdTimeoutId = setTimeout(() => {
|
|
const xhr = new XMLHttpRequest()
|
|
const xhr = new XMLHttpRequest()
|
|
- xhr.open('POST', vditor.options.markdownUrl)
|
|
|
|
|
|
+ xhr.open('POST', vditor.options.preview.url)
|
|
xhr.onreadystatechange = () => {
|
|
xhr.onreadystatechange = () => {
|
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
if (xhr.status === 200) {
|
|
if (xhr.status === 200) {
|
|
const responseJSON = JSON.parse(xhr.responseText)
|
|
const responseJSON = JSON.parse(xhr.responseText)
|
|
this.element.innerHTML = responseJSON.html
|
|
this.element.innerHTML = responseJSON.html
|
|
- if (vditor.options.parseMarkdown) {
|
|
|
|
- vditor.options.parseMarkdown(this.element)
|
|
|
|
|
|
+ if (vditor.options.preview.parse) {
|
|
|
|
+ vditor.options.preview.parse(this.element)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -34,7 +38,7 @@ export class Markdown {
|
|
xhr.send(JSON.stringify({
|
|
xhr.send(JSON.stringify({
|
|
markdownText: vditor.editor.element.value,
|
|
markdownText: vditor.editor.element.value,
|
|
}))
|
|
}))
|
|
- }, vditor.options.previewDelay)
|
|
|
|
|
|
+ }, vditor.options.preview.delay)
|
|
} else {
|
|
} else {
|
|
this.element.innerHTML = vditor.editor.element.value
|
|
this.element.innerHTML = vditor.editor.element.value
|
|
}
|
|
}
|