File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -37,11 +37,15 @@ export function getDecodedAttribute(element: Element, attrib: string) {
3737 }
3838}
3939
40+ const kTagBrackets : Record < string , string > = {
41+ "<" : "<" ,
42+ ">" : ">" ,
43+ } ;
44+
4045const kAttrReplacements : Record < string , string > = {
4146 '"' : """ ,
4247 "'" : "'" ,
43- "<" : "<" ,
44- ">" : ">" ,
48+ ...kTagBrackets ,
4549 "&" : "&" ,
4650} ;
4751export function encodeAttributeValue ( value : unknown ) {
@@ -56,6 +60,13 @@ export function encodeAttributeValue(value: unknown) {
5660 }
5761}
5862
63+ export function encodeHtml ( value : string ) {
64+ Object . keys ( kTagBrackets ) . forEach ( ( key ) => {
65+ value = value . replaceAll ( key , kTagBrackets [ key ] ) ;
66+ } ) ;
67+ return value ;
68+ }
69+
5970export function findParent (
6071 el : Element ,
6172 match : ( el : Element ) => boolean ,
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ import { kLanguageDefaults } from "../../../config/constants.ts";
5151import { pathWithForwardSlashes } from "../../../core/path.ts" ;
5252import { isHtmlFileOutput } from "../../../config/format.ts" ;
5353import { projectIsBook } from "../../project-context.ts" ;
54+ import { encodeHtml } from "../../../core/html.ts" ;
5455
5556// The main search key
5657export const kSearch = "search" ;
@@ -290,7 +291,7 @@ export async function updateSearchIndex(
290291 href : href ,
291292 title,
292293 section : "" ,
293- text : pageText . join ( "\n" ) ,
294+ text : encodeHtml ( pageText . join ( "\n" ) ) ,
294295 } ) ;
295296 }
296297
@@ -302,14 +303,15 @@ export async function updateSearchIndex(
302303 const hrefWithAnchor = `${ href } #${ section . id } ` ;
303304 const sectionText = section . textContent . trim ( ) ;
304305 h2 . remove ( ) ;
306+
305307 if ( sectionText ) {
306308 // Don't index empty sections
307309 updateDoc ( {
308310 objectID : hrefWithAnchor ,
309311 href : hrefWithAnchor ,
310312 title,
311313 section : sectionTitle ,
312- text : sectionText ,
314+ text : encodeHtml ( sectionText ) ,
313315 } ) ;
314316 }
315317 }
@@ -325,7 +327,7 @@ export async function updateSearchIndex(
325327 href,
326328 title,
327329 section : "" ,
328- text : mainText ,
330+ text : encodeHtml ( mainText ) ,
329331 } ) ;
330332 }
331333 }
You can’t perform that action at this time.
0 commit comments