зеркало из https://github.com/github/docs.git
remove removeNewlinesFromInlineTags from renderContent (#33586)
This commit is contained in:
Родитель
1eb8c3efb8
Коммит
e650b4cf2a
|
@ -10,11 +10,6 @@ const blankLine = '\\s*?[\r\n]*'
|
|||
const startNextLine = '[^\\S\r\n]*?[-\\*] <a'
|
||||
const blankLineInList = new RegExp(`(${endLine})${blankLine}(${startNextLine})`, 'mg')
|
||||
|
||||
// used below to remove unwanted newlines from inline tags in tables
|
||||
const inlineTags = ['a', 'code', 'em']
|
||||
const inlineTagString = `(?:${inlineTags.join('|')})`
|
||||
const inlineTagRegex = new RegExp(`\n?(</?${inlineTagString}>?)\n?`, 'gm')
|
||||
|
||||
// parse multiple times because some templates contain more templates. :]
|
||||
async function renderContent(template = '', context = {}, options = {}) {
|
||||
// If called with a falsy template, it can't ever become something
|
||||
|
@ -51,11 +46,6 @@ async function renderContent(template = '', context = {}, options = {}) {
|
|||
const vFile = await processor.process(template)
|
||||
let html = vFile.toString()
|
||||
|
||||
// Remove unwanted newlines (which appear as spaces) from inline tags inside tables
|
||||
if (html.includes('<table>')) {
|
||||
html = removeNewlinesFromInlineTags(html)
|
||||
}
|
||||
|
||||
if (options.textOnly) {
|
||||
html = fastTextOnly(html)
|
||||
}
|
||||
|
@ -73,18 +63,6 @@ async function renderContent(template = '', context = {}, options = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
function removeNewlinesFromInlineTags(html) {
|
||||
const $ = cheerio.load(html)
|
||||
|
||||
// see https://cheerio.js.org/#html-htmlstring-
|
||||
$(inlineTags.join(','))
|
||||
.parents('td')
|
||||
.get()
|
||||
.map((tag) => $(tag).html($(tag).html().replace(inlineTagRegex, '$1')))
|
||||
|
||||
return $('body').html()
|
||||
}
|
||||
|
||||
// Given a piece of HTML return it without HTML. E.g.
|
||||
// `<p>Foo & bar</p>` becomes `Foo & bar`
|
||||
// and `A <a href="">link</a> and <code>code</code>` becomes `A link and code`.
|
||||
|
|
Загрузка…
Ссылка в новой задаче