CLI tool to sync your Markdown to Leaflet
leafletpub atproto cli markdown

Ability to change theme of the code block

Changed files
+28 -6
src
+9
src/commands/config-cmd.ts
··· 77 if (config.frontmatter.uploadDateKey) 78 printConfigLine("Upload Date Key", wrap(config.frontmatter.uploadDateKey, '"'), 2); 79 } 80 if (config.prependDoc) { 81 printConfigLine( 82 "Prepend doc",
··· 77 if (config.frontmatter.uploadDateKey) 78 printConfigLine("Upload Date Key", wrap(config.frontmatter.uploadDateKey, '"'), 2); 79 } 80 + if (config.codeblockTheme) { 81 + printConfigLine( 82 + "Code Block Theme", 83 + config.codeblockTheme 84 + .split("-") 85 + .map((val) => val.charAt(0).toLocaleUpperCase() + val.slice(1)) 86 + .join(" ") 87 + ); 88 + } 89 if (config.prependDoc) { 90 printConfigLine( 91 "Prepend doc",
+5 -3
src/commands/sync-cmd.ts
··· 154 consola.error(error); 155 } 156 157 for (const file of files) { 158 const path = config.glob.base ? join(config.glob.base, file) : "./" + file; 159 if (config.prependDoc && resolve(config.prependDoc.path) == resolve(path)) continue; ··· 199 }); 200 } 201 202 - prependBlocks = generateBlocks(ast.children, uploadedImages); 203 } 204 205 if (config.appendDoc) { ··· 238 }); 239 } 240 241 - appendBlocks = generateBlocks(ast.children, uploadedImages); 242 } 243 244 const md = (await readFile(config.glob.base ? join(config.glob.base, file) : file)).toString(); ··· 311 const doc = generateDoc( 312 miniDoc.did, 313 publicationUri, 314 - [...prependBlocks, ...generateBlocks(ast.children, uploadedImages), ...appendBlocks], 315 title, 316 description, 317 new Date(uploadDate)
··· 154 consola.error(error); 155 } 156 157 + const codeblockTheme = config.codeblockTheme ? config.codeblockTheme : undefined; 158 + 159 for (const file of files) { 160 const path = config.glob.base ? join(config.glob.base, file) : "./" + file; 161 if (config.prependDoc && resolve(config.prependDoc.path) == resolve(path)) continue; ··· 201 }); 202 } 203 204 + prependBlocks = generateBlocks(ast.children, uploadedImages, codeblockTheme); 205 } 206 207 if (config.appendDoc) { ··· 240 }); 241 } 242 243 + appendBlocks = generateBlocks(ast.children, uploadedImages, codeblockTheme); 244 } 245 246 const md = (await readFile(config.glob.base ? join(config.glob.base, file) : file)).toString(); ··· 313 const doc = generateDoc( 314 miniDoc.did, 315 publicationUri, 316 + [...prependBlocks, ...generateBlocks(ast.children, uploadedImages, codeblockTheme), ...appendBlocks], 317 title, 318 description, 319 new Date(uploadDate)
+10 -1
src/config.ts
··· 7 8 export interface Config { 9 glob: { pattern: string; base?: string }; 10 - frontmatter?: { type: "yaml"; titleKey: string; descriptionKey?: string; uploadDateKey?: string }; 11 publicationUri?: ResourceUri; 12 prependDoc?: { path: string; replacement?: Replacement }; 13 appendDoc?: { path: string; replacement?: Replacement }; 14 } 15 16 export function defineConfig(config: Config) {
··· 7 8 export interface Config { 9 glob: { pattern: string; base?: string }; 10 + frontmatter?: { 11 + type: "yaml"; 12 + titleKey: string; 13 + descriptionKey?: string; 14 + uploadDateKey?: string; 15 + }; 16 publicationUri?: ResourceUri; 17 prependDoc?: { path: string; replacement?: Replacement }; 18 appendDoc?: { path: string; replacement?: Replacement }; 19 + /** 20 + * All available themes can be found at {@link https://shiki.matsu.io/themes} under the ID column 21 + */ 22 + codeblockTheme?: string; 23 } 24 25 export function defineConfig(config: Config) {
+4 -2
src/conversion.ts
··· 10 11 export function generateBlocks( 12 children: RootContent[], 13 - uploadedImages: Map<string, { blob: Blob; width: number; height: number }> 14 ) { 15 return children 16 .flatMap((val): PubLeafletPagesLinearDocument.Block | PubLeafletPagesLinearDocument.Block[] | null => { 17 if (val.type == "heading") { ··· 53 $type: "pub.leaflet.blocks.code", 54 plaintext: val.value, 55 language: val.lang == null ? undefined : val.lang, 56 - syntaxHighlightingTheme: "catppuccin-mocha", 57 }, 58 }; 59 } else if (val.type == "blockquote") {
··· 10 11 export function generateBlocks( 12 children: RootContent[], 13 + uploadedImages: Map<string, { blob: Blob; width: number; height: number }>, 14 + codeblockTheme?: string 15 ) { 16 + codeblockTheme ??= "catppuccin-mocha"; 17 return children 18 .flatMap((val): PubLeafletPagesLinearDocument.Block | PubLeafletPagesLinearDocument.Block[] | null => { 19 if (val.type == "heading") { ··· 55 $type: "pub.leaflet.blocks.code", 56 plaintext: val.value, 57 language: val.lang == null ? undefined : val.lang, 58 + syntaxHighlightingTheme: codeblockTheme, 59 }, 60 }; 61 } else if (val.type == "blockquote") {