Skip to content
Permalink
Browse files

feat: leverage "html content" by default for now

  • Loading branch information...
ulivz committed Feb 8, 2019
1 parent 4b21277 commit 85801e757c3e7abbc1517ed9d2fd8ad4e338dd24
Showing with 19 additions and 3 deletions.
  1. +13 −3 lib/index.js
  2. +6 −0 lib/yuque.js
@@ -15,7 +15,8 @@ const debug = require('debug')(PACKAGE_NAME)
*/

module.exports = (opts, ctx) => {
let { repoId, repoUrl, authToken } = opts
let { repoId, repoUrl, authToken, source } = opts
const useMarkdown = source === 'markdown'

if (repoId) {
assert(
@@ -35,6 +36,10 @@ module.exports = (opts, ctx) => {
return {
name: PACKAGE_NAME,

define: {
USE_MARKDOWN: useMarkdown
},

chainMarkdown(config) {
if (opts.html) {
return
@@ -110,12 +115,17 @@ module.exports = (opts, ctx) => {
spinner.start(`Fetching ${chalk.cyan(title)} ... `)

const { status, data } = await yuque.getPage(slug)
debug('status', status)

let postContent
debug(status)
if (status && status === 404) {
postContent = `# ${title}\n > 此文档尚未创建`
} else {
postContent = data.body
if (useMarkdown) {
postContent = data.body
} else {
postContent = Yuque.beautifyHTML(data.body_html)
}
}

const {
@@ -64,6 +64,12 @@ module.exports = class Yuque {
}
}

static beautifyHTML(html) {
return html
.replace(/<p><br\s\/><\/p>/g, '')
.replace(/<p><span><br\s\/><\/span><\/p>/g, '')
}

static async get(base, path) {
path = `${base}${path}`
return Yuque.fetch(path)

0 comments on commit 85801e7

Please sign in to comment.
You can’t perform that action at this time.