markdown-up 2.0.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/data.js +2 -2
- package/lib/dataTable.js +55 -12
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -137,11 +137,11 @@ Debug mode logs the script runtime duration and runs the BareScript linter, whic
|
|
|
137
137
|
code analysis on your code and reports warnings for any issues found.
|
|
138
138
|
|
|
139
139
|
Debug mode also enables debug logging using the
|
|
140
|
-
[
|
|
140
|
+
[systemLogDebug function](https://craigahobbs.github.io/bare-script/library/#var.vName='systemLogDebug').
|
|
141
141
|
For example:
|
|
142
142
|
|
|
143
143
|
~~~ barescript
|
|
144
|
-
|
|
144
|
+
systemLogDebug('Hello debug')
|
|
145
145
|
~~~
|
|
146
146
|
|
|
147
147
|
To turn on debug mode, click the debug button in the MarkdownUp menu in the upper-right of the page.
|
package/lib/data.js
CHANGED
|
@@ -517,7 +517,7 @@ export function topData(data, count, categoryFields = null) {
|
|
|
517
517
|
|
|
518
518
|
|
|
519
519
|
// Helper function to format labels
|
|
520
|
-
export function formatValue(value, precision = null, datetime = null) {
|
|
520
|
+
export function formatValue(value, precision = null, datetime = null, trim = true) {
|
|
521
521
|
if (value instanceof Date) {
|
|
522
522
|
if (datetime === 'year') {
|
|
523
523
|
// Round to nearest year
|
|
@@ -546,7 +546,7 @@ export function formatValue(value, precision = null, datetime = null) {
|
|
|
546
546
|
return value.toISOString().replace(rDateCleanup, '');
|
|
547
547
|
} else if (typeof value === 'number') {
|
|
548
548
|
const numberFormat = value.toFixed(precision ?? defaultPrecision);
|
|
549
|
-
return numberFormat.replace(rNumberCleanup, '');
|
|
549
|
+
return trim ? numberFormat.replace(rNumberCleanup, '') : numberFormat;
|
|
550
550
|
}
|
|
551
551
|
return `${value}`;
|
|
552
552
|
}
|
package/lib/dataTable.js
CHANGED
|
@@ -24,8 +24,8 @@ struct DataTable
|
|
|
24
24
|
# The table's category fields
|
|
25
25
|
optional string[len > 0] categories
|
|
26
26
|
|
|
27
|
-
# The "categories" and "fields"
|
|
28
|
-
optional
|
|
27
|
+
# The field formatting for "categories" and "fields"
|
|
28
|
+
optional DataTableFieldFormat{len > 0} formats
|
|
29
29
|
|
|
30
30
|
# The numeric formatting precision (default is 2)
|
|
31
31
|
optional int(>= 0) precision
|
|
@@ -34,6 +34,23 @@ struct DataTable
|
|
|
34
34
|
optional DataTableDatetimeFormat datetime
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
# A data table field formatting model
|
|
38
|
+
struct DataTableFieldFormat
|
|
39
|
+
|
|
40
|
+
# If true, format the field as Markdown
|
|
41
|
+
optional bool markdown
|
|
42
|
+
|
|
43
|
+
# The field alignment
|
|
44
|
+
optional DataTableFieldAlignment align
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# A field alignment
|
|
48
|
+
enum DataTableFieldAlignment
|
|
49
|
+
left
|
|
50
|
+
right
|
|
51
|
+
center
|
|
52
|
+
|
|
53
|
+
|
|
37
54
|
# A datetime format
|
|
38
55
|
enum DataTableDatetimeFormat
|
|
39
56
|
|
|
@@ -97,8 +114,8 @@ export function dataTableElements(data, dataTable = null, options = null) {
|
|
|
97
114
|
}
|
|
98
115
|
|
|
99
116
|
// Generate the data table's element model
|
|
100
|
-
const
|
|
101
|
-
const markdownOptions = (
|
|
117
|
+
const fieldFormats = (dataTable !== null ? (dataTable.formats ?? null) : null);
|
|
118
|
+
const markdownOptions = (options !== null && 'urlFn' in options ? {'urlFn': options.urlFn} : null);
|
|
102
119
|
const formatPrecision = (dataTable !== null ? (dataTable.precision ?? null) : null);
|
|
103
120
|
const formatDatetime = (dataTable !== null ? (dataTable.datetime ?? null) : null);
|
|
104
121
|
return {
|
|
@@ -108,8 +125,22 @@ export function dataTableElements(data, dataTable = null, options = null) {
|
|
|
108
125
|
{
|
|
109
126
|
'html': 'tr',
|
|
110
127
|
'elem': [
|
|
111
|
-
categories.map((field) =>
|
|
112
|
-
|
|
128
|
+
categories.map((field) => {
|
|
129
|
+
const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
|
|
130
|
+
return {
|
|
131
|
+
'html': 'th',
|
|
132
|
+
'attr': (fieldFormat !== null && 'align' in fieldFormat ? {'style': `text-align: ${fieldFormat.align}`} : null),
|
|
133
|
+
'elem': {'text': field}
|
|
134
|
+
};
|
|
135
|
+
}),
|
|
136
|
+
tableFields.map((field) => {
|
|
137
|
+
const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
|
|
138
|
+
return {
|
|
139
|
+
'html': 'th',
|
|
140
|
+
'attr': (fieldFormat !== null && 'align' in fieldFormat ? {'style': `text-align: ${fieldFormat.align}`} : null),
|
|
141
|
+
'elem': {'text': field}
|
|
142
|
+
};
|
|
143
|
+
})
|
|
113
144
|
]
|
|
114
145
|
},
|
|
115
146
|
|
|
@@ -128,17 +159,29 @@ export function dataTableElements(data, dataTable = null, options = null) {
|
|
|
128
159
|
skip = (compareValues(value, rowPrev[field] ?? null) === 0);
|
|
129
160
|
}
|
|
130
161
|
|
|
131
|
-
const
|
|
162
|
+
const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
|
|
163
|
+
const fieldElements = fieldFormat !== null && fieldFormat.markdown
|
|
132
164
|
? markdownElements(parseMarkdown(`${value}`), markdownOptions)
|
|
133
|
-
: {'text': formatValue(value, formatPrecision, formatDatetime)};
|
|
134
|
-
return {
|
|
165
|
+
: {'text': formatValue(value, formatPrecision, formatDatetime, false)};
|
|
166
|
+
return {
|
|
167
|
+
'html': 'td',
|
|
168
|
+
'attr': fieldFormat !== null && 'align' in fieldFormat
|
|
169
|
+
? {'style': `text-align: ${fieldFormat.align}`} : null,
|
|
170
|
+
'elem': skip ? null : fieldElements
|
|
171
|
+
};
|
|
135
172
|
}),
|
|
136
173
|
tableFields.map((field) => {
|
|
137
174
|
const value = row[field] ?? null;
|
|
138
|
-
const
|
|
175
|
+
const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
|
|
176
|
+
const fieldElements = fieldFormat !== null && fieldFormat.markdown
|
|
139
177
|
? markdownElements(parseMarkdown(`${value}`), markdownOptions)
|
|
140
|
-
: {'text': formatValue(value, formatPrecision, formatDatetime)};
|
|
141
|
-
return {
|
|
178
|
+
: {'text': formatValue(value, formatPrecision, formatDatetime, false)};
|
|
179
|
+
return {
|
|
180
|
+
'html': 'td',
|
|
181
|
+
'attr': fieldFormat !== null && 'align' in fieldFormat
|
|
182
|
+
? {'style': `text-align: ${fieldFormat.align}`} : null,
|
|
183
|
+
'elem': fieldElements
|
|
184
|
+
};
|
|
142
185
|
})
|
|
143
186
|
]
|
|
144
187
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "node --test test/"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"bare-script": "~2.
|
|
25
|
+
"bare-script": "~2.1",
|
|
26
26
|
"element-model": "~1.1",
|
|
27
27
|
"markdown-model": "~1.8",
|
|
28
28
|
"schema-markdown": "~1.2",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"c8": "~8.0",
|
|
33
|
-
"eslint": "~8.
|
|
33
|
+
"eslint": "~8.48",
|
|
34
34
|
"jsdoc": "~4.0",
|
|
35
35
|
"jsdom": "~22.1"
|
|
36
36
|
}
|