@@ -36,7 +36,10 @@ import { Data, Literal, Node, Parent } from "unist";
3636
3737export function markdowntoHTML (
3838 src : string ,
39- options : { allowDangerousHtml : boolean } = { allowDangerousHtml : true }
39+ options : { allowDangerousHtml : boolean ; encodeHtmlEntities ?: boolean } = {
40+ allowDangerousHtml : true ,
41+ encodeHtmlEntities : true
42+ }
4043) {
4144 const result = remark ( )
4245 . use ( remarkGfm , { singleTilde : false } )
@@ -46,7 +49,7 @@ export function markdowntoHTML(
4649 . use ( removeComments )
4750 . use ( convertFileEmbeds )
4851 . use ( remarkRehype , { allowDangerousHtml : options . allowDangerousHtml } )
49- . use ( escapeCode )
52+ . use ( escapeCode , { encodeHtmlEntities : options . encodeHtmlEntities } )
5053 . use ( fixChecklistClasses )
5154 . use ( liftLanguageToPreFromCode )
5255 . use ( collapseMultilineParagraphs )
@@ -185,31 +188,32 @@ const remarkHighlight: () => Transformer = () => (tree) => {
185188 const children : Node < Data > [ ] = values . map ( ( str , i ) =>
186189 i % 2 === 0
187190 ? {
188- type : "text" ,
189- value : str
190- }
191+ type : "text" ,
192+ value : str
193+ }
191194 : {
192- type : "highlight" ,
193- data : {
194- hName : "span" ,
195- hProperties : {
196- style : `background-color: rgb(255, 255, 0);`
197- }
198- } ,
199- children : [
200- {
201- type : "text" ,
202- value : str
203- }
204- ]
205- }
195+ type : "highlight" ,
196+ data : {
197+ hName : "span" ,
198+ hProperties : {
199+ style : `background-color: rgb(255, 255, 0);`
200+ }
201+ } ,
202+ children : [
203+ {
204+ type : "text" ,
205+ value : str
206+ }
207+ ]
208+ }
206209 ) ;
207210 ( parent as Parent ) . children . splice ( index ! , 1 , ...children ) ;
208211 return [ "skip" , index ] ;
209212 } ) ;
210213} ;
211214
212- const escapeCode : Plugin < [ ] , HastRoot , HastRoot > = function ( ) {
215+ const escapeCode : Plugin < [ { encodeHtmlEntities ?: boolean } ?] , HastRoot , HastRoot > = function ( options = { } ) {
216+ const { encodeHtmlEntities = true } = options ;
213217 return ( tree : HastRoot ) => {
214218 visit ( tree , "element" , ( node ) => {
215219 if ( ! isElement ( node , "code" ) ) return ;
@@ -220,7 +224,7 @@ const escapeCode: Plugin<[], HastRoot, HastRoot> = function () {
220224 lines . forEach ( ( line , i ) => {
221225 children . push ( {
222226 type : "text" ,
223- value : encodeNonAsciiHTML ( line )
227+ value : encodeHtmlEntities ? encodeNonAsciiHTML ( line ) : line
224228 } ) ;
225229 if ( i !== lines . length - 1 )
226230 children . push ( {
0 commit comments