@@ -201,9 +201,25 @@ export interface RenderedContents {
201201 fullContents : string | undefined ;
202202}
203203
204+ export const kInlineCodeStyle = "inline-code-style" ;
205+ export const kUrlsToAbsolute = "urls-to-absolute" ;
206+
207+ export interface RenderedContentOptions {
208+ remove ?: {
209+ anchors ?: boolean ;
210+ links ?: boolean ;
211+ images ?: boolean ;
212+ } ;
213+ transform ?: {
214+ [ kInlineCodeStyle ] ?: boolean ;
215+ math ?: boolean ;
216+ [ kUrlsToAbsolute ] ?: boolean ;
217+ } ;
218+ }
219+
204220export const renderedContentReader = (
205221 project : ProjectContext ,
206- forFeed : boolean ,
222+ options : RenderedContentOptions ,
207223 siteUrl ?: string ,
208224) => {
209225 const renderedContent : Record < string , RenderedContents > = { } ;
@@ -212,7 +228,7 @@ export const renderedContentReader = (
212228 renderedContent [ filePath ] = readRenderedContents (
213229 filePath ,
214230 project ,
215- forFeed ,
231+ options ,
216232 siteUrl ,
217233 ) ;
218234 }
@@ -238,7 +254,7 @@ export const absoluteUrl = (siteUrl: string, url: string) => {
238254export function readRenderedContents (
239255 filePath : string ,
240256 project : ProjectContext ,
241- forFeed : boolean ,
257+ options : RenderedContentOptions ,
242258 siteUrl ?: string ,
243259) : RenderedContents {
244260 const htmlInput = Deno . readTextFileSync ( filePath ) ;
@@ -265,7 +281,7 @@ export function readRenderedContents(
265281 }
266282
267283 // Convert any images to have absolute paths
268- if ( forFeed && siteUrl ) {
284+ if ( options . transform ?. [ kUrlsToAbsolute ] && siteUrl ) {
269285 const imgNodes = doc . querySelectorAll ( "img" ) ;
270286 if ( imgNodes ) {
271287 for ( const imgNode of imgNodes ) {
@@ -305,16 +321,31 @@ export function readRenderedContents(
305321 } ) ;
306322 } ) ;
307323
308- if ( forFeed ) {
309- // String unacceptable links
324+ // Strip unacceptable tags
325+ const stripTags = [ ] ;
326+ if ( options . remove ?. images ) {
327+ stripTags . push ( "img" ) ;
328+ }
329+ stripTags . forEach ( ( tag ) => {
330+ const nodes = doc . querySelectorAll ( `${ tag } ` ) ;
331+ nodes ?. forEach ( ( node ) => {
332+ const el = node as Element ;
333+ el . remove ( ) ;
334+ } ) ;
335+ } ) ;
336+
337+ if ( options . remove ?. anchors ) {
338+ // Strip unacceptable links
310339 const relativeLinkSel = 'a[href^="#"]' ;
311340 const linkNodes = doc . querySelectorAll ( relativeLinkSel ) ;
312341 linkNodes . forEach ( ( linkNode ) => {
313342 const nodesToMove = linkNode . childNodes ;
314343 linkNode . after ( ...nodesToMove ) ;
315344 linkNode . remove ( ) ;
316345 } ) ;
346+ }
317347
348+ if ( options . transform ?. [ kInlineCodeStyle ] ) {
318349 // Process code to apply styles for syntax highlighting
319350 const highlightingMap = defaultSyntaxHighlightingClassMap ( ) ;
320351 const spanNodes = doc . querySelectorAll ( "code span" ) ;
@@ -337,7 +368,9 @@ export function readRenderedContents(
337368 const codeBlockEl = codeBlockNode as Element ;
338369 codeBlockEl . setAttribute ( "style" , codeStyle ) ;
339370 }
371+ }
340372
373+ if ( options . transform ?. math ) {
341374 // Process math using webtex
342375 const trimMath = ( str : string ) => {
343376 // Text of math is prefixed by the below
@@ -359,7 +392,9 @@ export function readRenderedContents(
359392 ) ;
360393 mathNode . parentElement ?. replaceChild ( imgEl , mathNode ) ;
361394 }
362- } else {
395+ }
396+
397+ if ( options . remove ?. links ) {
363398 // String all links
364399 const relativeLinkSel = "a" ;
365400 const linkNodes = doc . querySelectorAll ( relativeLinkSel ) ;
0 commit comments