File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,4 +2,5 @@ export const ObsidianRegex = {
22 IMAGE_LINK : / ! \[ \[ ( [ ^ | \] ] + ) \| ? ( \d * ) ] ] / g,
33 WIKI_LINK : / (?< ! ! ) \[ \[ ( [ ^ | \] ] + ) \| ? ( .* ) ] ] / g,
44 CALLOUT : / > \[ ! ( .* ) ] .* ?\n ( > .* ) / ig,
5+ SIMPLE_FOOTNOTE : / \[ \^ ( \d + ) ] / g
56} 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";
88import { CalloutConverter } from "./CalloutConverter" ;
99import { FrontMatterConverter } from "./FrontMatterConverter" ;
1010import { vaultAbsolutePath } from "../utils" ;
11+ import { FootnotesConverter } from "./FootnotesConverter" ;
1112
1213export async function convertToChirpy ( plugin : O2Plugin ) {
1314 // validation
@@ -35,10 +36,12 @@ export async function convertToChirpy(plugin: O2Plugin) {
3536 plugin . settings . jekyllSetting ( ) . jekyllRelativeResourcePath
3637 ) ;
3738 const calloutConverter = new CalloutConverter ( ) ;
39+ const footnotesConverter = new FootnotesConverter ( ) ;
3840
3941 frontMatterConverter . setNext ( wikiLinkConverter )
4042 . setNext ( resourceLinkConverter )
41- . setNext ( calloutConverter ) ;
43+ . setNext ( calloutConverter )
44+ . setNext ( footnotesConverter ) ;
4245
4346 const result = frontMatterConverter . convert ( await plugin . app . vault . read ( file ) ) ;
4447 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