55 AnkiLinkSettingsTab ,
66} from "./settings" ;
77import { TARGET_DECK , sendAddNoteRequest , buildNote , sendCreateDeckRequest , sendDeckNamesRequest , ConnNoteFields } from "./ankiConnectUtil" ;
8+ import { FLASHCARD_PATTERN , splitCalloutBody } from "./regexUtil" ;
89
910export default class AnkiLink extends Plugin {
1011 settings ! : AnkiLinkSettings ;
@@ -58,10 +59,8 @@ export default class AnkiLink extends Plugin {
5859 const fileContents = await Promise . all (
5960 vault . getMarkdownFiles ( ) . map ( ( file ) => vault . read ( file ) ) ,
6061 ) ;
61- const pattern : RegExp =
62- / \[ ! f l a s h c a r d \] \s * ( [ ^ \n ] * ) \n ( (?: > (?: [ ^ \n ] * ) \n ? ) * ) / ;
6362 fileContents . forEach ( ( c ) => {
64- const values = pattern . exec ( c ) ;
63+ const values = FLASHCARD_PATTERN . exec ( c ) ;
6564 values ?. shift ( ) ;
6665 } ) ;
6766 const deckNamesRes = await sendDeckNamesRequest ( ) ;
@@ -72,11 +71,14 @@ export default class AnkiLink extends Plugin {
7271 if ( createDeckRes . error ) throw new Error ( `AnkiConnect: ${ createDeckRes . error } ` )
7372 }
7473 const cards = fileContents . reduce < ConnNoteFields [ ] > ( ( acc , s ) => {
75- const matches = pattern . exec ( s ) ;
74+ const matches = FLASHCARD_PATTERN . exec ( s ) ;
7675 if ( ! matches || matches . length < 3 ) {
7776 return acc ;
7877 }
79- acc . push ( { Front : matches [ 1 ] ! , Back : matches [ 2 ] ! } ) ;
78+ const title = matches [ 1 ] ! ;
79+ const body = matches [ 2 ] ! ;
80+ const back = splitCalloutBody ( body ) ;
81+ acc . push ( { Front : title , Back : back } ) ;
8082 return acc ;
8183 } , [ ] ) ;
8284 console . log ( cards )
0 commit comments