Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/conf/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class Regex {
wikiImageLinks: RegExp;
markdownImageLinks: RegExp;
wikiAudioLinks: RegExp;
htmlImgTags: RegExp;
obsidianCodeBlock: RegExp; // ```code block``
codeBlock: RegExp;
mathBlock: RegExp; // $$ latex $$
Expand Down Expand Up @@ -41,6 +42,8 @@ export class Regex {
this.wikiAudioLinks =
/!\[\[(.*\.(?:mp3|webm|wav|m4a|ogg|3gp|flac)).*?\]\]/gim;

this.htmlImgTags = /<img src=([^>]+)'/g;

// https://regex101.com/r/eqnJeW/1
this.obsidianCodeBlock = /(?:```(?:.*?\n?)+?```)(?:\n|$)/gim;

Expand All @@ -49,7 +52,7 @@ export class Regex {
this.mathBlock = /(\$\$)(.*?)(\$\$)/gis;
this.mathInline = /(\$)(.*?)(\$)/gi;

this.cardsDeckLine = /cards-deck: [\p{L}]+/giu;
this.cardsDeckLine = /cards-deck: [^\n]+/giu;
this.cardsToDelete = /^\s*(?:\n)(?:\^(\d{13}))(?:\n\s*?)?/gm;

// https://regex101.com/r/WxuFI2/1
Expand Down
3 changes: 2 additions & 1 deletion src/entities/flashcard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { codeDeckExtension, sourceDeckExtension } from "src/conf/constants";
import { Card } from "src/entities/card";
import {substituteSep} from "src/utils";

export class Flashcard extends Card {
constructor(
Expand Down Expand Up @@ -58,7 +59,7 @@ export class Flashcard extends Card {
const medias: object[] = [];
this.mediaBase64Encoded.forEach((data, index) => {
medias.push({
filename: this.mediaNames[index],
filename: substituteSep(this.mediaNames[index]),
data: data,
});
});
Expand Down
5 changes: 4 additions & 1 deletion src/services/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Flashcard } from "../entities/flashcard";
import { Inlinecard } from "src/entities/inlinecard";
import { Spacedcard } from "src/entities/spacedcard";
import { Clozecard } from "src/entities/clozecard";
import { escapeMarkdown } from "src/utils";
import {escapeMarkdown, substituteSep} from "src/utils";
import { Card } from "src/entities/card";
import { htmlToMarkdown } from 'obsidian';

Expand Down Expand Up @@ -509,6 +509,9 @@ export class Parser {
private substituteImageLinks(str: string): string {
str = str.replace(this.regex.wikiImageLinks, "<img src='$1'>");
str = str.replace(this.regex.markdownImageLinks, "<img src='$1'>");
str = str.replace(this.regex.htmlImgTags, function (match, p1, p2) {
return substituteSep(match);
});

return str;
}
Expand Down
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ export function escapeMarkdown(string: string, skips: string[] = []) {

export function escapeRegExp(str: string) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}
}

export function substituteSep(str: string): string {
return str.replace("/", "__")
}