teledzik 1.0.9 → 1.1.3

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.
@@ -19,14 +19,21 @@ function formatTableToCard(tableHtml) {
19
19
  }
20
20
  if (rows.length === 0)
21
21
  return '';
22
- // Header vs Row handling (Format sebagai Kartu Elegan)
22
+ // Header vs Row handling (Format sebagai Kartu Elegan Terstruktur)
23
23
  const isKeyValue = rows.length > 0 && rows.every((r) => r.length === 2);
24
24
  let cardText = '';
25
25
  if (isKeyValue) {
26
- const isHeaderRow = hasHeader && rows.length > 1 && (/^(parameter|informasi|metrik|field|key|unit|format|statistik|opsi|nama|item)$/i.test(rows[0][0].replace(/<[^>]*>/g, '').trim()) ||
26
+ const isHeaderRow = hasHeader && rows.length > 1 && (/^(parameter|informasi|metrik|field|key|unit|format|statistik|opsi|nama|item|rincian)$/i.test(rows[0][0].replace(/<[^>]*>/g, '').trim()) ||
27
27
  /^(status|keterangan|detail|nilai|value|jumlah|estimasi|tipe|contoh input)$/i.test(rows[0][1].replace(/<[^>]*>/g, '').trim()));
28
28
  const dataRows = isHeaderRow ? rows.slice(1) : rows;
29
- const lines = dataRows.map((r) => `• <b>${r[0]}:</b> ${r[1]}`);
29
+ const cleanKey = (str) => str.replace(/<[^>]*>/g, '').trim();
30
+ const maxLen = Math.max(...dataRows.map(r => cleanKey(r[0]).length), 0);
31
+ const targetLen = Math.min(Math.max(maxLen, 6), 16);
32
+ const lines = dataRows.map((r) => {
33
+ const raw = cleanKey(r[0]);
34
+ const pad = ' '.repeat(Math.max(0, targetLen - raw.length));
35
+ return `<code>${raw}${pad} :</code> ${r[1]}`;
36
+ });
30
37
  cardText = `<blockquote>\n${lines.join('\n')}\n</blockquote>\n\n`;
31
38
  }
32
39
  else {
@@ -74,7 +81,7 @@ function sanitizeRichHtml(html) {
74
81
  result = result.replace(/<tg-math-block[^>]*>([\s\S]*?)<\/tg-math-block>/gi, (_, c) => `<pre><code>${c.trim()}</code></pre>\n\n`);
75
82
  result = result.replace(/<tg-reference[^>]*>([\s\S]*?)<\/tg-reference>/gi, (_, c) => `<i>${c.trim()}</i>`);
76
83
  result = result.replace(/<mark[^>]*>([\s\S]*?)<\/mark>/gi, (_, c) => `<b>[${c.trim()}]</b>`);
77
- result = result.replace(/<figure[^>]*>[\s\S]*?<figcaption[^>]*>([\s\S]*?)<\/figcaption><\/figure>/gi, (_, cap) => `\n<i>📷 ${cap.trim()}</i>\n`);
84
+ result = result.replace(/<figure[^>]*>([\s\S]*?)<figcaption[^>]*>([\s\S]*?)<\/figcaption><\/figure>/gi, (_, body, cap) => `${body}\n<i>📷 ${cap.trim()}</i>\n`);
78
85
  result = result.replace(/<p[^>]*>([\s\S]*?)<\/p>/gi, (_, c) => `${c.trim()}\n\n`);
79
86
  result = result.replace(/<footer[^>]*>([\s\S]*?)<\/footer>/gi, (_, c) => `<i>${c.trim()}</i>\n`);
80
87
  result = result.replace(/<br\s*\/?>/gi, '\n');
@@ -83,7 +90,8 @@ function sanitizeRichHtml(html) {
83
90
  result = result.replace(/<sub[^>]*>([\s\S]*?)<\/sub>/gi, '$1');
84
91
  result = result.replace(/<sup[^>]*>([\s\S]*?)<\/sup>/gi, '$1');
85
92
  result = result.replace(/<tg-(map|collage|slideshow)[^>]*>([\s\S]*?)<\/tg-\1>/gi, '$2');
86
- result = result.replace(/<(img|video|audio|tg-map)[^>]*\/?>/gi, '');
93
+ result = result.replace(/<img[^>]*src="([^"]+)"[^>]*\/?>/gi, '<a href="$1">&#8205;</a>');
94
+ result = result.replace(/<(video|audio|tg-map)[^>]*\/?>/gi, '');
87
95
  return result.replace(/\n{3,}/g, '\n\n').trim();
88
96
  }
89
97
  exports.sanitizeRichHtml = sanitizeRichHtml;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teledzik",
3
- "version": "1.0.9",
3
+ "version": "1.1.3",
4
4
  "description": "Modern Telegram Bot Framework",
5
5
  "keywords": [
6
6
  "telekaf",
@@ -14,16 +14,24 @@ function formatTableToCard(tableHtml: string): string {
14
14
  }
15
15
  if (rows.length === 0) return ''
16
16
 
17
- // Header vs Row handling (Format sebagai Kartu Elegan)
17
+ // Header vs Row handling (Format sebagai Kartu Elegan Terstruktur)
18
18
  const isKeyValue = rows.length > 0 && rows.every((r) => r.length === 2);
19
19
  let cardText = '';
20
20
  if (isKeyValue) {
21
21
  const isHeaderRow = hasHeader && rows.length > 1 && (
22
- /^(parameter|informasi|metrik|field|key|unit|format|statistik|opsi|nama|item)$/i.test(rows[0][0].replace(/<[^>]*>/g, '').trim()) ||
22
+ /^(parameter|informasi|metrik|field|key|unit|format|statistik|opsi|nama|item|rincian)$/i.test(rows[0][0].replace(/<[^>]*>/g, '').trim()) ||
23
23
  /^(status|keterangan|detail|nilai|value|jumlah|estimasi|tipe|contoh input)$/i.test(rows[0][1].replace(/<[^>]*>/g, '').trim())
24
24
  );
25
25
  const dataRows = isHeaderRow ? rows.slice(1) : rows;
26
- const lines = dataRows.map((r) => `• <b>${r[0]}:</b> ${r[1]}`);
26
+ const cleanKey = (str: string) => str.replace(/<[^>]*>/g, '').trim();
27
+ const maxLen = Math.max(...dataRows.map(r => cleanKey(r[0]).length), 0);
28
+ const targetLen = Math.min(Math.max(maxLen, 6), 16);
29
+
30
+ const lines = dataRows.map((r) => {
31
+ const raw = cleanKey(r[0]);
32
+ const pad = ' '.repeat(Math.max(0, targetLen - raw.length));
33
+ return `<code>${raw}${pad} :</code> ${r[1]}`;
34
+ });
27
35
  cardText = `<blockquote>\n${lines.join('\n')}\n</blockquote>\n\n`;
28
36
  } else {
29
37
  const lines = rows.map((r, idx) => {
@@ -81,7 +89,7 @@ export function sanitizeRichHtml(html: string): string {
81
89
  result = result.replace(/<tg-reference[^>]*>([\s\S]*?)<\/tg-reference>/gi, (_, c) => `<i>${c.trim()}</i>`)
82
90
  result = result.replace(/<mark[^>]*>([\s\S]*?)<\/mark>/gi, (_, c) => `<b>[${c.trim()}]</b>`)
83
91
 
84
- result = result.replace(/<figure[^>]*>[\s\S]*?<figcaption[^>]*>([\s\S]*?)<\/figcaption><\/figure>/gi, (_, cap) => `\n<i>📷 ${cap.trim()}</i>\n`)
92
+ result = result.replace(/<figure[^>]*>([\s\S]*?)<figcaption[^>]*>([\s\S]*?)<\/figcaption><\/figure>/gi, (_, body, cap) => `${body}\n<i>📷 ${cap.trim()}</i>\n`)
85
93
 
86
94
  result = result.replace(/<p[^>]*>([\s\S]*?)<\/p>/gi, (_, c) => `${c.trim()}\n\n`)
87
95
  result = result.replace(/<footer[^>]*>([\s\S]*?)<\/footer>/gi, (_, c) => `<i>${c.trim()}</i>\n`)
@@ -92,7 +100,8 @@ export function sanitizeRichHtml(html: string): string {
92
100
  result = result.replace(/<sub[^>]*>([\s\S]*?)<\/sub>/gi, '$1')
93
101
  result = result.replace(/<sup[^>]*>([\s\S]*?)<\/sup>/gi, '$1')
94
102
  result = result.replace(/<tg-(map|collage|slideshow)[^>]*>([\s\S]*?)<\/tg-\1>/gi, '$2')
95
- result = result.replace(/<(img|video|audio|tg-map)[^>]*\/?>/gi, '')
103
+ result = result.replace(/<img[^>]*src="([^"]+)"[^>]*\/?>/gi, '<a href="$1">&#8205;</a>')
104
+ result = result.replace(/<(video|audio|tg-map)[^>]*\/?>/gi, '')
96
105
 
97
106
  return result.replace(/\n{3,}/g, '\n\n').trim()
98
107
  }