File tree Expand file tree Collapse file tree 4 files changed +52
-1
lines changed Expand file tree Collapse file tree 4 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -2,4 +2,5 @@ export const ObsidianRegex = {
2
2
IMAGE_LINK : / ! \[ \[ ( [ ^ | \] ] + ) \| ? ( \d * ) ] ] / g,
3
3
WIKI_LINK : / (?< ! ! ) \[ \[ ( [ ^ | \] ] + ) \| ? ( .* ) ] ] / g,
4
4
CALLOUT : / > \[ ! ( .* ) ] .* ?\n ( > .* ) / ig,
5
+ SIMPLE_FOOTNOTE : / \[ \^ ( \d + ) ] / g
5
6
} as const ;
Original file line number Diff line number Diff line change
1
+ import { AbstractConverter } from "../core/Converter" ;
2
+ import { ObsidianRegex } from "../ObsidianRegex" ;
3
+
4
+ export class FootnotesConverter extends AbstractConverter {
5
+
6
+ convert ( input : string ) : string {
7
+ const result = input . replace ( ObsidianRegex . SIMPLE_FOOTNOTE , ( match , key ) => {
8
+ return `[^fn-nth-${ key } ]` ;
9
+ } ) ;
10
+ return super . convert ( result ) ;
11
+ }
12
+
13
+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { Notice, TFile } from "obsidian";
8
8
import { CalloutConverter } from "./CalloutConverter" ;
9
9
import { FrontMatterConverter } from "./FrontMatterConverter" ;
10
10
import { vaultAbsolutePath } from "../utils" ;
11
+ import { FootnotesConverter } from "./FootnotesConverter" ;
11
12
12
13
export async function convertToChirpy ( plugin : O2Plugin ) {
13
14
// validation
@@ -35,10 +36,12 @@ export async function convertToChirpy(plugin: O2Plugin) {
35
36
plugin . settings . jekyllSetting ( ) . jekyllRelativeResourcePath
36
37
) ;
37
38
const calloutConverter = new CalloutConverter ( ) ;
39
+ const footnotesConverter = new FootnotesConverter ( ) ;
38
40
39
41
frontMatterConverter . setNext ( wikiLinkConverter )
40
42
. setNext ( resourceLinkConverter )
41
- . setNext ( calloutConverter ) ;
43
+ . setNext ( calloutConverter )
44
+ . setNext ( footnotesConverter ) ;
42
45
43
46
const result = frontMatterConverter . convert ( await plugin . app . vault . read ( file ) ) ;
44
47
await plugin . app . vault . modify ( file , result ) ;
Original file line number Diff line number Diff line change
1
+ import { FootnotesConverter } from "../jekyll/FootnotesConverter" ;
2
+
3
+ const converter = new FootnotesConverter ( ) ;
4
+
5
+ describe ( "FootnotesConverter" , ( ) => {
6
+ it ( "should convert simple footnotes" , ( ) => {
7
+ const contents = `
8
+ # Hello World
9
+
10
+ This is a simple footnote[^1]. next footnote[^2].
11
+
12
+ [^1]: meaningful
13
+
14
+ [^2]: meaningful 2
15
+
16
+ ` ;
17
+
18
+ const expected = `
19
+ # Hello World
20
+
21
+ This is a simple footnote[^fn-nth-1]. next footnote[^fn-nth-2].
22
+
23
+ [^fn-nth-1]: meaningful
24
+
25
+ [^fn-nth-2]: meaningful 2
26
+
27
+ ` ;
28
+ const actual = converter . convert ( contents ) ;
29
+ expect ( actual ) . toEqual ( expected ) ;
30
+ } ) ;
31
+
32
+ it . todo ( "should convert footnotes with multiple lines" ) ;
33
+ it . todo ( "should convert inline footnotes" ) ;
34
+ } ) ;
You can’t perform that action at this time.
0 commit comments