Compare commits

..

No commits in common. "master" and "0.1.8" have entirely different histories.

15 changed files with 38 additions and 50 deletions

5
.gitignore vendored
View file

@ -22,7 +22,4 @@ data.json
.DS_Store
# Test vault
test-vault
# Other
desktop.ini
test-vault

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023 Cleon Pinto
Copyright (c) 2021 Michael Brenan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

2
dist/manifest.json vendored
View file

@ -1,7 +1,7 @@
{
"id": "meld-build",
"name": "Meld Build",
"version": "0.1.9",
"version": "0.1.8",
"minAppVersion": "1.0.1",
"description": "Write and execute (sandboxed) JavaScript to render templates, query DataView and create dynamic notes.",
"author": "meld-cp",

View file

@ -75,8 +75,8 @@ const ans4 = await $.ui.ask( 'Title', 'question 4', ['1', '2', '3'] );
// show a message
await $.ui.message( `Your answers were:\n\n${ans1}, ${ans2}, ${ans3}, ${ans4}` );
// show a 2 line message with title
await $.ui.message( 'A Title', 'A titled message\nLine 2' );
// show a message with title
await $.ui.message( 'A Title', 'A titled <b>message</b>' );
await $.ui.message( 'Math', 13 * 67 );
// rebuild the current view, may be needed if you have an embedded note which was modified

View file

@ -100,8 +100,8 @@ Say your note looks like this:
# My Runnable Note
The template codeblock:
```
Greetings {{name}}, {{message}}
```html
<p>Greetings <strong>{{name}}</strong>, {{message}}</p>
```
The meld-build block to run:
@ -116,7 +116,7 @@ await $.ui.message( result );
````
Running this note will show a message with the following text: 'Greetings John, How are you?'
Running this note will show a message with the following text: 'Greetings **John**, How are you?'
See the `$.io.import` and `$.io.load` [API](api.md) functions for other ways to load templates.

View file

@ -1,7 +1,7 @@
{
"id": "meld-build",
"name": "Meld Build",
"version": "0.1.9",
"version": "0.1.8",
"minAppVersion": "1.0.1",
"description": "Write and execute (sandboxed) JavaScript to render templates, query DataView and create dynamic notes.",
"author": "meld-cp",

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "meld-build-obsidian-plugin",
"version": "0.1.9",
"version": "0.1.6",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "meld-build-obsidian-plugin",
"version": "0.1.9",
"version": "0.1.6",
"license": "MIT",
"devDependencies": {
"@types/handlebars": "^4.1.0",

View file

@ -1,6 +1,6 @@
{
"name": "meld-build-obsidian-plugin",
"version": "0.1.9",
"version": "0.1.8",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {

View file

@ -4,8 +4,8 @@ export class MessageModal extends Modal {
private message:string;
constructor( app: App ) {
super( app );
constructor(app: App) {
super(app);
}
public async execute(
@ -15,10 +15,12 @@ export class MessageModal extends Modal {
this.titleEl.setText( title );
this.contentEl.append( ...MessageModal.buildContent( message ) );
this.message = message;
await new Promise<void>((resolve) => {
this.open();
this.onClose = () => {
this.contentEl.empty();
resolve();
@ -27,17 +29,10 @@ export class MessageModal extends Modal {
}
private static buildContent( message: string ) : Node[] {
const result = Array<Node>();
const lines = message.split( '\n' );
lines.forEach( line => {
result.push( createDiv( { text: line } ) );
} );
return result;
onOpen() {
const { contentEl } = this;
const formattedLines = this.message.split('\n').join('<br/>');
contentEl.innerHTML = formattedLines;
}
}

View file

@ -12,7 +12,7 @@ export class Parser {
const result: NamedCodeBlock[] = [];
const file = view.file;
const fileContent = await view.app.vault.cachedRead(file);
const fileContent = await view.app.vault.read(file);
const fileCache = view.app.metadataCache.getFileCache( file );
if ( fileCache == null ){
@ -210,7 +210,7 @@ export class Parser {
} = {};
const file = view.file;
const fileContent = await view.app.vault.cachedRead(file);
const fileContent = await view.app.vault.read(file);
const fileCache = view.app.metadataCache.getFileCache( file );
if ( fileCache == null ){
@ -232,6 +232,9 @@ export class Parser {
}
if ( section.type == 'table' ){
// const from = editor.offsetToPos(section.position.start.offset);
// const to = editor.offsetToPos(section.position.end.offset);
// const table = editor.getRange( from, to );
const table = fileContent.slice(
section.position.start.offset,
section.position.end.offset

View file

@ -45,8 +45,8 @@ export class IoRunContextImplementation implements TIoRunContext {
if (file instanceof TFile){
if ( file.extension == 'csv'){
const csvData = await this.vault.cachedRead( file );
const dataSet = pzr.loadCsv(csvData);
const csvdata = await this.vault.read( file );
const dataSet = pzr.loadCsv(csvdata);
this.data[name??file.basename] = dataSet;
return dataSet;
}
@ -70,7 +70,7 @@ export class IoRunContextImplementation implements TIoRunContext {
}
if ( file.extension == 'md' ){
const content = await this.vault.cachedRead( file );
const content = await this.vault.read( file );
const pzr = new Parser();
pzr.applyMarkdownContent(
file.basename,
@ -94,7 +94,7 @@ export class IoRunContextImplementation implements TIoRunContext {
return undefined;
}
return await this.vault.cachedRead(af)
return await this.vault.read(af)
}
async load_data(path: string, name?: string | undefined): Promise<DataSet> {

View file

@ -1,5 +1,5 @@
import { DataSet } from "./data-set";
import { TMarkdownHelperRunContext, TMarkdownHelperTableCellFormatter } from "./run-context";
import { TMarkdownHelperRunContext } from "./run-context";
import { RunLogger } from "./run-logger";
export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRunContext{
@ -14,7 +14,7 @@ export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRu
return MarkdownTableHelper.buildTable( headings, rows );
}
buildTableFromDataSet(data: DataSet, cellFormatter?:TMarkdownHelperTableCellFormatter): string {
buildTableFromDataSet(data: DataSet): string {
const headings = data.columns;
const rowValues : any[][] = [];
@ -23,13 +23,7 @@ export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRu
for (const heading of headings) {
const prop = data.getPropertyName(heading);
let value = prop == undefined ? undefined : row[prop];
if (prop != undefined && cellFormatter != null){
const formattedValue = cellFormatter(prop, value);
if (formattedValue != undefined){
value = formattedValue;
}
}
const value = prop == undefined ? undefined : row[prop];
values.push(value);
}
@ -41,7 +35,7 @@ export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRu
public table(arg1: unknown, arg2?: unknown): string {
if (arg1 instanceof DataSet){
return this.buildTableFromDataSet(arg1, arg2 as TMarkdownHelperTableCellFormatter);
return this.buildTableFromDataSet(arg1);
}
if ( Array.isArray(arg1) && Array.isArray(arg2) ){
return this.buildTable(arg1, arg2);

View file

@ -71,7 +71,7 @@ export class MarkerRunContextImplementation implements TMarkerRunContext {
private async getTargetContents() : Promise<string>{
const targetFile = this.getTargetFileOrThrow();
return await this.vault.cachedRead( targetFile );
return await this.vault.read( targetFile );
}
async fetch(): Promise<MarkerValue[]> {

View file

@ -118,9 +118,9 @@ export class MarkerChange{
}
}
export type TMarkdownHelperTableCellFormatter = (propName:string, value:any) => string|undefined;
export type TMarkdownHelperRunContext = {
table( headings:Array<string>, rows:Array<Array<any>> ) : string;
table( data:DataSet, cellFormatter?:TMarkdownHelperTableCellFormatter ) : string;
table( data:DataSet ) : string;
}

View file

@ -6,6 +6,5 @@
"0.1.5": "1.0.1",
"0.1.6": "1.0.1",
"0.1.7": "1.0.1",
"0.1.8": "1.0.1",
"0.1.9": "1.0.1"
"0.1.8": "1.0.1"
}