Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/raw_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ module.exports = function rawRender (hexo, text, options = {}) {
}

return hexo.render.renderSync({
text,
text: text.replace(/[-]{2}/g, 'rDOUBLE_DASHr'),
engine,
})
// these replacements are a temporary fix: see the comments on
// https://github.com/cypress-io/cypress-documentation/pull/935
.replace('–', '--')
.replace('—', '---')
.replace(/rDOUBLE_DASHr/g, '--')
})
}
46 changes: 26 additions & 20 deletions lib/tags/note.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Promise = require('bluebird')
const rawRender = require('../raw_render')

module.exports = function note (hexo, args, content) {
// {% note info Want to see Cypress in action? %}
Expand All @@ -22,30 +23,35 @@ module.exports = function note (hexo, args, content) {
bolt: 'bolt', // useful for tips / hints
}

const className = args.shift()

const toMarkdown = (text) =>
hexo.render.renderSync({ text, engine: 'markdown' })
rawRender(hexo, text, { engine: 'markdown' })

const stripSurroundingParagraph = (text) =>
text.replace(/^<p>/, '').replace(/<\/p>$/, '')
const stripSurroundingParagraph = (text) => {
return text.replace(/^<p>/, '').replace(/<\/p>$/, '')
}

let header = ''
const className = args.shift()
const icon = iconLookup[className]
const renderHeader = (params) => {
if (!params.length) {
return Promise.resolve('')
}

return toMarkdown(params.join(' '))
.then((content) => {
const className = args.shift()
const icon = iconLookup[className]

if (args.length) {
header += `<strong class="note-title foo">
${icon ? `<i class="fa fa-${icon}"></i>` : ''}
${stripSurroundingParagraph(toMarkdown(args.join(' ')))}
</strong>`
return `<strong class="note-title foo">
${icon ? `<i class="fa fa-${icon}"></i>` : ''}
${stripSurroundingParagraph(content)}
</strong>`
})
}

return Promise.resolve(
// these replacements are a temporary fix: see the comments on
// https://github.com/cypress-io/cypress-documentation/pull/935
toMarkdown(content)
.replace('–', '--')
.replace('—', '---')
).then((markdown) => {
return `<blockquote class="note ${className}">${header}${markdown}</blockquote>`
})
Promise.all([
toMarkdown(content),
renderHeader(args),
])
.then(([markdown, header]) => `<blockquote class="note ${className}">${header}${markdown}</blockquote>`)
}