diff --git a/src/compiler.ts b/src/compiler.ts index 10a89c8..fd69dc5 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -128,7 +128,7 @@ export class Compiler{ io: { - import : async (filepath) => await this.import(log, data, templateBlocks, filepath ), + import : async (filepath) => await this.import( log, data, templateBlocks, filepath ), async load(path):Promise { const filepath = Utils.getSameFolderFilepath(path); @@ -136,13 +136,13 @@ export class Compiler{ const af = app.vault.getAbstractFileByPath(filepath); if (!(af instanceof TFile)){ - return Promise.resolve(undefined); + return undefined; } return await app.vault.read(af) }, - load_data: async (filepath, name) => await this.data_loader(data, filepath, name), + load_data: async (filepath, name) => await this.data_loader( data, filepath, name ), //load_template: (filepath) => this.template_loader(templateBlocks, filepath), @@ -184,7 +184,7 @@ export class Compiler{ } }, - async open( linktext ) { + async open( linktext: string ) { await app.workspace.openLinkText( linktext, '' ); }, @@ -256,6 +256,8 @@ export class Compiler{ templates: string[], path:string ) : Promise{ + + //console.log('import'); const absFilepath = this.getAbsoluteFilepathFromActiveFile(path); if (!absFilepath){ @@ -272,6 +274,7 @@ export class Compiler{ if ( file.extension == 'md' ){ const content = await app.vault.read( file ); + //console.log({content}); const pzr = new Parser(); pzr.applyMarkdownContent( file.basename, content, data, templates); return true; diff --git a/src/parser.ts b/src/parser.ts index 60860e5..ac5dede 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -9,29 +9,29 @@ export class Parser { data:IDataSetCollection, templates:string[] ) : void { - const lines = content.split('\n').map( e=>e.trim().trim()); + const lines = content.split('\n'); //console.debug(lines); let currentHeader = ''; - for (let i = 0; i < lines.length; i++) { - const line = lines[i]; - if (line.startsWith('#')){ + for ( let i = 0; i < lines.length; i++ ) { + const trimLine = lines[i].trim(); + if (trimLine.startsWith('#')){ // header - currentHeader = this.extractHeader(line); - }else if (line.startsWith('|')){ + currentHeader = this.extractHeader(trimLine); + }else if ( trimLine.startsWith('|') ){ // extract table const tableLines: string[] = []; - while( i < lines.length && lines[i].startsWith('|') ){ - const tableLine = lines[i]; + while( i < lines.length && lines[i].trim().startsWith('|') ){ + const tableLine = lines[i].trim(); tableLines.push(tableLine); i++; } const dataPropName = this.convertToTableName( currentHeader.length > 0 ? currentHeader : name ); data[dataPropName] = this.parseAsMdTable(tableLines); - }else if ( line.startsWith('```html') ){ + }else if ( trimLine.startsWith('```html') ){ const templateLines: string[] = []; i++; - while( i < lines.length && !lines[i].startsWith('```') ){ + while( i < lines.length && !lines[i].trim().startsWith('```') ){ const templateLine = lines[i]; templateLines.push(templateLine); i++; @@ -42,7 +42,7 @@ export class Parser { } private extractHeader(line:string) : string{ - return this.convertToTableName(line.replace('#','')); + return this.convertToTableName(line.replace('#','').trim()); } private parseAsMdTable( tableLines:string[] ): DataSet {