Skip to content

Commit 83ffd4e

Browse files
committed
add the block id link
1 parent 05948ab commit 83ffd4e

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

data.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Basic++": "",
77
"Basic+++": "",
88
"Basic-73fde": "",
9-
"Cloze ALL": "(?:^[\\s-]*-[\\s-]*-[\\s-]*-[\\s-]*$\\n)((?:.*\\n)*?(?:.*\\{\\{c\\d+::(?:.|\\n)+?\\}\\}.*\\n)(?:^.{1,3}$|^.{4}(?<!<!--).*$\\n)*?)(?=(?:^<!--.*$\\n)?^[\\s-]*-[\\s-]*-[\\s-]*-[\\s-]*$\\n)",
9+
"Cloze ALL": "((?:.+\\n)*(?:.*{{c.*)(?:\\n(?:^.{1,3}$|^.{4}(?<!<!--)(?<!\\^ID-).*))*)",
1010
"Pot Card 2": "",
1111
"Python - Basic": "",
1212
"Python - Basic (and reversed card)": "",
@@ -72,8 +72,8 @@
7272
"Tag": "Obsidian_to_Anki",
7373
"Deck": "Default",
7474
"Scheduling Interval": 0,
75-
"Add File Link": false,
76-
"Add Context": false,
75+
"Add File Link": true,
76+
"Add Context": true,
7777
"CurlyCloze": false,
7878
"CurlyCloze - Highlights to Clozes": false,
7979
"ID Comments": true,
@@ -116,7 +116,8 @@
116116
"Welcome.md": "5dce4937496ad2d20178a7578f1a1368",
117117
"norcx'anki'test/未命名.md": "68a672a3c453707a5db64bd4da5324c5",
118118
"未命名.md": "d41d8cd98f00b204e9800998ecf8427e",
119-
"norcx'anki'test/挖空测试.md": "08d3f20ea7d3869cf4e63b8ad32533ae"
119+
"norcx'anki'test/挖空测试.md": "08d3f20ea7d3869cf4e63b8ad32533ae",
120+
"未命名 1 1.md": "9d5ac601c16c5b988e5351736714eaa9"
120121
},
121122
"fields_dict": {
122123
"Basic": [

src/file.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { CachedMetadata, HeadingCache } from 'obsidian'
1212
const double_regexp: RegExp = /(?:\r\n|\r|\n)((?:\r\n|\r|\n)(?:<!--)?ID: \d+)/g
1313
const card_regexp: RegExp = /(?:\r\n|\r|\n)((?:\r\n|\r|\n)[Card])/g
1414

15-
function id_to_str(identifier:number, inline:boolean = false, comment:boolean = false): string {
15+
function id_to_str(identifier:number, inline:boolean = false, comment:boolean = false,blocklinkid:boolean): string {
16+
if(blocklinkid){
17+
return "^ID-"+identifier.toString()
18+
}
1619
let result = "ID: " + identifier.toString()
1720
if (comment) {
1821
result = "<!--" + result + "-->"
@@ -470,7 +473,7 @@ export class AllFile extends AbstractFile {
470473
(id_position: number, index: number) => {
471474
const identifier: number | null = this.note_ids[index]
472475
if (identifier) {
473-
normal_inserts.push([id_position, id_to_str(identifier, false, this.data.comment)])
476+
normal_inserts.push([id_position, id_to_str(identifier, false, this.data.comment,this.data.add_card_link)])
474477
}
475478
}
476479
)
@@ -479,7 +482,7 @@ export class AllFile extends AbstractFile {
479482
(id_position: number, index: number) => {
480483
const identifier: number | null = this.note_ids[index + this.notes_to_add.length] //Since regular then inline
481484
if (identifier) {
482-
inline_inserts.push([id_position, id_to_str(identifier, true, this.data.comment)])
485+
inline_inserts.push([id_position, id_to_str(identifier, true, this.data.comment,this.data.add_card_link)])
483486
}
484487
}
485488
)
@@ -488,7 +491,7 @@ export class AllFile extends AbstractFile {
488491
(id_position: number, index: number) => {
489492
const identifier: number | null = this.note_ids[index + this.notes_to_add.length + this.inline_notes_to_add.length] // Since regular then inline then regex
490493
if (identifier) {
491-
regex_inserts.push([id_position, "\n" + id_to_str(identifier, false, this.data.comment)])
494+
regex_inserts.push([id_position, "\n" + id_to_str(identifier, false, this.data.comment,this.data.add_card_link)])
492495
}
493496
}
494497
)

src/files-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class FileManager {
143143
new AllFile(
144144
content,
145145
file.path,
146-
this.data.add_file_link ? this.getUrl(file) : "",
146+
this.data.add_file_link ? (this.data.add_card_link ? this.getUrl(file).slice(0,-3)+"%23%5E" :this.getUrl(file)) : "",
147147
file_data,
148148
cache,
149149
fullpath,

src/note.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { FileData } from './interfaces/settings-interface'
1010

1111
const TAG_PREFIX:string = "Tags: "
1212
export const TAG_SEP:string = " "
13-
export const ID_REGEXP_STR: string = String.raw`\n?(?:<!--)?(?:ID: (\d+).*)`
13+
export const ID_REGEXP_STR: string = String.raw`\n?(?:<!--)?(?:\^?ID(?:\: |-)(\d+).*)`//`\n?(?:<!--)?(?:ID: (\d+).*)`
1414
export const TAG_REGEXP_STR: string = String.raw`(Tags: .*)`
1515
const OBS_TAG_REGEXP: RegExp = /#(\w+)/g
1616

@@ -89,7 +89,12 @@ abstract class AbstractNote {
8989
template["fields"] = this.getFields()
9090
const file_link_fields = data.file_link_fields
9191
if (url) {
92-
this.formatter.format_note_with_url(template, url, file_link_fields[this.note_type])
92+
if(url.endsWith("%23%5E")){
93+
this.formatter.format_note_with_url(template,url+"ID-"+String(this.identifier), file_link_fields[this.note_type])
94+
}
95+
else{
96+
this.formatter.format_note_with_url(template,url, file_link_fields[this.note_type])
97+
}
9398
}
9499
if (Object.keys(frozen_fields_dict).length) {
95100
this.formatter.format_note_with_frozen_fields(template, frozen_fields_dict)
@@ -291,7 +296,12 @@ export class RegexNote {
291296
template["fields"] = this.getFields()
292297
const file_link_fields = data.file_link_fields
293298
if (url) {
294-
this.formatter.format_note_with_url(template, url, file_link_fields[this.note_type])
299+
if(url.endsWith("%23%5E")){
300+
this.formatter.format_note_with_url(template,url+"ID-"+String(this.identifier), file_link_fields[this.note_type])
301+
}
302+
else{
303+
this.formatter.format_note_with_url(template,url, file_link_fields[this.note_type])
304+
}
295305
}
296306
if (Object.keys(frozen_fields_dict).length) {
297307
this.formatter.format_note_with_frozen_fields(template, frozen_fields_dict)

0 commit comments

Comments
 (0)