Merge 382a20cf19 into fa9ec6e854
This commit is contained in:
commit
7379de5ac1
@ -93,13 +93,8 @@ export function renderMarkdownWithMarkers(ir: MarkdownIR, options: RenderOptions
|
|||||||
for (let i = 0; i < points.length; i += 1) {
|
for (let i = 0; i < points.length; i += 1) {
|
||||||
const pos = points[i];
|
const pos = points[i];
|
||||||
|
|
||||||
while (stack.length && stack[stack.length - 1]?.end === pos) {
|
// Close links before styles to maintain proper nesting order
|
||||||
const span = stack.pop();
|
// (links are typically nested inside styles like bold/italic)
|
||||||
if (!span) break;
|
|
||||||
const marker = styleMarkers[span.style];
|
|
||||||
if (marker) out += marker.close;
|
|
||||||
}
|
|
||||||
|
|
||||||
const closingLinks = linkEnds.get(pos);
|
const closingLinks = linkEnds.get(pos);
|
||||||
if (closingLinks && closingLinks.length > 0) {
|
if (closingLinks && closingLinks.length > 0) {
|
||||||
for (const link of closingLinks) {
|
for (const link of closingLinks) {
|
||||||
@ -107,6 +102,13 @@ export function renderMarkdownWithMarkers(ir: MarkdownIR, options: RenderOptions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (stack.length && stack[stack.length - 1]?.end === pos) {
|
||||||
|
const span = stack.pop();
|
||||||
|
if (!span) break;
|
||||||
|
const marker = styleMarkers[span.style];
|
||||||
|
if (marker) out += marker.close;
|
||||||
|
}
|
||||||
|
|
||||||
const openingLinks = linkStarts.get(pos);
|
const openingLinks = linkStarts.get(pos);
|
||||||
if (openingLinks && openingLinks.length > 0) {
|
if (openingLinks && openingLinks.length > 0) {
|
||||||
for (const link of openingLinks) {
|
for (const link of openingLinks) {
|
||||||
|
|||||||
@ -47,4 +47,19 @@ describe("markdownToTelegramHtml", () => {
|
|||||||
const res = markdownToTelegramHtml("```js\nconst x = 1;\n```");
|
const res = markdownToTelegramHtml("```js\nconst x = 1;\n```");
|
||||||
expect(res).toBe("<pre><code>const x = 1;\n</code></pre>");
|
expect(res).toBe("<pre><code>const x = 1;\n</code></pre>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("properly nests link tags inside bold when URL is at end of bold span", () => {
|
||||||
|
const res = markdownToTelegramHtml("**Check https://example.com**");
|
||||||
|
expect(res).toBe('<b>Check <a href="https://example.com">https://example.com</a></b>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("properly nests link tags inside italic", () => {
|
||||||
|
const res = markdownToTelegramHtml("_visit https://docs.molt.bot_");
|
||||||
|
expect(res).toBe('<i>visit <a href="https://docs.molt.bot">https://docs.molt.bot</a></i>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders emoji before bold correctly", () => {
|
||||||
|
const res = markdownToTelegramHtml("🧪 **Header text**");
|
||||||
|
expect(res).toBe("🧪 <b>Header text</b>");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user