From 76c2558cc4be35e322338f359f1d24177d6d0f74 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Thu, 31 Oct 2019 09:45:02 -0400 Subject: [PATCH 1/3] provide proper `--args` for any place utilizing rawRender- `changelog.js`- `note.js` now renders with rawRender --- lib/raw_render.js | 11 ++++++++++- lib/tags/note.js | 7 ++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/raw_render.js b/lib/raw_render.js index d930af53c9..b21e40e168 100644 --- a/lib/raw_render.js +++ b/lib/raw_render.js @@ -10,9 +10,18 @@ module.exports = function rawRender (hexo, text, options = {}) { return text } - return hexo.render.renderSync({ + const output =hexo.render.renderSync({ text, engine, }) + if (engine !== 'markdown'){ + return output + } + + return output + // these replacements are a temporary fix: see the comments on + // https://github.com/cypress-io/cypress-documentation/pull/935 + .replace('–', '--') + .replace('—', '---') }) } diff --git a/lib/tags/note.js b/lib/tags/note.js index a2d76d9f0f..08c807807e 100644 --- a/lib/tags/note.js +++ b/lib/tags/note.js @@ -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? %} @@ -23,7 +24,7 @@ module.exports = function note (hexo, args, content) { } const toMarkdown = (text) => - hexo.render.renderSync({ text, engine: 'markdown' }) + rawRender(hexo, text, {engine: 'markdown'}) const stripSurroundingParagraph = (text) => text.replace(/^

/, '').replace(/<\/p>$/, '') @@ -40,11 +41,7 @@ module.exports = function note (hexo, args, content) { } 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 `

${header}${markdown}
` }) From 20bd058e54d4c136d3c4b7834b307435dc86dfd1 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Thu, 31 Oct 2019 10:08:23 -0400 Subject: [PATCH 2/3] rawRender returns promise and not string `Note.js` update to reflect that rawRender returns a promise and not a string --- lib/raw_render.js | 13 +++++++------ lib/tags/note.js | 41 +++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/lib/raw_render.js b/lib/raw_render.js index b21e40e168..697c273c02 100644 --- a/lib/raw_render.js +++ b/lib/raw_render.js @@ -10,18 +10,19 @@ module.exports = function rawRender (hexo, text, options = {}) { return text } - const output =hexo.render.renderSync({ + const output = hexo.render.renderSync({ text, engine, }) - if (engine !== 'markdown'){ + + if (engine !== 'markdown') { return output } return output - // these replacements are a temporary fix: see the comments on - // https://github.com/cypress-io/cypress-documentation/pull/935 - .replace('–', '--') - .replace('—', '---') + // these replacements are a temporary fix: see the comments on + // https://github.com/cypress-io/cypress-documentation/pull/935 + .replace('–', '--') + .replace('—', '---') }) } diff --git a/lib/tags/note.js b/lib/tags/note.js index 08c807807e..c6e35d6ad6 100644 --- a/lib/tags/note.js +++ b/lib/tags/note.js @@ -23,26 +23,35 @@ module.exports = function note (hexo, args, content) { bolt: 'bolt', // useful for tips / hints } + const className = args.shift() + const toMarkdown = (text) => - rawRender(hexo, text, {engine: 'markdown'}) + rawRender(hexo, text, { engine: 'markdown' }) - const stripSurroundingParagraph = (text) => - text.replace(/^

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

/, '').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 += ` - ${icon ? `` : ''} - ${stripSurroundingParagraph(toMarkdown(args.join(' ')))} - ` + return ` + ${icon ? `` : ''} + ${stripSurroundingParagraph(content)} + ` + }) } - return Promise.resolve( - toMarkdown(content) - ).then((markdown) => { - return `

${header}${markdown}
` - }) + Promise.all([ + toMarkdown(content), + renderHeader(args), + ]) + .then(([markdown, header]) => `
${header}${markdown}
`) } From de090e8f4cffc954faae0fedc41546bfb81e1e33 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Thu, 31 Oct 2019 15:52:34 -0400 Subject: [PATCH 3/3] pre-process `--` => keyword, then post-process keyword => `--` This feels like a hack, but it resolves the issue. --- lib/raw_render.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/raw_render.js b/lib/raw_render.js index 697c273c02..fccc77508e 100644 --- a/lib/raw_render.js +++ b/lib/raw_render.js @@ -10,19 +10,14 @@ module.exports = function rawRender (hexo, text, options = {}) { return text } - const output = hexo.render.renderSync({ - text, + return hexo.render.renderSync({ + text: text.replace(/[-]{2}/g, 'rDOUBLE_DASHr'), engine, }) - - if (engine !== 'markdown') { - return output - } - - return output // 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, '--') }) }