Skip to content

Commit

Permalink
chore: auto prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeandcc committed Sep 7, 2023
1 parent 4b1d81b commit b497061
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/html-to-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ function* scanDocuments({ path, url }) {
return
}

const hast = unified()
.use(parse, { emitParseErrors: false })
.parse(vfile)
const hast = unified().use(parse, { emitParseErrors: false }).parse(vfile)

const article = select('article', hast)
if (!article) {
Expand All @@ -42,23 +40,27 @@ function* scanDocuments({ path, url }) {
const pageTitle = toText(pageTitleElement)
const sectionHeaders = getSectionHeaders(markdown)

const keywords = selectAll('meta[name="keywords"]', hast).reduce((acc, metaNode) => {
if (metaNode.properties.content) {
return acc.concat(metaNode.properties.content.replace(/,/g, ' '))
}
return acc
}, []).join(' ')
const keywords = selectAll('meta[name="keywords"]', hast)
.reduce((acc, metaNode) => {
if (metaNode.properties.content) {
return acc.concat(metaNode.properties.content.replace(/,/g, ' '))
}
return acc
}, [])
.join(' ')

let version = null;
let version = null
if (workerData.loadedVersions) {
const docsearchVersionElement = select('meta[name="docsearch:version"]', hast);
const docsearchVersionElement = select(
'meta[name="docsearch:version"]',
hast
)

version = docsearchVersionElement
? workerData.loadedVersions[docsearchVersionElement.properties.content]
: null;
: null
}


yield {
title: pageTitle,
type: 0,
Expand All @@ -67,11 +69,11 @@ function* scanDocuments({ path, url }) {
// If there is no sections then push the complete content under page title
content: sectionHeaders.length === 0 ? getContent(markdown) : '',
keywords,
version,
version
}

for (const sectionDesc of sectionHeaders) {
const { title, content, ref, tagName } = sectionDesc;
const { title, content, ref, tagName } = sectionDesc
yield {
title,
type: 1,
Expand All @@ -85,7 +87,13 @@ function* scanDocuments({ path, url }) {
}

function getContent(element) {
return toText(element).replace(/\s\s+/g, ' ').replace(/(\r\n|\n|\r)/gm, ' ').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
return toText(element)
.replace(/\s\s+/g, ' ')
.replace(/(\r\n|\n|\r)/gm, ' ')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
}

function getSectionHeaders(element) {
Expand All @@ -112,7 +120,7 @@ function getSectionHeaders(element) {
) {
let currentHeadingNode = parentHeadingNode

for (const node of element.children) {
for (const node of element.children) {
if (is(node, isHeadingNodeTest)) {
trackHeadingNode(node)
currentHeadingNode = node
Expand All @@ -132,7 +140,7 @@ function getSectionHeaders(element) {
return {
...rest,
content: node['_indexed-content']
}
}
})
}

Expand Down

0 comments on commit b497061

Please sign in to comment.