@@ -9,74 +9,15 @@ import glob from "glob";
99import path from "path" ;
1010import fs from "fs" ;
1111import { URL } from 'url' ;
12- import remarkRehype from "remark-rehype" ;
13- import rehypeSlug from "rehype-slug" ;
14- import rehypeStringify from "rehype-stringify" ;
1512
1613import { defaultProcessor } from "./markdown.js" ;
1714
18- const remarkCodeblocks = options => ( tree , file ) => {
19- const { children } = tree ;
20- const codeblocks = { } ;
21-
22- const formatter = value => {
23- // Strip newlines and weird spacing
24- return value
25- . replace ( / \n / g, " " )
26- . replace ( / \s + / g, " " )
27- . replace ( / \( \s + / g, "(" )
28- . replace ( / \s + \) / g, ")" ) ;
29- } ;
30-
31- children . forEach ( child => {
32- if ( child . type === "code" && child . value ) {
33- const { meta, lang } = child ;
34- if ( meta === "sig" && lang === "re" ) {
35- if ( codeblocks [ lang ] == null ) {
36- codeblocks [ lang ] = [ ] ;
37- }
38- codeblocks [ lang ] . push ( formatter ( child . value ) ) ;
39- }
40- }
41- } ) ;
42-
43- file . data = Object . assign ( { } , file . data , { codeblocks } ) ;
44- } ;
45-
46- const rehypeHeaders = options => ( tree , file ) => {
47- const headers = [ ] ;
48- let mainHeader ;
49- tree . children . forEach ( child => {
50- if ( child . type === "heading" && child . depth === 1 ) {
51- if ( child . children . length > 0 ) {
52- mainHeader = child . children . map ( element => element . value ) . join ( "" ) ;
53- }
54- }
55- if ( child . type === "heading" && child . depth === 2 ) {
56- if ( child . children . length > 0 ) {
57- const id = child . data . id || "" ;
58- const name = child . children . map ( element => element . value ) . join ( "" ) ;
59- headers . push ( { name, href : id } ) ;
60- }
61- }
62- } ) ;
63-
64- file . data = Object . assign ( { } , file . data , { headers, mainHeader } ) ;
65- } ;
66-
67- const processor = defaultProcessor
68- . use ( remarkCodeblocks )
69- . use ( remarkRehype )
70- . use ( rehypeSlug )
71- . use ( rehypeHeaders )
72- . use ( rehypeStringify )
73-
7415const pathname = new URL ( '.' , import . meta. url ) . pathname ;
7516const __dirname = process . platform !== 'win32' ? pathname : pathname . substring ( 1 )
7617
7718const processFile = filepath => {
7819 const content = fs . readFileSync ( filepath , "utf8" ) ;
79- const result = processor . processSync ( content ) ;
20+ const result = defaultProcessor . processSync ( content ) ;
8021
8122 const pagesPath = path . resolve ( "./pages" ) ;
8223 const relFilepath = path . relative ( pagesPath , filepath ) ;
0 commit comments