@@ -5,6 +5,7 @@ import rehypeRemark from "rehype-remark";
55import remarkStringify from "remark-stringify" ;
66import remarkGfm from "remark-gfm" ;
77import { visitParents } from "unist-util-visit-parents" ;
8+ import type { Node } from "unist" ;
89import { basename , dirname , join , relative } from "node:path" ;
910import { fileURLToPath } from "node:url" ;
1011import { mkdir , readdir , readFile , writeFile } from "node:fs/promises" ;
@@ -49,19 +50,19 @@ async function collectFiles(currentDir: string, baseDir: string): Promise<FileMa
4950 * Custom remark plugin to clean up code blocks by removing excessive blank lines.
5051 */
5152function remarkCleanCodeBlocks ( ) {
52- return ( tree : any ) => {
53- function visit ( node : any ) {
54- if ( node . type === 'code' && node . value ) {
53+ return ( tree : Node ) => {
54+ function visit ( node : Node ) {
55+ if ( node . type === 'code' && 'value' in node && typeof node . value === 'string' ) {
5556 // Remove lines that only contain whitespace
5657 node . value = node . value
5758 . split ( '\n' )
5859 . filter ( ( line : string ) => line . trim ( ) . length > 0 )
5960 . join ( '\n' ) . trim ( ) ;
6061 }
6162
62- if ( node . children ) {
63+ if ( 'children' in node && Array . isArray ( node . children ) ) {
6364 for ( const child of node . children ) {
64- visit ( child ) ;
65+ visit ( child as Node ) ;
6566 }
6667 }
6768 }
@@ -75,12 +76,12 @@ function remarkCleanCodeBlocks() {
7576 * This is a special case, and the easiest way to handle it is to just manually decode it.
7677 */
7778function remarkDecodeTableEntities ( ) {
78- return ( tree : any ) => {
79- visitParents ( tree , 'text' , ( node : any , ancestors : any [ ] ) => {
79+ return ( tree : Node ) => {
80+ visitParents ( tree , 'text' , ( node : Node , ancestors : Node [ ] ) => {
8081 // Check if any ancestor is a tableCell
8182 const isInTableCell = ancestors . some ( ( ancestor ) => ancestor . type === 'tableCell' ) ;
8283
83- if ( isInTableCell ) {
84+ if ( isInTableCell && 'value' in node && typeof node . value === 'string' ) {
8485 node . value = node . value
8586 . replace ( / \\ & # 1 2 3 ; / g, "{" )
8687 . replace ( / \\ & # 1 2 5 ; / g, "}" )
0 commit comments