Update Download endpoint to export four shapes of Markdown files

Restructures PDF download into an Export menu containing the PDF export and 4 Markdown Options
Slightly tweaks tests
Effectively moves the api.mergeBrewText to helpers. I think this makes more sense.
Changes the download extension from txt to 'md`.
The Commonmark, TOML, and JSON exports are the same with the frontmatter in a slightly different shape. These were selected based on lightweight research into Markdown Frontmatter.

If specific formats - such as Obsidian - are different enough in terms of formatting the frontmatter or desired metadata content, this is fairly easy
This commit is contained in:
David Bolack
2026-10-13 12:34:51 -05:00
parent 3179c56263
commit c1315b3512
7 changed files with 89 additions and 37 deletions
+40 -1
View File
@@ -114,6 +114,44 @@ const splitTextStyleAndMetadata = (brew)=>{
if(typeof brew.tags === 'string') brew.tags = brew.tags ? [brew.tags] : [];
};
const transformFrontmatter = (brew, format = 'hb')=>{
const markdownFormats = {
hb : '```metadata',
cm : '---',
toml : '+++',
json : ';;;'
};
let text = brew.text;
if((brew.style !== undefined) && (format == 'hb')) {
text = `\`\`\`css\n` +
`${brew.style || ''}\n` +
`\`\`\`\n\n` +
`${text}`;
}
const metadata = _.pick(brew, ['title', 'description', 'tags']);
if(format == 'hb') {
const snippetsArray = brewSnippetsToJSON('brew_snippets', brew.snippets, null, false).snippets;
metadata.snippets = snippetsArray.length > 0 ? snippetsArray : undefined;
metadata.bleedSize = { top: brew?.bleedSize?.top, bottom: brew?.bleedSize?.bottom, inner: brew?.bleedSize?.inner, outer: brew?.bleedSize?.outer };
metadata.safetySpace = { top: brew?.safetySpace?.top, bottom: brew?.safetySpace?.bottom, outer: brew?.safetySpace?.outer, inner: brew?.safetySpace?.inner };
metadata.trimSize = { width: brew?.trimSize?.width, height: brew?.trimSize?.height };
metadata.columns = brew?.columns;
metadata.columnGutter = brew?.columnGutter;
metadata.license = brew?.license;
metadata.legalAuthors = brew?.legalAuthors;
metadata.renderer = brew.renderer;
metadata.theme = brew.theme;
}
text = `${markdownFormats[format]}\n` +
`${format != 'json' ? yaml.dump(metadata) : JSON.stringify(metadata)}\n` +
`${markdownFormats[format].slice(0, 3)}\n\n` +
`${text}`;
return text;
};
const printCurrentBrew = async ()=>{
if(window.typeof !== 'undefined') {
// fire a custom event for the print cycle
@@ -230,5 +268,6 @@ export {
fetchThemeBundle,
brewSnippetsToJSON,
debugTextMismatch,
yamlSnippetsToText
yamlSnippetsToText,
transformFrontmatter
};