@meistrari/tela-skills 1.6.0 → 1.6.2
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/package.json +1 -1
- package/skill/canvas.test.ts +38 -0
- package/skill/canvas.ts +26 -5
package/package.json
CHANGED
package/skill/canvas.test.ts
CHANGED
|
@@ -146,4 +146,42 @@ describe('canvas', () => {
|
|
|
146
146
|
expect(body.message).toEqual({ role: 'system', content: 'Current', markdownContent: 'Current', index: 0 })
|
|
147
147
|
expect('messages' in body).toBe(false)
|
|
148
148
|
})
|
|
149
|
+
|
|
150
|
+
test('preserves underscores in variable names when converting markdown to HTML', async () => {
|
|
151
|
+
const { markdownToHtml } = await import('./canvas.ts')
|
|
152
|
+
const markdown = [
|
|
153
|
+
'- Texto da publicação: {texto_publicacao}',
|
|
154
|
+
'- Fase do processo: {fase_processo}',
|
|
155
|
+
'- Garantia judicial: {garantia_judicial}',
|
|
156
|
+
'- Órgão legal: {orgao_legal}',
|
|
157
|
+
].join('\n')
|
|
158
|
+
|
|
159
|
+
const html = markdownToHtml(markdown)
|
|
160
|
+
|
|
161
|
+
expect(html).toContain('<variable class="variable" data-variable="texto_publicacao">texto_publicacao</variable>')
|
|
162
|
+
expect(html).toContain('<variable class="variable" data-variable="fase_processo">fase_processo</variable>')
|
|
163
|
+
expect(html).toContain('<variable class="variable" data-variable="garantia_judicial">garantia_judicial</variable>')
|
|
164
|
+
expect(html).toContain('<variable class="variable" data-variable="orgao_legal">orgao_legal</variable>')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('does not replace literal sentinel-like text when restoring variables', async () => {
|
|
168
|
+
const { markdownToHtml } = await import('./canvas.ts')
|
|
169
|
+
const markdown = 'Literal sentinel: %%TELAVAR0%% {texto_publicacao}'
|
|
170
|
+
|
|
171
|
+
const html = markdownToHtml(markdown)
|
|
172
|
+
|
|
173
|
+
expect(html).toContain('Literal sentinel: %%TELAVAR0%% ')
|
|
174
|
+
expect(html).toContain('<variable class="variable" data-variable="texto_publicacao">texto_publicacao</variable>')
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('renders markdown separator lines as horizontal rules', async () => {
|
|
178
|
+
const { markdownToHtml } = await import('./canvas.ts')
|
|
179
|
+
|
|
180
|
+
for (const separator of ['---', '***', '___']) {
|
|
181
|
+
const html = markdownToHtml(`# Contexto\n\n${separator}\n\n# Etapas`)
|
|
182
|
+
|
|
183
|
+
expect(html).toContain('<hr>')
|
|
184
|
+
expect(html).not.toContain(`<p>${separator}</p>`)
|
|
185
|
+
}
|
|
186
|
+
})
|
|
149
187
|
})
|
package/skill/canvas.ts
CHANGED
|
@@ -436,6 +436,15 @@ export function markdownToHtml(markdown: string): string {
|
|
|
436
436
|
htmlParts.push(`<h1>${trimmed.slice(2)}</h1>`)
|
|
437
437
|
isFirst = false
|
|
438
438
|
}
|
|
439
|
+
// Horizontal rule
|
|
440
|
+
else if (/^(?:-{3,}|\*{3,}|_{3,})$/.test(trimmed)) {
|
|
441
|
+
if (inList) {
|
|
442
|
+
htmlParts.push('</ul>')
|
|
443
|
+
inList = false
|
|
444
|
+
}
|
|
445
|
+
htmlParts.push('<hr>')
|
|
446
|
+
isFirst = false
|
|
447
|
+
}
|
|
439
448
|
// Bullet list
|
|
440
449
|
else if (trimmed.startsWith('- ')) {
|
|
441
450
|
if (!inList) {
|
|
@@ -467,16 +476,28 @@ export function markdownToHtml(markdown: string): string {
|
|
|
467
476
|
htmlParts.push('</ul>')
|
|
468
477
|
|
|
469
478
|
let html = htmlParts.join('')
|
|
479
|
+
const variableTags: string[] = []
|
|
480
|
+
let markerId = 0
|
|
481
|
+
let markerPrefix = `\0TELAVAR${markerId}:`
|
|
482
|
+
|
|
483
|
+
// Pick a per-call marker that cannot collide with literal user content.
|
|
484
|
+
while (html.includes(markerPrefix)) {
|
|
485
|
+
markerId += 1
|
|
486
|
+
markerPrefix = `\0TELAVAR${markerId}:`
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
html = html.replace(/\{([^}]+)\}/g, (_match, variableName: string) => {
|
|
490
|
+
const index = variableTags.push(`<variable class="variable" data-variable="${variableName}">${variableName}</variable>`) - 1
|
|
491
|
+
return `${markerPrefix}${index}:\0`
|
|
492
|
+
})
|
|
470
493
|
|
|
471
494
|
// Convert **bold** and _italic_
|
|
472
495
|
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
|
|
473
496
|
html = html.replace(/_(.+?)_/g, '<em>$1</em>')
|
|
474
497
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
'<variable class="variable" data-variable="$1">$1</variable>',
|
|
479
|
-
)
|
|
498
|
+
variableTags.forEach((tag, index) => {
|
|
499
|
+
html = html.split(`${markerPrefix}${index}:\0`).join(tag)
|
|
500
|
+
})
|
|
480
501
|
|
|
481
502
|
return html
|
|
482
503
|
}
|