Skip to content

Commit

Permalink
Closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed Aug 19, 2023
1 parent dfd7f5d commit 322c011
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
gh release create "$tag" \
--title="$tag" \
main.js manifest.json
main.js manifest.json styles.css
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "easy-bake",
"name": "Easy Bake",
"version": "1.0.2",
"version": "1.0.3",
"minAppVersion": "0.15.0",
"description": "Easily compile many Obsidian notes down to a single file.",
"author": "mgmeyers",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-sample-plugin",
"version": "1.0.2",
"version": "1.0.3",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
45 changes: 38 additions & 7 deletions src/BakeModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ import {
import EasyBake, { BakeSettings } from './main';
import { extractSubpath, getWordCount } from './util';

const lineStartRE = /(?:^|[\r\n]) *$/;
const lineEndRE = /^ *(?:[\r\n]|$)/;
const lineStartRE = /(?:^|\n) *$/;
const listLineStartRE = /(?:^|\n)([ \t]*)(?:[-*+]|[0-9]+[.)]) +$/;
const lineEndRE = /^ *(?:\r?\n|$)/;

function applyIndent(text: string, indent?: string) {
if (!indent) return text;
return text.trim().replace(/(\r?\n)/g, `$1${indent}`);
}

function stripFirstBullet(text: string) {
return text.replace(/^[ \t]*(?:[-*+]|[0-9]+[.)]) +/, '');
}

async function bake(
app: App,
Expand All @@ -31,7 +41,9 @@ async function bake(

if (subpath) {
const resolvedSubpath = resolveSubpath(cache, subpath);
text = extractSubpath(text, resolvedSubpath, cache);
if (resolvedSubpath) {
text = extractSubpath(text, resolvedSubpath, cache);
}
}

const links = settings.bakeLinks ? cache.links || [] : [];
Expand Down Expand Up @@ -59,7 +71,11 @@ async function bake(
const before = text.substring(0, start);
const after = text.substring(end);

const isInline = !lineStartRE.test(before) || !lineEndRE.test(after);
const listMatch = settings.bakeInList
? before.match(listLineStartRE)
: null;
const isInline =
!(listMatch || lineStartRE.test(before)) || !lineEndRE.test(after);
const notMarkdown = linkedFile.extension !== 'md';

const replaceTarget = (replacement: string) => {
Expand All @@ -84,7 +100,10 @@ async function bake(
continue;
}

replaceTarget(await bake(app, linkedFile, subpath, newAncestors, settings));
const baked = await bake(app, linkedFile, subpath, newAncestors, settings);
replaceTarget(
listMatch ? applyIndent(stripFirstBullet(baked), listMatch[1]) : baked
);
}

return text;
Expand Down Expand Up @@ -116,7 +135,7 @@ export class BakeModal extends Modal {
const { settings } = plugin;

this.titleEl.setText('Bake file');
this.modalEl.addClass('mod-narrow');
this.modalEl.addClass('mod-narrow', 'easy-bake-modal');
this.contentEl
.createEl('p', { text: 'Input file: ' })
.createEl('strong', { text: file.path });
Expand Down Expand Up @@ -145,6 +164,18 @@ export class BakeModal extends Modal {
})
);

new Setting(contentEl)
.setName('Bake links and embeds in lists')
.setDesc(
'Include the content of [[any link]] or ![[embedded markdown file]] when it takes up an entire list bullet.'
)
.addToggle((toggle) =>
toggle.setValue(settings.bakeInList).onChange((value) => {
settings.bakeInList = value;
plugin.saveSettings();
})
);

new Setting(contentEl)
.setName('Bake file links')
.setDesc(
Expand All @@ -168,7 +199,7 @@ export class BakeModal extends Modal {
);
});

contentEl.createDiv('modal-button-container', (el) => {
this.modalEl.createDiv('modal-button-container', (el) => {
let outputName = file.basename + '.baked';
let outputFolder = file.parent?.path || '';

Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { BakeModal } from './BakeModal';
export interface BakeSettings {
bakeLinks: boolean;
bakeEmbeds: boolean;
bakeInList: boolean;
convertFileLinks: boolean;
}

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

Expand Down
10 changes: 10 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body:not(.is-mobile) .easy-bake-modal .modal {
overflow: hidden;
}

body:not(.is-mobile) .easy-bake-modal .modal-content {
overflow: auto;
height: 100%;
flex-grow: 0;
flex-shrink: 1;
}
4 changes: 2 additions & 2 deletions version-bump.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const targetVersion = process.env.npm_package_version;
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
const { minAppVersion } = manifest;
manifest.version = targetVersion;
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t") + '\n');

// update versions.json with target version and minAppVersion from manifest.json
let versions = JSON.parse(readFileSync("versions.json", "utf8"));
versions[targetVersion] = minAppVersion;
writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));
writeFileSync("versions.json", JSON.stringify(versions, null, "\t") + '\n');
5 changes: 3 additions & 2 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"1.0.0": "0.15.0",
"1.0.1": "0.15.0",
"1.0.2": "0.15.0"
}
"1.0.2": "0.15.0",
"1.0.3": "0.15.0"
}

0 comments on commit 322c011

Please sign in to comment.