fix: include image links as markdown when copying solution/problem content#955
Open
fix: include image links as markdown when copying solution/problem content#955
Conversation
…ntent Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com> Agent-Logs-Url: https://github.com/XMOJ-Script-dev/XMOJ-Script/sessions/dbcbbaed-e0e2-4aa7-959e-869a3b011a32
Deploying xmoj-script-dev-channel with
|
| 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 |
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
PythonSmall-Q
approved these changes
Mar 22, 2026
7965914 to
ead676a
Compare
Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
PythonSmall-Q
approved these changes
Mar 22, 2026
Contributor
There was a problem hiding this comment.
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 useGetMDText()instead of.innerText. - Update
/problem_solution.php“CopyMD” handler to useGetMDText()instead of.innerText.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
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.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copying 题解/题目 content silently dropped embedded images because
.innerTextstrips all HTML nodes including<img>tags.Changes
GetMDText(element)helper — recursively walks DOM nodes, emitting text content as-is and converting<img src="...">tomarkdown. Images without asrcare skipped. Relative URLs are resolved vianew URL(src, location.href)./problem_solution.phpcopy handler — replace.innerTextwithGetMDText()so images appear in the copied markdown./problem.phpcopy handler — same fix for problem description sections.Original prompt
📱 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
Dependencies
package.jsonto 3.3.6 (prerelease).Update.json3.3.6 feed entry (time and description).Written for commit 7f71fa1. Summary will update on new commits.