feat: add copy markdowm/text button for docs pages#1521
feat: add copy markdowm/text button for docs pages#1521solarhell wants to merge 12 commits intocloudwego:mainfrom
Conversation
Add a split button with dropdown to copy page content as Markdown or plain text, useful for pasting into LLMs. Supports i18n (zh/en).
✅ Deploy Preview for cloudwego ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- Replace rendered mermaid SVGs with [diagram] placeholder - Replace images with [image: alt] or remove if no alt text - Prevents gibberish SVG text nodes from polluting plain text output
The copy-to-llm partial was only included in _default/content.html, but most docs pages use layouts/docs/list.html, so the button never rendered.
Hugo's jsonify double-encodes .RawContent, causing JSON.parse to return a string instead of an object. Fix by placing markdown in a separate text/plain script tag and reading it directly from the DOM.
Replace the JSON script tag with data-* attributes on the container element, eliminating JSON parse/stringify overhead entirely.
Show a toast above the button with format-specific message (e.g. "已复制 Markdown 格式") and swap the copy icon to a checkmark, similar to volcengine docs.
|
什么场景下需要复制全文? |
不方便 web-fetch 的情况,手动复制了粘贴过去给 LLM(ClaudeCode、Codex)。 |
|
把这个仓库或者eino目录喂给 LLM 不是更直接吗?@solarhell |
直接喂仓库/目录确实是一种方式,但有几个场景下「复制全文」按钮更实用:
|
|
table, "", // 拷贝出来 md 格式一堆乱码 |
|
button 和 dropdown 参考下 bootstrap 本身的写法,https://getbootstrap.com/docs/4.0/components/dropdowns/ |
关于 HTML table 复制为 Markdown 的分析@GuangmingLuo 感谢反馈!我统计了一下 总览
各项目分布
结论
方案讨论针对 EINO 的 table 问题,有两个方向:
大家觉得有必要加这个转换吗?还是说可以接受 HTML table 原样复制? |
- Replace custom dropdown with Bootstrap btn-group + dropdown-toggle-split - Remove manual open/close JS logic, leverage Bootstrap's built-in dropdown - Simplify SCSS from ~120 lines to ~30 lines by reusing Bootstrap styles
|
@rogerogers 感谢建议!已重构为 Bootstrap 4 的 split button dropdown 写法(commit 1168316):
|
|
https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand execCommand 看着已经完全弃用了,感觉没必要作为 fallback |
Use navigator.clipboard.writeText directly as execCommand is fully deprecated. Removes the fallback textarea + execCommand approach.
|
@rogerogers 已移除 |
| } | ||
| }); | ||
|
|
||
| return clone.textContent.replace(/\n{3,}/g, '\n\n').trim(); |
There was a problem hiding this comment.
| return clone.textContent.replace(/\n{3,}/g, '\n\n').trim(); | |
| return clone.textContent.replace(/(\s*\n){3,}/g, '\n\n').trim(); |
好点。比如 section类型 的页面,复制会有有大量空格
| </div> | ||
|
|
||
| {{/* Embed raw markdown for copy-as-markdown */}} | ||
| <script id="copy-fulltext-markdown" type="text/plain">{{ .RawContent }}</script> |
There was a problem hiding this comment.
| <script id="copy-fulltext-markdown" type="text/plain">{{ .RawContent }}</script> | |
| <script id="copy-fulltext-markdown" type="text/plain">{{ .RawContent | safeHTML }}</script> |
safeHTML 会好点,有标签的页面复制出来会有很多符号



Summary
Changes
layouts/partials/copy-to-llm.html— button component templateassets/js/copy-to-llm.js— copy logic (Clipboard API + fallback)assets/scss/_copy-to-llm.scss— button and dropdown styleslayouts/_default/content.html— include the button partiallayouts/partials/scripts.html— add JS to bundleassets/scss/main.scss— import new SCSSi18n/zh.toml/i18n/en.toml— add translation keysTest plan