Skip to content

sync: dev to extern-contrib - #1032

Merged
boomzero merged 34 commits into
extern-contribfrom
dev
Oct 3, 2026
Merged

boomzero merged 34 commits into
extern-contribfrom
dev

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

sync-branches: New code has just landed in dev, so let's bring extern-contrib up to speed!

Summary by Sourcery

Improve problem-statement Markdown copying while preserving source formatting and add comprehensive browser regression coverage.

New Features:

  • Add Markdown copy controls for complete problems and individual sections, including structured sample input/output blocks.
  • Preserve TeX math, code fences, tables, links, images, and other formatting when copying problem statements as Markdown.

Bug Fixes:

  • Prevent rendered math and structured content from being flattened or duplicated during Markdown copying.

Enhancements:

  • Refactor problem Markdown copy generation to support modern and classic page layouts and follow the currently displayed language.

CI:

  • Install dependencies and Chromium in CI before running the browser-based test suite.

Tests:

  • Add Playwright regression coverage for Markdown formatting, math, tables, samples, language selection, copy controls, and extraction failures.

Chores:

  • Bump the userscript and package version to 3.8.0 and record the release in Update.json.

Summary by cubic

Syncs dev into extern-contrib, bringing the 3.8.0 release: it restores the userscript on pages broken by recent layout changes, makes copy controls work on the new /web/contest pages, and adds problem Markdown copying that preserves TeX math source, code fence language, table layout, and link destinations.

  • Fixes a TypeError on abnormal pages and reuses the copy controls across the new and legacy contest pages.
  • Adds copy controls for each section, the samples, and the full problem statement, with rendered math replaced by its TeX source and sample data copied as fenced blocks under their original headings.
  • Adds a Playwright browser test suite for Markdown copy regressions and makes CI install Chromium before running tests.
  • Bumps the userscript to 3.8.0 (with 3.7.2 as a prerelease) and adds the matching release entry to Update.json.

Written for commit 973262c. Summary will update on new commits.

Review in cubic

boomzero and others added 30 commits October 2, 2026 22:29
…-copy

fix: preserve problem Markdown and add full-statement copying
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

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

Latest commit: 973262c
Status: ✅  Deploy successful!
Preview URL: https://737e1453.xmoj-script-dev-channel.pages.dev

View logs

@sourcery-ai

sourcery-ai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This synchronization adds a reusable, language-aware Markdown-copy pipeline that extracts math source, preserves code and table structure, and exposes full-statement and section-level controls across modern and legacy problem pages. It also adds extensive Playwright browser regression tests, updates CI to provision Chromium, and bumps the release metadata.

Sequence diagram for language-aware Markdown copying

sequenceDiagram
    actor User
    participant Button as Copy button
    participant Init as InitializeProblemMarkdownCopy
    participant Markdown as GetProblemStatementMarkdown
    participant Section as GetProblemSectionMarkdown
    participant Text as GetMDText
    participant Clipboard as GM_setClipboard
    User->>Button: Click copy
    Button->>Markdown: Build statement Markdown
    Markdown->>Section: Extract problem sections
    Section->>Text: Convert section content
    Text-->>Section: Markdown with math, code, and tables
    Section-->>Markdown: Section Markdown
    Markdown-->>Button: Complete Markdown
    Button->>Clipboard: GM_setClipboard(markdown)
Loading

File-Level Changes

Change Details Files
Expanded Markdown copying from problem sections into complete, language-aware problem statements with reusable copy controls.
  • Added shared initialization for full-problem and per-section copy buttons.
  • Selected visible Chinese or English content and generated headings, descriptions, samples, and other sections.
  • Reused the same implementation for contest pages and fetched legacy problem pages while preventing duplicate controls.
XMOJ.user.js
Reworked HTML-to-Markdown conversion to preserve structured content and rendered mathematics.
  • Added MathJax, KaTeX, and MathML source extraction with inline and display delimiters.
  • Added fenced code-block handling with language detection and safe fence lengths.
  • Added Markdown pipe-table conversion, HTML fallbacks for unsupported tables, URL resolution, whitespace normalization, and cell-aware formatting.
XMOJ.user.js
Added browser regression coverage for Markdown conversion and copy controls.
  • Created a browser fixture covering math, code, tables, whitespace, links/images, samples, language switching, and DOM immutability.
  • Added Playwright-driven Node tests, including extraction-anchor failure cases and duplicate-anchor detection.
tests/markdown-copy.html
tests/markdown-copy.test.cjs
package.json
Updated test execution and browser CI setup for the new Playwright suite.
  • Installed dependencies without scripts and provisioned Chromium with system dependencies in CI.
  • Extended npm test to run both contest and Markdown-copy tests.
.github/workflows/Test.yml
package.json
Bumped project metadata and synchronized update information.
  • Incremented the userscript and package versions from 3.7.1 to 3.7.2.
  • Updated the generated update metadata.
XMOJ.user.js
package.json
Update.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="XMOJ.user.js" line_range="7948-7950" />
<code_context>
+        for (const child of body.children) Visit(child);
+        content = parts.join("\n\n");
+    } else {
+        const translated = body.querySelector(language === "en" ? ".content.lang_en" : ".content.lang_cn");
+        const fallback = body.querySelector(".content.lang_cn") || body.querySelector(".content");
+        content = GetMDText(translated || fallback || body).trim();
     }
+    return content ? "## " + heading + "\n\n" + content : "";
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** When English is selected but a section has no `.content.lang_en`, `translated` is null and the fallback explicitly selects `.content.lang_cn`, so the copied English statement contains Chinese content for that section.

**Triggers:** When a bilingual problem has an English title or other English sections but one section lacks an English translation.

**Suggested fix:** For `language === "en"`, omit the section or use an unlabelled content fallback before falling back to Chinese; do not silently copy `.content.lang_cn`.

```suggestion
        const translated = body.querySelector(language === "en" ? ".content.lang_en" : ".content.lang_cn");
        const fallback = language === "en"
            ? body.querySelector(".content:not(.lang_en):not(.lang_cn)")
            : body.querySelector(".content.lang_cn") || body.querySelector(".content");
        content = translated || fallback ? GetMDText(translated || fallback).trim() : "";
```
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: XMOJ.user.js:7950


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread XMOJ.user.js
Comment on lines +7948 to +7950
const translated = body.querySelector(language === "en" ? ".content.lang_en" : ".content.lang_cn");
const fallback = body.querySelector(".content.lang_cn") || body.querySelector(".content");
content = GetMDText(translated || fallback || body).trim();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): When English is selected but a section has no .content.lang_en, translated is null and the fallback explicitly selects .content.lang_cn, so the copied English statement contains Chinese content for that section.

Triggers: When a bilingual problem has an English title or other English sections but one section lacks an English translation.

Suggested fix: For language === "en", omit the section or use an unlabelled content fallback before falling back to Chinese; do not silently copy .content.lang_cn.

Suggested change
const translated = body.querySelector(language === "en" ? ".content.lang_en" : ".content.lang_cn");
const fallback = body.querySelector(".content.lang_cn") || body.querySelector(".content");
content = GetMDText(translated || fallback || body).trim();
const translated = body.querySelector(language === "en" ? ".content.lang_en" : ".content.lang_cn");
const fallback = language === "en"
? body.querySelector(".content:not(.lang_en):not(.lang_cn)")
: body.querySelector(".content.lang_cn") || body.querySelector(".content");
content = translated || fallback ? GetMDText(translated || fallback).trim() : "";

@hendragon-bot hendragon-bot Bot added GitHub-related user-script This issue or pull request is related to the main user script labels Oct 3, 2026
@boomzero
boomzero merged commit adf51b7 into extern-contrib Oct 3, 2026
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GitHub-related size/XL 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.

1 participant