Skip to content

Commit

Permalink
Bug fix: render buttons in Live Preview mode when Obsidian starts (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lx authored Sep 28, 2022
1 parent 59bfbf4 commit a0fd6d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ Then insert that button inline:
Note: swap count is reset if you close the note.

## Releases

### Next version (not released yet)

- Bugfix: buttons now render in Live Preview mode when Obsidian starts ([Lx])

[Lx]: https://github.com/Lx


### 0.4.4
- Bugfix: blue and purple colors should now work
- Bugfix: reduced the height of the Button Maker for smaller displays
Expand Down
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,21 @@ export default class ButtonsPlugin extends Plugin {
callback: () => new InlineButtonModal(this.app).open(),
});

this.registerMarkdownCodeBlockProcessor("button", async (source, el) => {
// create an object out of the arguments
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView) {
addButtonToStore(this.app, activeView.file);
this.registerMarkdownCodeBlockProcessor(
"button",
async (source, el, ctx) => {
// create an object out of the arguments
const file = this.app.vault
.getFiles()
.find((f) => f.path === ctx.sourcePath);
addButtonToStore(this.app, file);
let args = createArgumentObject(source);
const storeArgs = await getButtonFromStore(this.app, args);
args = storeArgs ? storeArgs.args : args;
const id = storeArgs && storeArgs.id;
createButton({ app: this.app, el, args, inline: false, id });
}
});
);

this.registerMarkdownPostProcessor(async (el, ctx) => {
// Search for <code> blocks inside this element; for each one, look for things of the form `
Expand Down

0 comments on commit a0fd6d2

Please sign in to comment.