DSH Markdown Copy: Copy selected session content as editable Markdown source code

Introduction

DSH messages are rendered using Markdown. On the screen, you see headings, lists, code blocks, tables, and formulas, but once you select and copy them with the mouse, the clipboard usually contains only the rendered plain text. When pasted into an editor or notes, the structure is lost, the code blocks disappear, and manual fixes are required later. Another approach is the built-in copy button per message, but it only copies the whole message, making it impossible to extract just a section.

The drinkerqvb/dsh-markdown-copy introduced below bridges this gap: it reads the selection during the browser’s copy event and writes the Markdown source code into the clipboard.

What is this

drinkerqvb/dsh-markdown-copy is maintained by DrinkerqvB and is a client-side (Web platform) plugin. It solves a very specific problem: when you select a segment of chat content and press Ctrl+C (or choose “Copy” from the context menu), the result should be editable Markdown source code, not rendered plain text.

It does not alter DSH’s rendering logic; it only intervenes in the browser’s copy event (during the capture phase): it checks if the selection falls entirely within the chat flow [data-chat-flow]. If so, it traverses the selected DOM fragment to regenerate Markdown and overwrites text/plain. The content pasted into an editor or notes will be editable Markdown.

Core Features

The plugin’s behavioral boundaries are clearly defined in the README:

  • Only handles copies where the selection falls entirely within the chat flow [data-chat-flow].
  • Copies from input boxes, multiline editors, and editable areas are not affected.
  • The selection can span multiple messages, and the output is ordered by document sequence.
  • The built-in “Copy” button remains unchanged, as DSH’s native buttons already output Markdown source code.
  • When the selection falls inside a table or code block, it expands to the entire table / entire code block to ensure structural integrity.
  • When the selection falls inside inline elements (bold, italic, inline code, links, formulas, headings, blockquotes, list items), it restores corresponding markers from the ancestor chain, outputting only the selected text.

The conversion rules are determined by DOM node types, and a comparison table is provided in the README:

DOM Generated Markdown
h1–h6 # … ######
p, block-level containers Paragraphs, separated by a blank line
ul / ol / nested lists - / 1., nested indentation of 2 spaces, task lists output [x] / [ ]
blockquote Add > to each line
pre / .md-code-block Fenced code blocks, language taken from the language tag of the code block banner
table GFM table, outputs alignment rows based on cell alignment
strong / em / del ** / * / ~~
code Backticks, adaptive fence length based on content
a / img [text](href) / ![alt](src)
.katex / .katex-display $…$ / $$…$$, TeX taken from KaTeX’s application/x-tex annotation
hr / br --- / \ line break
[data-clock] operation rows, code block banners Skip

Escaping and “Render Equivalence”

Body text is escaped character by character (*, backticks, [, ], <, paired $, leading block syntax, &entity;, etc., depending on context) to ensure the result of re-rendering after pasting matches the selected content on the screen. Code fences, inline code, formulas, and link targets belong to their respective syntaxes and are not escaped.

This contract is render equivalence, not byte-for-byte restoration. Source syntax consumed during the rendering phase (e.g., \# vs #, * vs - list markers) cannot be distinguished in the DOM, and any implementation cannot restore it. When byte-for-byte consistency with the model’s original text is required, use the built-in copy button per message, which is the reason it is kept unchanged in the README.

Installation and Activation

Execute the official installation command in DSH:

dsh plugin add https://github.com/DrinkerqvB/dsh-markdown-copy

After installing on the desktop client, refresh the session page to take effect; no restart is needed. The current version is 0.1.1 with an MIT license.

Typical Usage

No extra configuration is needed after installation; you can operate directly in the session page. The following workflow can be reproduced:

  1. Select a segment of content within the chat flow [data-chat-flow] using the mouse, for example, a list from several messages plus a code block.
  2. Press Ctrl+C (or “Copy” from the right-click menu).
  3. Paste the clipboard content into an editor and check if the headings, list indentation, code fences, and language tags are restored to editable Markdown source code.

When the selection falls on part of a table or code block, the entire component is output; to get just a specific cell, you need to select that part of the inline text directly or use the message’s built-in copy button to get the original text.

Use Cases and Notes

Suitable for developers who need to extract snippets from DSH sessions to organize into notes or documents. The plugin runs with the permissions of the current DSH process; you should check the source code and license (MIT) before installing.

There are several known limitations to note:

  • Byte-for-byte restoration is not feasible; see the previous section.
  • When selecting part of a table or code block, the entire component is output, resulting in content more than what was selected.
  • Original HTML tags in the model’s source text are not rendered in DSH and will not appear in the output.

Conclusion

drinkerqvb/dsh-markdown-copy fills the gap of “select to copy Markdown”: it does not modify rendering, does not interfere with input boxes, and does not disrupt the built-in copy button. It only restores the DOM to source code when the selection falls within the chat flow. The directory page is at https://www.skillhub.cn/plugins/DrinkerqvB/dsh-markdown-copy, and the source code is at https://github.com/DrinkerqvB/dsh-markdown-copy.

When you need to modify conversion rules or debug, you can refer to the development section in the repository: src/copy-markdown.js is a pure function script, node build.mjs generates client.js from it, tests are loaded directly into jsdom, and node build.mjs needs to be run again before submitting.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye