Convert em to mark in search results (#17391)
This commit is contained in:
@@ -39,6 +39,6 @@ export default function h (tagName, ...children) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const tags = Object.fromEntries(
|
export const tags = Object.fromEntries(
|
||||||
['div', 'form', 'a', 'input', 'button', 'ol', 'li', 'em']
|
['div', 'form', 'a', 'input', 'button', 'ol', 'li', 'mark']
|
||||||
.map(tagName => [tagName, (...args) => h(tagName, ...args)])
|
.map(tagName => [tagName, (...args) => h(tagName, ...args)])
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -241,26 +241,26 @@ function tmplSearchResult ({ url, breadcrumbs, heading, title, content }) {
|
|||||||
div(
|
div(
|
||||||
{ class: 'search-result-breadcrumbs d-block text-gray-dark opacity-60 text-small pb-1' },
|
{ class: 'search-result-breadcrumbs d-block text-gray-dark opacity-60 text-small pb-1' },
|
||||||
// Remove redundant title from the end of breadcrumbs
|
// Remove redundant title from the end of breadcrumbs
|
||||||
emify((breadcrumbs || '').replace(` / ${title}`, ''))
|
markify((breadcrumbs || '').replace(` / ${title}`, ''))
|
||||||
),
|
),
|
||||||
div(
|
div(
|
||||||
{ class: 'search-result-title d-block h4-mktg text-gray-dark' },
|
{ class: 'search-result-title d-block h4-mktg text-gray-dark' },
|
||||||
// Display page title and heading (if present exists)
|
// Display page title and heading (if present exists)
|
||||||
emify(heading ? `${title}: ${heading}` : title)
|
markify(heading ? `${title}: ${heading}` : title)
|
||||||
),
|
),
|
||||||
div(
|
div(
|
||||||
{ class: 'search-result-content d-block text-gray' },
|
{ class: 'search-result-content d-block text-gray' },
|
||||||
// Truncate without breaking inner HTML tags
|
// Truncate without breaking inner HTML tags
|
||||||
emify(truncate(content, maxContentLength))
|
markify(truncate(content, maxContentLength))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow em tags in search responses
|
// Convert em to mark tags in search responses
|
||||||
function emify (text) {
|
function markify (text) {
|
||||||
const { em } = tags
|
const { mark } = tags
|
||||||
return text
|
return text
|
||||||
.split(/<\/?em>/g)
|
.split(/<\/?em>/g)
|
||||||
.map((el, i) => i % 2 ? em(el) : el)
|
.map((el, i) => i % 2 ? mark(el) : el)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user