mirror of
https://github.com/meld-cp/obsidian-build.git
synced 2026-07-22 07:30:25 +00:00
fix template line trimming
This commit is contained in:
parent
ab0e6eac50
commit
8601900e80
2 changed files with 18 additions and 15 deletions
|
|
@ -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<string|undefined> {
|
||||
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<boolean>{
|
||||
|
||||
//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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue