Compare commits

...

6 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
7 changed files with 24 additions and 15 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

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.

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,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

@ -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;
}