Compare commits

...

9 commits

Author SHA1 Message Date
meld-cp
60b609a904
Update LICENSE 2024-06-06 19:39:19 +12:00
meld-cp
26e6163047 update gitignore 2024-04-07 13:45:13 +12:00
meld-cp
e75c9c7454
Merge pull request #3 from meld-cp/meld-cp/issue2
Add cell formatting for markdown table creation
2023-03-31 13:44:29 +13:00
meld-cp
f161094121 Add cell formatting for markdown table creation
Fixes #2
2023-03-31 00:40:08 +00:00
meld-cp
f40da8d781
Update user-guide.md 2023-03-30 07:16:13 +13:00
meld-cp
0bbb5f0d44
Update api.md 2023-03-27 04:02:12 +13:00
Cleon
12f591841c ver bump 2023-03-26 10:33:39 +13:00
Cleon
26181f02dc use cachedRead instead of read 2023-03-26 10:32:04 +13:00
Cleon
214df0d6fb remove use of innerHTML for messages 2023-03-26 10:12:45 +13:00
15 changed files with 50 additions and 38 deletions

5
.gitignore vendored
View file

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

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 Michael Brenan
Copyright (c) 2023 Cleon Pinto
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.8",
"version": "0.1.9",
"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 message with title
await $.ui.message( 'A Title', 'A titled <b>message</b>' );
// show a 2 line message with title
await $.ui.message( 'A Title', 'A titled message\nLine 2' );
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:
```html
<p>Greetings <strong>{{name}}</strong>, {{message}}</p>
```
Greetings {{name}}, {{message}}
```
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.8",
"version": "0.1.9",
"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.6",
"version": "0.1.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "meld-build-obsidian-plugin",
"version": "0.1.6",
"version": "0.1.9",
"license": "MIT",
"devDependencies": {
"@types/handlebars": "^4.1.0",

View file

@ -1,6 +1,6 @@
{
"name": "meld-build-obsidian-plugin",
"version": "0.1.8",
"version": "0.1.9",
"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,12 +15,10 @@ export class MessageModal extends Modal {
this.titleEl.setText( title );
this.message = message;
this.contentEl.append( ...MessageModal.buildContent( message ) );
await new Promise<void>((resolve) => {
this.open();
this.onClose = () => {
this.contentEl.empty();
resolve();
@ -29,10 +27,17 @@ export class MessageModal extends Modal {
}
onOpen() {
const { contentEl } = this;
const formattedLines = this.message.split('\n').join('<br/>');
contentEl.innerHTML = formattedLines;
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;
}
}

View file

@ -12,7 +12,7 @@ export class Parser {
const result: NamedCodeBlock[] = [];
const file = view.file;
const fileContent = await view.app.vault.read(file);
const fileContent = await view.app.vault.cachedRead(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.read(file);
const fileContent = await view.app.vault.cachedRead(file);
const fileCache = view.app.metadataCache.getFileCache( file );
if ( fileCache == null ){
@ -232,9 +232,6 @@ 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.read( file );
const dataSet = pzr.loadCsv(csvdata);
const csvData = await this.vault.cachedRead( 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.read( file );
const content = await this.vault.cachedRead( file );
const pzr = new Parser();
pzr.applyMarkdownContent(
file.basename,
@ -94,7 +94,7 @@ export class IoRunContextImplementation implements TIoRunContext {
return undefined;
}
return await this.vault.read(af)
return await this.vault.cachedRead(af)
}
async load_data(path: string, name?: string | undefined): Promise<DataSet> {

View file

@ -1,5 +1,5 @@
import { DataSet } from "./data-set";
import { TMarkdownHelperRunContext } from "./run-context";
import { TMarkdownHelperRunContext, TMarkdownHelperTableCellFormatter } 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): string {
buildTableFromDataSet(data: DataSet, cellFormatter?:TMarkdownHelperTableCellFormatter): string {
const headings = data.columns;
const rowValues : any[][] = [];
@ -23,7 +23,13 @@ export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRu
for (const heading of headings) {
const prop = data.getPropertyName(heading);
const value = prop == undefined ? undefined : row[prop];
let value = prop == undefined ? undefined : row[prop];
if (prop != undefined && cellFormatter != null){
const formattedValue = cellFormatter(prop, value);
if (formattedValue != undefined){
value = formattedValue;
}
}
values.push(value);
}
@ -35,7 +41,7 @@ export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRu
public table(arg1: unknown, arg2?: unknown): string {
if (arg1 instanceof DataSet){
return this.buildTableFromDataSet(arg1);
return this.buildTableFromDataSet(arg1, arg2 as TMarkdownHelperTableCellFormatter);
}
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.read( targetFile );
return await this.vault.cachedRead( 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 ) : string;
table( data:DataSet, cellFormatter?:TMarkdownHelperTableCellFormatter ) : string;
}

View file

@ -6,5 +6,6 @@
"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.8": "1.0.1",
"0.1.9": "1.0.1"
}