@@ -26,10 +26,20 @@ import { set_link_attributes } from "./links";
2626import { highight_code_block } from "./code" ;
2727import { parse_frontmatter } from "./frontmatter" ;
2828import { split_view } from "./split_view" ;
29- import { custom_vfile , section } from "./types" ;
29+ import { custom_vfile } from "./types" ;
30+ import { section } from "../types" ;
3031
3132import u from "unist-builder" ;
3233
34+ interface Format {
35+ file : string ;
36+ markdown : string ;
37+ project : string ;
38+ docs_type : docs_type ;
39+ dir : string ;
40+ seen_slugs ?: Map < string , number > ;
41+ }
42+
3343// MDAST == Markdown AST
3444// HAST == HTML AST
3545
@@ -65,38 +75,40 @@ const { process } = unified()
6575 // HAST -> string
6676 . use ( stringify , { allowDangerousCharacters : true , allowDangerousHtml : true } ) ;
6777
68- export function format ( ) {
69- return async function (
70- file : string ,
71- markdown : string ,
72- project : string ,
73- docs_type : docs_type ,
74- dir : string ,
75- seen_slugs : Map < string , number > = new Map ( )
76- ) {
77- const sections : section [ ] = [ ] ;
78- const section_title = file . toLowerCase ( ) . endsWith ( "readme.md" )
79- ? make_slug ( project , seen_slugs )
80- : false ;
81- const vfile = vFile < custom_vfile > ( {
82- contents : markdown ,
83- data : {
84- seen_slugs,
85- sections,
86- section_stack : [ sections ] ,
87- section_title,
88- dir,
89- file_type : file . toLowerCase ( ) . endsWith ( "readme.md" )
90- ? "readme"
91- : "other" ,
92- docs_type,
93- prev_level : 3 ,
94- slugs : [ ] ,
95- } ,
96- } ) ;
78+ export async function format ( {
79+ file,
80+ markdown,
81+ project,
82+ docs_type,
83+ dir,
84+ seen_slugs = new Map ( ) ,
85+ } : Format ) : Promise < custom_vfile > {
86+ const sections : section [ ] = [ ] ;
87+ const section_title = file . toLowerCase ( ) . endsWith ( "readme.md" )
88+ ? project
89+ : false ;
90+
91+ const section_slug = file . toLowerCase ( ) . endsWith ( "readme.md" )
92+ ? make_slug ( project , seen_slugs )
93+ : false ;
94+
95+ const vfile = vFile < custom_vfile > ( {
96+ contents : markdown ,
97+ data : {
98+ seen_slugs,
99+ sections,
100+ section_stack : [ sections ] ,
101+ section_title,
102+ section_slug,
103+ dir,
104+ file_type : file . toLowerCase ( ) . endsWith ( "readme.md" ) ? "readme" : "other" ,
105+ docs_type,
106+ prev_level : 3 ,
107+ slugs : [ ] ,
108+ } ,
109+ } ) ;
97110
98- const docs = await process ( vfile ) ;
111+ const docs = ( await process ( vfile ) ) as custom_vfile ;
99112
100- return docs ;
101- } ;
113+ return docs ;
102114}
0 commit comments