mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed invalid escaping of HTML in search results
This commit is contained in:
parent
702de82585
commit
829820a239
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -196,7 +196,7 @@
|
||||
"base": base_url,
|
||||
"features": features,
|
||||
"translations": {},
|
||||
"search": "assets/javascripts/workers/search.709b4209.min.js" | url,
|
||||
"search": "assets/javascripts/workers/search.409db549.min.js" | url,
|
||||
"version": config.extra.version or None
|
||||
} -%}
|
||||
{%- set translations = app.translations -%}
|
||||
@ -223,7 +223,7 @@
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script src="{{ 'assets/javascripts/bundle.56838a2c.min.js' | url }}"></script>
|
||||
<script src="{{ 'assets/javascripts/bundle.56a63758.min.js' | url }}"></script>
|
||||
{% for path in config["extra_javascript"] %}
|
||||
<script src="{{ path | url }}"></script>
|
||||
{% endfor %}
|
||||
|
@ -83,7 +83,7 @@ export function mountSearchHiglight(
|
||||
)
|
||||
])
|
||||
.pipe(
|
||||
map(([index, url]) => setupSearchHighlighter(index.config)(
|
||||
map(([index, url]) => setupSearchHighlighter(index.config, true)(
|
||||
url.searchParams.get("h")!
|
||||
)),
|
||||
map(fn => {
|
||||
|
@ -167,7 +167,7 @@ export class Search {
|
||||
|
||||
/* Set up document map and highlighter factory */
|
||||
this.documents = setupSearchDocumentMap(docs)
|
||||
this.highlight = setupSearchHighlighter(config)
|
||||
this.highlight = setupSearchHighlighter(config, false)
|
||||
|
||||
/* Set separator for tokenizer */
|
||||
lunr.tokenizer.separator = new RegExp(config.separator)
|
||||
|
@ -54,11 +54,12 @@ export type SearchHighlightFactoryFn = (query: string) => SearchHighlightFn
|
||||
* Create a search highlighter
|
||||
*
|
||||
* @param config - Search index configuration
|
||||
* @param escape - Whether to escape HTML
|
||||
*
|
||||
* @returns Search highlight factory function
|
||||
*/
|
||||
export function setupSearchHighlighter(
|
||||
config: SearchIndexConfig
|
||||
config: SearchIndexConfig, escape: boolean
|
||||
): SearchHighlightFactoryFn {
|
||||
const separator = new RegExp(config.separator, "img")
|
||||
const highlight = (_: unknown, data: string, term: string) => {
|
||||
@ -79,8 +80,12 @@ export function setupSearchHighlighter(
|
||||
})`, "img")
|
||||
|
||||
/* Highlight string value */
|
||||
return value => escapeHTML(value)
|
||||
.replace(match, highlight)
|
||||
.replace(/<\/mark>(\s+)<mark[^>]*>/img, "$1")
|
||||
return value => (
|
||||
escape
|
||||
? escapeHTML(value)
|
||||
: value
|
||||
)
|
||||
.replace(match, highlight)
|
||||
.replace(/<\/mark>(\s+)<mark[^>]*>/img, "$1")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user