markdown-up 2.3.0 → 2.3.1

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/lib/dataTable.js CHANGED
@@ -41,12 +41,15 @@ struct DataTable
41
41
  # A data table field formatting model
42
42
  struct DataTableFieldFormat
43
43
 
44
- # If true, format the field as Markdown
45
- optional bool markdown
46
-
47
44
  # The field alignment
48
45
  optional DataTableFieldAlignment align
49
46
 
47
+ # If true, don't wrap text
48
+ optional bool nowrap
49
+
50
+ # If true, format the field as Markdown
51
+ optional bool markdown
52
+
50
53
 
51
54
  # A field alignment
52
55
  enum DataTableFieldAlignment
@@ -134,7 +137,7 @@ export function dataTableElements(data, dataTable = null, options = null) {
134
137
  const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
135
138
  return {
136
139
  'html': 'th',
137
- 'attr': (fieldFormat !== null && 'align' in fieldFormat ? {'style': `text-align: ${fieldFormat.align}`} : null),
140
+ 'attr': createFieldAttr(fieldFormat),
138
141
  'elem': {'text': field}
139
142
  };
140
143
  }),
@@ -142,7 +145,7 @@ export function dataTableElements(data, dataTable = null, options = null) {
142
145
  const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
143
146
  return {
144
147
  'html': 'th',
145
- 'attr': (fieldFormat !== null && 'align' in fieldFormat ? {'style': `text-align: ${fieldFormat.align}`} : null),
148
+ 'attr': createFieldAttr(fieldFormat),
146
149
  'elem': {'text': field}
147
150
  };
148
151
  })
@@ -170,9 +173,8 @@ export function dataTableElements(data, dataTable = null, options = null) {
170
173
  : {'text': formatValue(value, formatPrecision, formatDatetime, formatTrim)};
171
174
  return {
172
175
  'html': 'td',
173
- 'attr': fieldFormat !== null && 'align' in fieldFormat
174
- ? {'style': `text-align: ${fieldFormat.align}`} : null,
175
- 'elem': skip ? null : fieldElements
176
+ 'attr': createFieldAttr(fieldFormat),
177
+ 'elem': (skip ? null : fieldElements)
176
178
  };
177
179
  }),
178
180
  tableFields.map((field) => {
@@ -183,8 +185,7 @@ export function dataTableElements(data, dataTable = null, options = null) {
183
185
  : {'text': formatValue(value, formatPrecision, formatDatetime, formatTrim)};
184
186
  return {
185
187
  'html': 'td',
186
- 'attr': fieldFormat !== null && 'align' in fieldFormat
187
- ? {'style': `text-align: ${fieldFormat.align}`} : null,
188
+ 'attr': createFieldAttr(fieldFormat),
188
189
  'elem': fieldElements
189
190
  };
190
191
  })
@@ -194,3 +195,15 @@ export function dataTableElements(data, dataTable = null, options = null) {
194
195
  ]
195
196
  };
196
197
  }
198
+
199
+
200
+ function createFieldAttr(fieldFormat) {
201
+ const fieldStyles = [];
202
+ if (fieldFormat !== null && 'align' in fieldFormat) {
203
+ fieldStyles.push(`text-align: ${fieldFormat.align}`);
204
+ }
205
+ if (fieldFormat !== null && fieldFormat.nowrap) {
206
+ fieldStyles.push('white-space: nowrap');
207
+ }
208
+ return (fieldStyles.length ? {'style': fieldStyles.join('; ')} : null);
209
+ }
@@ -398,7 +398,7 @@ export const markdownScriptFunctions = {
398
398
  // $doc: Compute the text's height to fit the width
399
399
  // $arg text: The text
400
400
  // $arg width: The width of the text. If 0, the default font size (in pixels) is returned.
401
- // $return: The text's height
401
+ // $return: The text's height, in pixels
402
402
  'drawTextHeight': ([text, width], options) => (width > 0 ? width / (fontWidthRatio * text.length) : options.runtime.drawingFontSizePx),
403
403
 
404
404
  // $function: drawTextStyle
@@ -423,7 +423,7 @@ export const markdownScriptFunctions = {
423
423
  // $doc: Compute the text's width
424
424
  // $arg text: The text
425
425
  // $arg fontSizePx: The text font size, in pixels
426
- // $return: The text's width
426
+ // $return: The text's width, in pixels
427
427
  'drawTextWidth': ([text, fontSizePx]) => fontWidthRatio * fontSizePx * text.length,
428
428
 
429
429
  // $function: drawVLine
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "2.3.0",
4
+ "version": "2.3.1",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "c8": "~8.0",
33
- "eslint": "~8.48",
33
+ "eslint": "~8.50",
34
34
  "jsdoc": "~4.0",
35
35
  "jsdom": "~22.1"
36
36
  }