Skip to content

Commit

Permalink
feature: added icon shortcode support :shortcode: (MSzturc#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzturc committed Jan 3, 2022
1 parent e32376e commit fa6a568
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/obsidianMarkdownPreprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CommentProcessor } from "./processors/commentProcessor";
import { DropProcessor } from "./processors/dropProcessor";
import { YamlStore } from "./yamlStore";
import { AutoClosingProcessor } from "./processors/autoClosingProcessor";
import { IconsProcessor } from "./processors/iconsProcessor";

export class ObsidianMarkdownPreprocessor {

Expand All @@ -32,6 +33,7 @@ export class ObsidianMarkdownPreprocessor {
private commentProcessor: CommentProcessor;
private dropProcessor: DropProcessor;
private autoClosingProcessor: AutoClosingProcessor;
private iconsProcessor: IconsProcessor;

constructor(utils: ObsidianUtils) {
this.multipleFileProcessor = new MultipleFileProcessor(utils);
Expand All @@ -48,12 +50,14 @@ export class ObsidianMarkdownPreprocessor {
this.commentProcessor = new CommentProcessor();
this.dropProcessor = new DropProcessor();
this.autoClosingProcessor = new AutoClosingProcessor();
this.iconsProcessor = new IconsProcessor();
}
process(markdown: string, options: Options) {
YamlStore.getInstance().options = options;
const afterMultipleFileProcessor = this.multipleFileProcessor.process(markdown);
const afterAutoClosingProcessor = this.autoClosingProcessor.process(afterMultipleFileProcessor);
const afterDropProcessor = this.dropProcessor.process(afterAutoClosingProcessor, options);
const afterIconsProcessor = this.iconsProcessor.process(afterAutoClosingProcessor);
const afterDropProcessor = this.dropProcessor.process(afterIconsProcessor, options);
const afterMermaidProcessor = this.mermaidProcessor.process(afterDropProcessor);
const afterBlockProcessor = this.blockProcessor.process(afterMermaidProcessor);
const afterFootNoteProcessor = this.footnoteProcessor.process(afterBlockProcessor, options);
Expand Down
15 changes: 15 additions & 0 deletions src/processors/iconsProcessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export class IconsProcessor {

private regex = /:(fas|far|fal|fad|fab)_([\w]+):/g;

process(markdown: string){
return this.transformIconShortcode(markdown);
}

transformIconShortcode(markdown: string) {
markdown = markdown.replaceAll(this.regex, `![]($1 fa-$2)`);
return markdown;
}

}

0 comments on commit fa6a568

Please sign in to comment.