mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-25 01:35:31 +00:00
fix(app): keep copied quote fences and diagrams faithful
Native fences were always three characters long, so a copied code block holding a Markdown example closed at its inner fence. The fence now outgrows the longest run of its character in the code. Code block copy uses the same writer and gets the same fix. Web quote copy read the diagram's incoming source while the preview still showed the previous streamed revision. It now copies the revision on screen. Co-authored-by: Pedro Vieira <pedro.vieira@dremio.com> Co-authored-by: Phieu Dinh <phieu@fiu.one>
This commit is contained in:
co-authored by
Pedro Vieira
Phieu Dinh
parent
40c5accf2a
commit
8a892ed4a7
@@ -45,7 +45,7 @@ Mermaid fences use the existing isolated diagram runtime and fullscreen viewer.
|
||||
|
||||
Code blocks and plain quotes have a copy control in their top trailing corner. Native code blocks use the library's compiled grammars. On native, the code block and quote container views share one control (`HeaderCopyButton` on Android, `ENRMHeaderCopyButton` on iOS). A quote reserves the code block's header band above its body, so the control never covers quote text at any font size. On web, code blocks use `HighlightedCodeBlock` through the library's `renderers.codeBlock` override, and quotes use `WebBlockquote` through `renderers.blockquote`. Both use `BlockCopyButton`. On compact layouts the control is always visible, so the web quote reserves a band above its body, as native does. On wide layouts the control appears on hover or focus, so the quote keeps a right gutter instead; a band there would leave an empty strip above every quote.
|
||||
|
||||
A quote copies its body without the `>` markers, with its nested Markdown, and reads the content at the time of the press, so a streaming quote copies what it shows. A nested quote or code block keeps its own control. Web quote copy uses the same two clipboard flavors as selection copy: `text/plain` is unescaped Markdown and `text/html` is rendered from escaped Markdown. A rendered Mermaid diagram copies as its fence because its wrapper carries the fence source. Native quote copy emits the Markdown as written. Admonitions get no control: web renders them with a separate library renderer. Quotes inside list items get no control either, because they render as text spans in the item.
|
||||
A quote copies its body without the `>` markers, with its nested Markdown, and reads the content at the time of the press, so a streaming quote copies what it shows. A nested quote or code block keeps its own control. Web quote copy uses the same two clipboard flavors as selection copy: `text/plain` is unescaped Markdown and `text/html` is rendered from escaped Markdown. A rendered Mermaid diagram copies as its fence because its wrapper carries the fence source. Native quote copy serializes the quote's parsed Markdown, so a workspace image copies as its cached file URL, as native selection copy does; native has no map back to the workspace path. A native Mermaid diagram in a quote renders outside it (see [native selection limitations](native-text-selection.md)), so each quote fragment copies only its own text. Admonitions get no control: web renders them with a separate library renderer. Quotes inside list items get no control either, because they render as text spans in the item.
|
||||
|
||||
Selection copy has to tell links Paseo recognized in the text (paths, forge references, code spans) from links in the Markdown, so the web link renderer marks the recognized ones. Plain-text paste carries them as the text the reply showed, and rich paste keeps them as links only when they point to an `http` or `https` URL. Authored links and parser autolinks such as a bare `www.example.com` copy as links. The fork also keeps the library's block spacing around the web code block override, preserves web list numbering and link titles, marks pending parses with `aria-busy` so Find waits for rendered text, and carries link syntax through native and web tap events. Web inline code inside a link inherits only the link colour; its code font, size and background stay intact. Keep link variants colour-only: native pills replace text runs and prevent paths from wrapping; Android pills also use the surrounding block’s font size. [Upstream PR #997](https://github.com/software-mansion/enriched-markdown/pull/997) tracks these changes.
|
||||
|
||||
|
||||
@@ -86,13 +86,15 @@ function MermaidFenceHostImpl({
|
||||
);
|
||||
const sourceVisible = !diagramVisible;
|
||||
// A visible diagram stands in for its fence, so copying the surrounding block takes
|
||||
// the source from here. The source view copies as its own code block.
|
||||
const diagramCopyAttributes = diagramVisible
|
||||
? {
|
||||
[MARKDOWN_COPY_FENCE_SOURCE_ATTRIBUTE]: code,
|
||||
[MARKDOWN_COPY_LANGUAGE_ATTRIBUTE]: "mermaid",
|
||||
}
|
||||
: null;
|
||||
// the source from here: the revision on screen, which lags `code` while a streamed
|
||||
// revision renders. The source view copies as its own code block.
|
||||
const diagramCopyAttributes =
|
||||
diagramVisible && visible
|
||||
? {
|
||||
[MARKDOWN_COPY_FENCE_SOURCE_ATTRIBUTE]: visible.source,
|
||||
[MARKDOWN_COPY_LANGUAGE_ATTRIBUTE]: "mermaid",
|
||||
}
|
||||
: null;
|
||||
const viewportStyle = diagramVisible ? diagramStyle : measuringStyle;
|
||||
|
||||
return (
|
||||
|
||||
+4
-1
@@ -42,7 +42,10 @@ object CodeBlockNode {
|
||||
language: String?,
|
||||
fenceChar: String,
|
||||
): String {
|
||||
val fence = fenceChar.repeat(3)
|
||||
// A fence must be longer than any run of its character in the code, or an inner
|
||||
// fence (a Markdown example) closes the block early.
|
||||
val longestRun = Regex("${Regex.escape(fenceChar)}+").findAll(code).maxOfOrNull { it.value.length } ?: 0
|
||||
val fence = fenceChar.repeat(maxOf(3, longestRun + 1))
|
||||
return "$fence${language.orEmpty()}\n$code\n$fence"
|
||||
}
|
||||
|
||||
|
||||
+17
@@ -173,6 +173,23 @@ class BlockquoteCopyTest {
|
||||
assertEquals("Second draft\n\nWith more", clipboardText())
|
||||
}
|
||||
|
||||
@Test fun codeBlockWithAnInnerFenceStaysOneBlock() {
|
||||
val view = quoteView()
|
||||
view.applyBlockquoteNode(
|
||||
quote(
|
||||
node(
|
||||
NodeType.CodeBlock,
|
||||
text("```js\nrun()\n```\n"),
|
||||
attributes = mapOf("language" to "markdown", "fenceChar" to "`"),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
view.copyButton().performClick()
|
||||
|
||||
assertEquals("````markdown\n```js\nrun()\n```\n````", clipboardText())
|
||||
}
|
||||
|
||||
@Test fun nestedQuoteCopiesOnlyItsOwnBody() {
|
||||
val view = quoteView()
|
||||
view.applyBlockquoteNode(quote(paragraph(text("Outer")), quote(paragraph(text("Inner")))))
|
||||
|
||||
@@ -40,7 +40,16 @@ NSString *ENRMCodeBlockFenceChar(MarkdownASTNode *node)
|
||||
|
||||
NSString *ENRMCodeBlockFencedMarkdown(NSString *code, NSString *language, NSString *fenceChar)
|
||||
{
|
||||
NSString *fence = [@"" stringByPaddingToLength:3 withString:fenceChar startingAtIndex:0];
|
||||
// A fence must be longer than any run of its character in the code, or an inner
|
||||
// fence (a Markdown example) closes the block early.
|
||||
unichar fenceUnit = [fenceChar characterAtIndex:0];
|
||||
NSUInteger longestRun = 0;
|
||||
NSUInteger run = 0;
|
||||
for (NSUInteger index = 0; index < code.length; index++) {
|
||||
run = [code characterAtIndex:index] == fenceUnit ? run + 1 : 0;
|
||||
longestRun = MAX(longestRun, run);
|
||||
}
|
||||
NSString *fence = [@"" stringByPaddingToLength:MAX(3, longestRun + 1) withString:fenceChar startingAtIndex:0];
|
||||
return [NSString stringWithFormat:@"%@%@\n%@\n%@", fence, language ?: @"", code, fence];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user