Skip to content
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

Fix escaping special html entites in search output #2461

Merged
merged 25 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b858db5
- Changed LunrJs to MinisearchJs for client-side search
Hetarth02 Jul 5, 2023
34303e0
Merge branch 'master' of https://github.com/Hetarth02/Documenter.jl i…
Hetarth02 Jul 16, 2023
1fb8e07
- Updated the duplication issue
Hetarth02 Jul 16, 2023
724bd89
- Corrected typo
Hetarth02 Jul 16, 2023
bb1dbc4
Merge branch 'master' of https://github.com/Hetarth02/Documenter.jl
Hetarth02 Aug 24, 2023
defe107
New Search Modal UI (#2202)
Hetarth02 Aug 24, 2023
f32d6de
Merge branch 'master' of https://github.com/Hetarth02/Documenter.jl
Hetarth02 Aug 24, 2023
984ef8c
Merge branch 'master' of https://github.com/Hetarth02/Documenter.jl
Hetarth02 Sep 26, 2023
149bdd0
Merge branch 'master' of https://github.com/Hetarth02/Documenter.jl
Hetarth02 Oct 15, 2023
24d8a5f
Merge branch 'JuliaDocs:master' into master
Hetarth02 Nov 4, 2023
60ca700
Merge branch 'JuliaDocs:master' into master
Hetarth02 Nov 10, 2023
be00b02
Merge branch 'JuliaDocs:master' into master
Hetarth02 Nov 13, 2023
b2feabd
Merge branch 'JuliaDocs:master' into master
Hetarth02 Nov 13, 2023
85828de
Merge branch 'JuliaDocs:master' into master
Hetarth02 Dec 10, 2023
e250ebb
Merge branch 'master' of https://github.com/Hetarth02/Documenter.jl
Hetarth02 Jan 23, 2024
0bd65e2
Merge branch 'master' of https://github.com/Hetarth02/Documenter.jl
Hetarth02 Feb 20, 2024
31b6ec8
- Fix escaping special html entites in search output
Hetarth02 Feb 20, 2024
92c0ce0
- Updated CHANGELOG.md
Hetarth02 Feb 20, 2024
ad949d1
Merge branch 'JuliaDocs:master' into master
Hetarth02 Feb 24, 2024
42d195a
Merge branch 'master' of https://github.com/Hetarth02/Documenter.jl i…
Hetarth02 Feb 24, 2024
cbc9c7f
- Removed lodash dependency
Hetarth02 Feb 24, 2024
0bb6e3d
- Updated CHANGELOG.md
Hetarth02 Feb 24, 2024
8f22b35
fix title too
mortenpi Feb 27, 2024
05b8563
Merge branch 'master' into Issue-2441
mortenpi Feb 27, 2024
a076be0
Update CHANGELOG.md
mortenpi Feb 27, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* Fix escaping special html entities in search output. ([#2441], [#2461])
* Fix the search filter toggle button styling in the HTML output. ([#2406], [#2408])
* The theme selector for the HTML output now correctly picks `Automatic (OS)` if the user hasn't explicitly set the theme. ([#2414], [#2438])
* Fix the search window sometimes not appearing in the HTML output. ([#2430], [#2458])
Expand Down Expand Up @@ -1800,9 +1801,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2415]: https://github.com/JuliaDocs/Documenter.jl/issues/2415
[#2430]: https://github.com/JuliaDocs/Documenter.jl/issues/2430
[#2438]: https://github.com/JuliaDocs/Documenter.jl/issues/2438
[#2441]: https://github.com/JuliaDocs/Documenter.jl/issues/2441
[#2458]: https://github.com/JuliaDocs/Documenter.jl/issues/2458
[#2459]: https://github.com/JuliaDocs/Documenter.jl/issues/2459
[#2460]: https://github.com/JuliaDocs/Documenter.jl/issues/2460
[#2461]: https://github.com/JuliaDocs/Documenter.jl/issues/2461
[JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953
[JuliaLang/julia#38054]: https://github.com/JuliaLang/julia/issues/38054
[JuliaLang/julia#39841]: https://github.com/JuliaLang/julia/issues/39841
Expand Down
35 changes: 33 additions & 2 deletions assets/html/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,35 @@ function worker_function(documenterSearchIndex, documenterBaseURL, filters) {

index.addAll(data);

/**
* Used to map characters to HTML entities.
* Refer: https://github.com/lodash/lodash/blob/main/src/escape.ts
*/
const htmlEscapes = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;",
};

/**
* Used to match HTML entities and HTML characters.
* Refer: https://github.com/lodash/lodash/blob/main/src/escape.ts
*/
const reUnescapedHtml = /[&<>"']/g;
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);

/**
* Escape function from lodash
* Refer: https://github.com/lodash/lodash/blob/main/src/escape.ts
*/
function escape(string) {
return string && reHasUnescapedHtml.test(string)
? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr])
: string || "";
}

/**
* Make the result component given a minisearch result data object and the value
* of the search input as queryString. To view the result object structure, refer:
Expand Down Expand Up @@ -246,10 +275,12 @@ function worker_function(documenterSearchIndex, documenterBaseURL, filters) {
)
: ""; // cut-off text before and after from the match

text = text.length ? escape(text) : "";

let display_result = text.length
? "..." +
text.replace(
new RegExp(`${querystring}`, "i"), // For first occurrence
new RegExp(`${escape(querystring)}`, "i"), // For first occurrence
'<span class="search-result-highlight py-1">$&</span>'
) +
"..."
Expand All @@ -268,7 +299,7 @@ function worker_function(documenterSearchIndex, documenterBaseURL, filters) {
<div class="w-100 is-flex is-flex-wrap-wrap is-justify-content-space-between is-align-items-flex-start">
<div class="search-result-title has-text-weight-bold ${
in_code ? "search-result-code-title" : ""
}">${result.title}</div>
}">${escape(result.title)}</div>
<div class="property-search-result-badge">${result.category}</div>
</div>
<p>
Expand Down
Loading