From 9c28d77bc31d9c42403a7a8a9edf04e8a84e7707 Mon Sep 17 00:00:00 2001 From: Erin Schnabel Date: Mon, 12 Aug 2024 07:09:32 -0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20simplify=20comment=20parsi?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/obsidian/comment.ts | 7 +++++++ src/obsidian/processors/commentProcessor.ts | 12 +++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/obsidian/comment.ts b/src/obsidian/comment.ts index 0273351..bca5483 100644 --- a/src/obsidian/comment.ts +++ b/src/obsidian/comment.ts @@ -94,6 +94,13 @@ export class CommentParser { return this.parseRegex.test(line); } + replace(line: string, comment: Comment): string { + return line.replace( + this.readCommentRegex, + this.commentToString(comment), + ); + } + private readCommentStringFromLine(line: string): string { return this.readCommentRegex.exec(line)?.[0] ?? ''; } diff --git a/src/obsidian/processors/commentProcessor.ts b/src/obsidian/processors/commentProcessor.ts index ccdb6fc..410ec9c 100644 --- a/src/obsidian/processors/commentProcessor.ts +++ b/src/obsidian/processors/commentProcessor.ts @@ -1,21 +1,15 @@ import { CommentParser } from 'src/obsidian/comment'; export class CommentProcessor { - private readCommentRegex = //; - private parser: CommentParser = new CommentParser(); process(markdown: string) { return markdown .split('\n') .map(line => { - if (this.parser.lineHasComment(line)) { - return line.replace( - this.readCommentRegex, - this.parser.commentToString( - this.parser.parseLine(line), - ), - ); + const comment = this.parser.parseLine(line); + if (comment) { + return this.parser.replace(line, comment); } else { return line; }