11import { MemoedDangerousHTMLStyle } from "@follow/components/common/MemoedDangerousHTMLStyle.jsx"
22import { Checkbox } from "@follow/components/ui/checkbox/index.jsx"
3+ import type { SpotlightRule } from "@follow/shared/spotlight"
34import { parseHtml as parseHtmlGeneral } from "@follow/utils/html"
45import type { Components } from "hast-util-to-jsx-runtime"
56import { createElement } from "react"
@@ -9,8 +10,9 @@ import { createHeadingRenderer, MarkdownLink, MarkdownP } from "./components"
910import { MarkdownImage } from "./components/image"
1011import { Math } from "./components/math"
1112import { ShikiHighLighter } from "./components/shiki"
13+ import { applySpotlightToHtmlRendererTree } from "./spotlight"
1214
13- const Style : Components [ "style" ] = ( { node, ...props } ) => {
15+ const renderStyleTag : Components [ "style" ] = ( { node, ...props } ) => {
1416 if ( typeof props . children === "string" ) {
1517 return createElement ( MemoedDangerousHTMLStyle , null , props . children )
1618 }
@@ -22,10 +24,16 @@ export const parseHtml = (
2224 options ?: Partial < {
2325 renderInlineStyle : boolean
2426 noMedia ?: boolean
27+ spotlightRules ?: SpotlightRule [ ]
2528 } > ,
2629) => {
30+ const spotlightRules = options ?. spotlightRules ?? [ ]
31+
2732 return parseHtmlGeneral ( content , {
2833 ...options ,
34+ hastTransform : ( tree ) => {
35+ applySpotlightToHtmlRendererTree ( tree , spotlightRules )
36+ } ,
2937 components : {
3038 a : ( { node, ...props } ) => {
3139 // Ignore link wrapper when child is an image to ensure image preview
@@ -62,7 +70,7 @@ export const parseHtml = (
6270 h6 : ( props ) => {
6371 return createHeadingRenderer ( 6 ) ( props )
6472 } ,
65- style : Style ,
73+ style : renderStyleTag ,
6674 img : ( { node, ...props } ) => {
6775 return createElement ( MarkdownImage , props as any )
6876 } ,
0 commit comments