feat: upgrade marked to 0.5.x, fixed #645, close #644 (#662)

This commit is contained in:
cinwell.li
2018-10-31 20:34:56 +08:00
committed by GitHub
parent 1ce37bdc2e
commit a39b214733
5 changed files with 75 additions and 86 deletions

View File

@@ -14,6 +14,7 @@ export function getAndRemoveConfig(str = '') {
if (str) {
str = str
.replace(/^'|'$/, '')
.replace(/:([\w-]+)=?([\w-]+)?/g, (m, key, value) => {
config[key] = (value && value.replace(/"/g, '')) || true
return ''
@@ -37,17 +38,17 @@ const compileMedia = {
},
iframe(url, title) {
return {
code: `<iframe src="${url}" ${title || 'width=100% height=400'}></iframe>`
html: `<iframe src="${url}" ${title || 'width=100% height=400'}></iframe>`
}
},
video(url, title) {
return {
code: `<video src="${url}" ${title || 'controls'}>Not Support</video>`
html: `<video src="${url}" ${title || 'controls'}>Not Support</video>`
}
},
audio(url, title) {
return {
code: `<audio src="${url}" ${title || 'controls'}>Not Support</audio>`
html: `<audio src="${url}" ${title || 'controls'}>Not Support</audio>`
}
},
code(url, title) {
@@ -296,18 +297,6 @@ export class Compiler {
return `<img src="${url}"data-origin="${href}" alt="${text}"${attrs}>`
}
const CHECKED_RE = /^\[([ x])\] +/
origin.listitem = renderer.listitem = function (text) {
const checked = CHECKED_RE.exec(text)
if (checked) {
text = text.replace(
CHECKED_RE,
`<input type="checkbox" ${checked[1] === 'x' ? 'checked' : ''} />`
)
}
return `<li${checked ? ` class="task-list-item"` : ''}>${text}</li>\n`
}
renderer.origin = origin
return renderer

View File

@@ -28,7 +28,12 @@ function walkFetchEmbed({embedTokens, compile, fetch}, cb) {
'\n```\n'
)
} else if (token.embed.type === 'mermaid') {
embedToken = [{type: 'html', text: `<div class="mermaid">\n${text}\n</div>`}]
embedToken = [
{type: 'html', text: `<div class="mermaid">\n${text}\n</div>`}
]
embedToken.links = {}
} else {
embedToken = [{type: 'html', text: text}]
embedToken.links = {}
}
}
@@ -39,10 +44,14 @@ function walkFetchEmbed({embedTokens, compile, fetch}, cb) {
}
})(token)
if (process.env.SSR) {
fetch(token.embed.url).then(next)
if (token.embed.url) {
if (process.env.SSR) {
fetch(token.embed.url).then(next)
} else {
get(token.embed.url).then(next)
}
} else {
get(token.embed.url).then(next)
next(token.embed.html)
}
}
}
@@ -67,16 +76,10 @@ export function prerenderEmbed({compiler, raw = '', fetch}, done) {
const embed = compiler.compileEmbed(href, title)
if (embed) {
if (embed.type === 'markdown' ||
embed.type === 'code' ||
embed.type === 'mermaid'
) {
embedTokens.push({
index,
embed
})
}
return embed.code
embedTokens.push({
index,
embed
})
}
return src

View File

@@ -74,11 +74,8 @@ kbd
padding 3px 5px
vertical-align middle
.task-list-item
list-style-type none
li input[type='checkbox']
margin 0 0.2em 0.25em -1.6em
margin 0 0.2em 0.25em 0
vertical-align middle
/* navbar */