1
0
mirror of synced 2025-12-22 19:34:15 -05:00

Convert em to mark in search results (#17391)

This commit is contained in:
Kevin Heis
2021-01-20 13:33:31 -08:00
committed by GitHub
parent aee3e7aced
commit cdb1e4a849
2 changed files with 8 additions and 8 deletions

View File

@@ -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)])
) )

View File

@@ -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)
} }