Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/BakeModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ export class BakeModal extends Modal {
})
);

new Setting(contentEl)
.setName("Increment heading levels")
.setDesc(
"Increase the heading levels of transcluded markdown files."
)
.addToggle((toggle) =>
toggle.setValue(settings.incrementHeadingLevels).onChange((value) => {
settings.incrementHeadingLevels = value;
plugin.saveSettings();
})
);

new Setting(contentEl).setName('Output file name').then((setting) => {
new Setting(contentEl).then((setting) => {
setting.addButton((btn) =>
Expand Down
5 changes: 3 additions & 2 deletions src/bake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
extractSubpath,
sanitizeBakedContent,
stripFirstBullet,
incrementHeadings,
} from './util';

const lineStartRE = /(?:^|\n) *$/;
Expand Down Expand Up @@ -102,9 +103,9 @@ export async function bake(
}

// Recurse and bake the linked file...
const baked = sanitizeBakedContent(
const baked = incrementHeadings(sanitizeBakedContent(
await bake(app, linkedFile, subpath, newAncestors, settings)
);
), settings.incrementHeadingLevels);
replaceTarget(
listMatch ? applyIndent(stripFirstBullet(baked), listMatch[1]) : baked
);
Expand Down
21 changes: 21 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export interface BakeSettings {
bakeEmbeds: boolean;
bakeInList: boolean;
convertFileLinks: boolean;
incrementHeadingLevels: boolean;
}

const DEFAULT_SETTINGS: BakeSettings = {
bakeLinks: true,
bakeEmbeds: true,
bakeInList: true,
convertFileLinks: true,
incrementHeadingLevels: false,
};

export default class EasyBake extends Plugin {
Expand Down Expand Up @@ -46,5 +48,24 @@ export default class EasyBake extends Plugin {
new BakeModal(this, file).open();
},
});

this.addCommand({
id: 'bake-file:saved-settings',
name: 'Bake current file using saved settings',
checkCallback: (checking) => {
// Current file
const file = this.activeMarkdownFile;
if (checking || !file) return !!file;
// Output file
let outputName = file.basename + '.baked';
let outputFolder = file.parent?.path || '';
if (outputFolder) outputFolder += '/';
// Bake
const inputPath = file.path;
const outputPath = outputFolder + outputName + '.md';
this.api.bakeAndOpen(inputPath, outputPath, this.settings)
},
});

}
}
5 changes: 5 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export function stripFrontmatter(text: string) {
return text.replace(/^---[\s\S]+?\r?\n---(?:\r?\n\s*|$)/, '');
}

export function incrementHeadings(text: string, incrementHeadings: boolean) {
if (!text || !incrementHeadings) return text;
return text.replace(/^(#+)(\s)/gm, (match, hashes, space) => '#'.repeat(hashes.length + 1) + space);
}

export function sanitizeBakedContent(text: string) {
return stripBlockId(stripFrontmatter(text));
}
Expand Down