Skip to content

Commit

Permalink
Fixed several rendering bugs + Bumped version
Browse files Browse the repository at this point in the history
  • Loading branch information
debanjandhar12 committed Aug 18, 2021
1 parent 7dbb959 commit 4610015
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ This plugin allow you to make flashcards in [Obsidian](https://obsidian.md/) and

This is similar to [Obsidian_to_Anki](https://github.com/Pseudonium/Obsidian_to_Anki) except this plugin uses a different and more powerful markup based syntax for making flashcards.

**NB: Please do not use this in your main vault or main anki account until 0.5.0 is released (by 15-06-21).**

## Installation

1. Download `main.js` and `manifest.json` from [releases](https://github.com/debanjandhar12/Obsidian-Anki-Sync/releases) and put it in a new folder in your obsidian plugin folder.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "ObsidianAnkiSync",
"name": "Obsidian Anki Sync",
"version": "0.4.1",
"version": "0.9.0",
"description": "Obsidian plugin to make flashcards and sync them to Anki.",
"author": "debanjandhar12",
"authorUrl": "https://github.com/debanjandhar12",
Expand Down
3 changes: 2 additions & 1 deletion src/basicblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export class BasicBlock extends Block {
breaks: false,
typographer: false,
});

md.inline.ruler.disable(['sub','sup','ins']);
md.block.ruler.disable(['code']);
anki = md.render(anki);

return anki;
Expand Down
3 changes: 2 additions & 1 deletion src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ export abstract class Block {
let modified = this.original.replace(BlockStartCommentRegExp, function (match): string {
return insertAttrib(match, 'oid', oid);
});
modified = modified.replaceAll("$", "$$$$"); // Bug Fix: https://stackoverflow.com/questions/9423722/string-replace-weird-behavior-when-using-dollar-sign-as-replacement

// Read and modify the file with addition of id in obsidian
let fileContent = await this.vault.read(this.file);
fileContent = fileContent.replace(this.original, modified);
this.vault.modify(this.file, fileContent)
this.vault.modify(this.file, fileContent);
}

async getAnkiId(): Promise<number> {
Expand Down
3 changes: 2 additions & 1 deletion src/clozeblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export class ClozeBlock extends Block {
breaks: false,
typographer: false,
});

md.inline.ruler.disable(['sub','sup','ins']);
md.block.ruler.disable(['code']);
anki = md.render(anki);

return anki;
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default class MyPlugin extends Plugin {
blockIds.push(await block.getAnkiId());
console.log("Recognized Block's AnkiId:", blockIds);
// Get Anki Notes and their ids
await AnkiConnect.invoke("reloadCollection", {});
let q = await AnkiConnect.query(`tag:${this.app.vault.getName().replace(/\s/g, "_")} note:ObsidianAnkiSyncModel tag:ObsidianAnkiSync`)
let ankiIds:number[] = q.map(i=>parseInt(i));
console.log("Anki Notes created by App:", ankiIds);
Expand All @@ -108,7 +109,8 @@ export default class MyPlugin extends Plugin {
}

// -- Update Anki and show results --
AnkiConnect.invoke("reloadCollection", {});
await AnkiConnect.invoke("removeEmptyNotes", {});
await AnkiConnect.invoke("reloadCollection", {});
new Notice(`Sync Completed! \nCreated Blocks:${created} Updated Blocks:${updated} Deleted Blocks:${deleted}`, 3000);
console.log(`Sync Completed! Created Blocks:${created} Updated Blocks:${updated} Deleted Blocks:${deleted}`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/replaceblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export class ReplaceBlock extends Block {
breaks: false,
typographer: false,
});

md.inline.ruler.disable(['sub','sup','ins']);
md.block.ruler.disable(['code']);
anki = md.render(anki);

return anki;
Expand Down

0 comments on commit 4610015

Please sign in to comment.