Skip to content

feat: remove some markdown/html items, while allowing other markdown items to be indexed #17817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion docs/build/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ const processMarkdown = (syntaxTree, entries, entry) => {
.replace(/::: danger/g, '')
.replace(/:::/g, '')
.replace(/\s\s+/g, ' ') // change multi-space to 1 space
.replace(/<script doc>[\s\S]*?<\/script>/g, '') // remove script doc
// .replace(/```(?:js|ts|diff|tabs)[\s\S]*?```/g, '') // remove markdown fences
.trim()

if (text === '') {
Expand Down Expand Up @@ -268,8 +270,21 @@ function processPage (page, entries) {

addItem(entries, entryItem)

let output = frontMatter.content || ''
output = output
// Remove <script doc>xxx</script>
.replace(/<script doc>[\s\S]*?<\/script>/g, '')
// Remove HTML tags
.replace(/<[^>]*>/g, '')
// Remove inline links
.replace(/\[(.*?)\][[(].*?[\])]/g, '$1')
// Remove code blocks
.replace(/(`{3,})(.*?)\1/gm, '')
// Remove inline code (leave content)
.replace(/`(.+?)`/g, '$1')

// get markdown ast
const ast = md(frontMatter.content)
const ast = md(output)

// process ast
processMarkdown(ast, entries, entryItem)
Expand Down