this repo has no description
at main 1.1 kB view raw
1import { format } from 'prettier'; 2import { unified } from 'unified'; 3import remarkParse from 'remark-parse'; 4import remarkStringify from 'remark-stringify'; 5import remarkGfm from 'remark-gfm'; 6 7import { remarkTitle } from './unified'; 8 9async function reformat(content: string, title: string): Promise<string> { 10 // NOTE: We reformat with remark again to get rid of prettier's 11 // table formatting mostly. This doesn't work well as LLM input 12 const md = await unified() 13 .use(remarkParse, { fragment: true }) 14 .use(remarkGfm, { 15 tablePipeAlign: false, 16 tableCellPadding: false, 17 }) 18 .use(remarkTitle, { title }) 19 .use(remarkStringify, { 20 bullet: '-', 21 incrementListMarker: false, 22 ruleSpaces: false, 23 tightDefinitions: true, 24 }) 25 .process(content); 26 return md.toString(); 27} 28 29export async function formatMarkdown(title: string, input: string) { 30 return reformat( 31 await format(input, { 32 semi: false, 33 singleQuote: false, 34 trailingComma: 'es5', 35 proseWrap: 'never', 36 parser: 'markdown', 37 }), 38 title 39 ); 40}