Skip to content

fix: include image links as markdown when copying solution/problem content#955

Open
Copilot wants to merge 10 commits intodevfrom
copilot/add-image-links-to-issue-copies
Open

fix: include image links as markdown when copying solution/problem content#955
Copilot wants to merge 10 commits intodevfrom
copilot/add-image-links-to-issue-copies

Conversation

Copy link
Contributor

Copilot AI commented Mar 22, 2026

Copying 题解/题目 content silently dropped embedded images because .innerText strips all HTML nodes including <img> tags.

Changes

  • Add GetMDText(element) helper — recursively walks DOM nodes, emitting text content as-is and converting <img src="..."> to ![](resolvedUrl) markdown. Images without a src are skipped. Relative URLs are resolved via new URL(src, location.href).
  • /problem_solution.php copy handler — replace .innerText with GetMDText() so images appear in the copied markdown.
  • /problem.php copy handler — same fix for problem description sections.
// Before
GM_setClipboard(element.innerText.trim()...);
// images silently dropped

// After
GM_setClipboard(GetMDText(element).trim()...);
// images preserved as ![](https://example.com/image.png)
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] 复制题解应包括图片链接</issue_title>
<issue_description>### 检查项

  • 我已确认了XMOJ增强脚本已为最新版,且最新版未修复这个 Bug 。
  • 我已在 Issues 页面 中搜索,确认了这一 Bug 未被提交过。

描述

rt

重现步骤

No response

控制台错误信息

No response</issue_description>

<agent_instructions>复制题解的时候图片也用markdown包裹(按照用户侧加载的图片link为来源</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@PythonSmall-Q okay @PythonSmall-Q 举个例子,没看懂 @boomzero

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.


Summary by cubic

Copying solution and problem content now preserves images by converting tags to Markdown image links with absolute URLs and keeps basic formatting like line breaks. Fixes #448.

  • Bug Fixes

    • Replace innerText-based copy with a recursive DOM walker so images aren’t dropped and line breaks/block spacing are preserved.
    • Convert img src to ; resolve relative URLs, skip missing src, and fall back to raw src if URL parsing fails.
  • Dependencies

    • Bump package.json to 3.3.6 (prerelease).
    • Update Update.json 3.3.6 feed entry (time and description).

Written for commit 7f71fa1. Summary will update on new commits.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 22, 2026

Deploying xmoj-script-dev-channel with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7f71fa1
Status: ✅  Deploy successful!
Preview URL: https://406e6368.xmoj-script-dev-channel.pages.dev
Branch Preview URL: https://copilot-add-image-links-to-i.xmoj-script-dev-channel.pages.dev

View logs

Copilot AI changed the title [WIP] Fix issue where copied solutions do not include image links fix: include image links as markdown when copying solution/problem content Mar 22, 2026
Copilot AI requested a review from PythonSmall-Q March 22, 2026 09:10
@PythonSmall-Q PythonSmall-Q marked this pull request as ready for review March 22, 2026 09:38
Copilot AI review requested due to automatic review settings March 22, 2026 09:38
@PythonSmall-Q PythonSmall-Q enabled auto-merge March 22, 2026 09:39
@hendragon-bot hendragon-bot bot added the user-script This issue or pull request is related to the main user script label Mar 22, 2026
@github-actions github-actions bot force-pushed the copilot/add-image-links-to-issue-copies branch from 7965914 to ead676a Compare March 22, 2026 09:39
PythonSmall-Q and others added 2 commits March 22, 2026 17:40
Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes markdown copy behavior in XMOJ userscript so embedded images are preserved (instead of being dropped by .innerText) when copying problem statements and solutions.

Changes:

  • Add GetMDText(element) helper to traverse DOM nodes and convert <img src="..."> into Markdown image syntax with absolute URLs.
  • Update /problem.php “CopyMD” handler to use GetMDText() instead of .innerText.
  • Update /problem_solution.php “CopyMD” handler to use GetMDText() instead of .innerText.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="XMOJ.user.js">

<violation number="1" location="XMOJ.user.js:1052">
P2: `GetMDText` drops block/line-break structure, so copied content can be flattened into one line. Preserve newlines for `<br>` and block elements when traversing nodes.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

PythonSmall-Q and others added 2 commits March 22, 2026 17:42
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
PythonSmall-Q and others added 2 commits March 22, 2026 17:43
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
@PythonSmall-Q PythonSmall-Q linked an issue Mar 22, 2026 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M user-script This issue or pull request is related to the main user script

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 复制题解应包括图片链接

3 participants