@@ -9,74 +9,15 @@ import glob from "glob";
9
9
import path from "path" ;
10
10
import fs from "fs" ;
11
11
import { URL } from 'url' ;
12
- import remarkRehype from "remark-rehype" ;
13
- import rehypeSlug from "rehype-slug" ;
14
- import rehypeStringify from "rehype-stringify" ;
15
12
16
13
import { defaultProcessor } from "./markdown.js" ;
17
14
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
-
74
15
const pathname = new URL ( '.' , import . meta. url ) . pathname ;
75
16
const __dirname = process . platform !== 'win32' ? pathname : pathname . substring ( 1 )
76
17
77
18
const processFile = filepath => {
78
19
const content = fs . readFileSync ( filepath , "utf8" ) ;
79
- const result = processor . processSync ( content ) ;
20
+ const result = defaultProcessor . processSync ( content ) ;
80
21
81
22
const pagesPath = path . resolve ( "./pages" ) ;
82
23
const relFilepath = path . relative ( pagesPath , filepath ) ;
0 commit comments