fix(app): keep a partial callout selection free of its marker

A selection that started inside an admonition's body kept the box as
its wrapper, so the copy added `> [!TYPE]` the user never selected. The
callout marker is now restored only when the copied markup includes the
generated title, which a whole callout or quote copy always does.

Co-authored-by: Pedro Vieira <pedro.vieira@dremio.com>
Co-authored-by: Phieu Dinh <phieu@fiu.one>
This commit is contained in:
Mohamed Boudra
2026-11-23 16:14:59 +01:00
co-authored by Pedro Vieira Phieu Dinh
parent 5b82167872
commit 47bcf6e609
2 changed files with 19 additions and 1 deletions
@@ -1087,6 +1087,21 @@ describe("quote copy", () => {
expect(content?.plainText).toBe("Before\n\n> [!WARNING]\n> Do not deploy.\n\nAfter");
});
it("copies a selection that starts inside an admonition without its callout marker", async () => {
const rendered = await renderMarkdown(
"> Before\n>\n> > [!WARNING]\n> > Do not deploy.\n>\n> After",
"After",
);
rendered.setAttribute("data-testid", "assistant-message");
const content = copyBetween(
[tokenText(rendered, "Do not deploy."), "Do not ".length],
[tokenText(rendered, "After"), "After".length],
);
expect(content?.plainText).toBe("deploy.\n\nAfter");
});
it("copies a rendered Mermaid diagram as its fence", () => {
const quote = document.createElement("blockquote");
quote.innerHTML = `<p>Before</p><div ${MARKDOWN_COPY_FENCE_SOURCE_ATTRIBUTE}="graph TD; A-->B" data-paseo-markdown-language="mermaid"><svg aria-label="diagram"></svg></div><p>After</p>`;
@@ -757,13 +757,16 @@ function numberOrderedListItems(list: Element, start: number): void {
/**
* The library renders an admonition as a box with a generated title. Keep it a quote
* with its type, so it copies as its callout source rather than as the title's prose.
* A selection that starts inside the body has no title and copies as prose.
*/
function restoreAdmonitions(container: HTMLElement): void {
const admonitions = Array.from(
container.querySelectorAll(`[${MARKDOWN_ADMONITION_TYPE_ATTRIBUTE}]`),
);
for (const admonition of admonitions.toReversed()) {
admonition.querySelector(`:scope > [${MARKDOWN_ADMONITION_TITLE_ATTRIBUTE}]`)?.remove();
const title = admonition.querySelector(`:scope > [${MARKDOWN_ADMONITION_TITLE_ATTRIBUTE}]`);
if (!title) continue;
title.remove();
const quote = document.createElement("blockquote");
quote.setAttribute(
MARKDOWN_ADMONITION_TYPE_ATTRIBUTE,