tellegram 1.1.10 → 1.1.11
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 +5 -5
- package/lib/table-to-list.mjs +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,9 +119,9 @@ convert(markdown, 'remove');
|
|
|
119
119
|
### Convert tables to list
|
|
120
120
|
|
|
121
121
|
Telegram does not support Markdown tables. By default, teLLegraM converts a
|
|
122
|
-
table into a vertical hierarchical list
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
table into a vertical hierarchical list using one numbered title line per row
|
|
123
|
+
plus `-` lines for the remaining fields. Number markers and `-` markers are
|
|
124
|
+
escaped to stay safe for Telegram MarkdownV2.
|
|
125
125
|
|
|
126
126
|
```js
|
|
127
127
|
import { convert } from 'tellegram';
|
|
@@ -135,11 +135,11 @@ const markdown = `
|
|
|
135
135
|
|
|
136
136
|
convert(markdown, 'escape');
|
|
137
137
|
/*
|
|
138
|
-
|
|
138
|
+
1\. Name: Alice
|
|
139
139
|
\- Role: Admin
|
|
140
140
|
\- Score: 95
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
2\. Name: Bob
|
|
143
143
|
\- Role: User
|
|
144
144
|
\- Score: 88
|
|
145
145
|
*/
|
package/lib/table-to-list.mjs
CHANGED
|
@@ -24,12 +24,12 @@ const normalizeValue = (cell, context) => {
|
|
|
24
24
|
return value || EMPTY_VALUE;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const pairToLine = (pair, isNested) => {
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
27
|
+
const pairToLine = (pair, rowIndex, isNested) => {
|
|
28
|
+
if (isNested) {
|
|
29
|
+
return `\\- ${pair.header}: ${pair.value}`;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
return
|
|
32
|
+
return `${rowIndex + 1}\\. ${pair.header}: ${pair.value}`;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export default (node, context) => {
|
|
@@ -55,13 +55,13 @@ export default (node, context) => {
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
if (!pairs.length) {
|
|
58
|
-
return
|
|
58
|
+
return `${rowIndex + 1}\\. Item ${rowIndex + 1}: ${EMPTY_VALUE}`;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const [first, ...rest] = pairs;
|
|
62
62
|
return [
|
|
63
|
-
pairToLine(first, false),
|
|
64
|
-
...rest.map(pair => pairToLine(pair, true)),
|
|
63
|
+
pairToLine(first, rowIndex, false),
|
|
64
|
+
...rest.map(pair => pairToLine(pair, rowIndex, true)),
|
|
65
65
|
].join('\n');
|
|
66
66
|
});
|
|
67
67
|
|