Skip to content

Commit

Permalink
- update typescrpt
Browse files Browse the repository at this point in the history
- update formatting
- add support for reverse cards
- fix bug where trace logs weren't showing
  • Loading branch information
jasonwilliams committed Feb 25, 2023
1 parent 6c3e385 commit 4570ffd
Show file tree
Hide file tree
Showing 19 changed files with 268 additions and 347 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to the "anki" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [1.3.0]

- Support remote images [#99](https://github.com/jasonwilliams/anki/pull/99)
- Parse NoteIDs [#92](https://github.com/jasonwilliams/anki/pull/92)
- Fixed bug with trace not showing in logs
- updated TypeScript and updated formatting.

## [1.2.7]

- Fix bug that LaTeX curly brackets do not convert correctly [#63](https://github.com/jasonwilliams/anki/issues/63)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ echo "Hello, World!"
- `anki.api.port`: API Port. | _8765_
- `anki.api.schema`: Schema. | _http_
- `anki.saveStrategy`: the behavior of the command `Anki: Send To Deck` | _default_
- `anki.template`: Which template to use? Normal or reverse? | _BasicWithHighlightVSCode_

I don't recommend messing with the following settings

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@
"trace"
]
},
"anki.noteType": {
"type": "string",
"default": "BasicWithHighlightVSCode",
"description": "Which noteType should be used when creating a note?",
"enum": [
"BasicWithHighlightVSCode",
"BasicWithHighlightVSCodeRev"
]
},
"anki.md.card.separator": {
"type": "string",
"default": "(?=^##\\s)",
Expand Down Expand Up @@ -187,7 +196,7 @@
"jest": "27.0.6",
"jest-cli": "^27.0.6",
"prettier": "^2.8.2",
"typescript": "4.9.4"
"typescript": "4.9.5"
},
"dependencies": {
"cheerio": "^1.0.0-rc.10",
Expand Down
39 changes: 6 additions & 33 deletions src/AnkiCardProvider.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import { join } from "path";
import {
TreeItemCollapsibleState,
TreeItem,
ExtensionContext,
TreeDataProvider,
window,
Uri,
} from "vscode";
import { TreeDataProvider, TreeItem, TreeItemCollapsibleState, Uri, window } from "vscode";
import { AnkiService } from "./AnkiService";
import { IContext } from "./extension";
import { AnkiFS } from "./fileSystemProvider";
import { getAnkiState } from "./state";

export class AnkiCardProvider implements TreeDataProvider<Dependency> {
private ankiService: AnkiService;
private context: ExtensionContext;
private context: IContext;
private ankiFS: AnkiFS;
private state: any;

constructor(extContext: IContext) {
this.ankiService = extContext.ankiService;
this.context = extContext.context;
this.context = extContext;
if (!extContext?.getAnkiFS) {
throw new Error("Anki Error: initialised AnkiFS/AnkiState is required");
}
Expand Down Expand Up @@ -140,35 +133,15 @@ export class AnkiCardProvider implements TreeDataProvider<Dependency> {
create: true,
overwrite: true,
});
const css = new Dependency(
"styling.css",
uri,
TreeItemCollapsibleState.None,
uri,
ItemType.Css
);
const css = new Dependency("styling.css", uri, TreeItemCollapsibleState.None, uri, ItemType.Css);

return css;
}

getIconPath(iconName: string): object {
return {
light: join(
this.context.extensionPath,
"src",
"resources",
"icons",
"light",
`${iconName}.svg`
),
dark: join(
this.context.extensionPath,
"src",
"resources",
"icons",
"dark",
`${iconName}.svg`
),
light: join(this.context.context.extensionPath, "src", "resources", "icons", "light", `${iconName}.svg`),
dark: join(this.context.context.extensionPath, "src", "resources", "icons", "dark", `${iconName}.svg`),
};
}
}
Expand Down
28 changes: 12 additions & 16 deletions src/AnkiService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fetch from "node-fetch";
import { load } from "cheerio";
import { Deck } from "./models/Deck";
import { Card } from "./models/Card";
import fetch from "node-fetch";
import { getLogger } from "./logger";
import { CONSTANTS } from "./constants";
import { Model } from "./manageTemplate";
import { Card } from "./models/Card";
import { Deck } from "./models/Deck";
import { getAnkiState } from "./state";

interface IResponse {
Expand Down Expand Up @@ -78,9 +78,7 @@ export class AnkiService {
});
}

async storeMultipleFiles(
files: { filename: string; data: string }[]
): Promise<any> {
async storeMultipleFiles(files: { filename: string; data: string }[]): Promise<any> {
const actions = files.map((v) => ({
action: "storeMediaFile",
params: {
Expand Down Expand Up @@ -111,16 +109,14 @@ export class AnkiService {
async modelTemplates(modelName: string): Promise<object> {
return await this.invoke("modelTemplates", { modelName });
}
async updateModelTemplate(model: any) {
async updateModelTemplate(model: Model) {
return await this.invoke("updateModelTemplates", {
model: {
name: CONSTANTS.defaultTemplateName,
templates: {
"Card 1": {
Front: model.cardTemplates[0].Front,
Back: model.cardTemplates[0].Back,
},
},
name: model.modelName,
templates: model.cardTemplates.reduce((acc, v) => {
(acc as any)[v.Name] = { Front: v.Front, Back: v.Back };
return acc;
}, {}),
},
});
}
Expand Down Expand Up @@ -164,7 +160,7 @@ export class AnkiService {
const cleanQuestion = $("html").text();
$ = load(v.answer.toString());
const cleanAnswer = $("html").text();
const newCard = new Card(cleanQuestion, cleanAnswer)
const newCard = new Card(cleanQuestion, cleanAnswer, undefined, undefined, v.modelName)
.setNoteId(v.note)
.setFields(v.fields)
.setDeckName(v.deckName);
Expand Down
Loading

0 comments on commit 4570ffd

Please sign in to comment.