跳转到内容

排版日志

This walkthrough documents the technical changes and verification steps completed to address the formatting template requirements for the course-design-report skill.

  • Problem: Next.js server-side pre-rendered the home and embed pages. CodeMirror (from react-codemirror2 package) references document globally at import time, which crashed the Next.js server in Node environments.
  • Solution: Created CodeMirrorWrapper.js to wrap react-codemirror2 and use React.forwardRef to pass references.
  • Integration: Updated Carbon.js to dynamically import CodeMirrorWrapper via next/dynamic with ssr: false. This completely bypassed server-side loading of CodeMirror, resolving the crash.

2. Fixed Next.js Dynamic Routing Mismatch Overlay Error

Section titled “2. Fixed Next.js Dynamic Routing Mismatch Overlay Error”
  • Problem: When loading the Carbon homepage with query parameters (e.g. http://localhost:3000/?code=...), Next.js dynamic routing triggered an mismatch error: The provided as value (/) is incompatible with the href value (/[id]). This overlayed a red stack trace screen on top of the browser viewport. As a result, the screenshot tool captured this error overlay instead of the actual code.
  • Solution: Updated EditorContainer.js to check if snippetId is falsy, and push to '/' instead of '{ pathname: "/[id]", query: { id: undefined } }'. This resolved the routing mismatch, removing the dev error overlay.

3. Individual Code Screenshotting & Chunk Splitting for Template

Section titled “3. Individual Code Screenshotting & Chunk Splitting for Template”
  • Problem: The initial version of rebuild_template.py replaced all 9 Java code block placeholders with a single hardcoded dummy screenshot (carbon_code.png).
  • Solution: Completely rewrote rebuild_template.py to:
    1. Extract the actual text content of the 9 separate code blocks from the source document template_source.docx.
    2. Implement code-splitting logic: If a code block is longer than 30 lines, split it into chunks of up to 30 lines.
    3. Invoke screenshot.js via Node to generate unique Carbon screenshots (with no background border, transparent background, mac theme, and user watermark) for each chunk.
    4. Replace the original placeholder paragraphs in the document with the respective images and add sequential captions (and “(续)” captions for splits).
  • Result: Successfully created 14 unique code screenshots and rebuilt the final template.docx (1.2 MB).
  • Problem: The cover page and table of contents (TOC) page should not display headers/footers (the cover should have neither; the TOC should have header only but no page numbers in the footer). In the initial build_docx.py, deleting all paragraphs from the template stripped all section breaks, merging the document into a single section, which incorrectly displayed headers and page numbers on the cover page.
  • Solution: Refactored build_docx.py to:
    1. Remove the trailing page break from write_toc and dynamically insert a section break via doc.add_section() after writing the cover and TOC pages.
    2. Unlink Section 1 (body section)‘s header and footer from Section 0 by setting is_linked_to_previous = False.
    3. Enable different_first_page_header_footer = True on Section 0 and clear its first page header/footer (making the cover header-free and footer-free).
    4. Populate the page number PAGE field only in the footer of Section 1 (main body).
    5. Move apply_page_setup(doc) to run at the end of document compilation to format all sections.
  • Autotesting: test_skill.py validates the full pipeline:
    1. Verify the integrity of template.docx by asserting that all embedded images are unique (checked using SHA-256 hashes).
    2. Dynamically create a test JS code file at runtime.
    3. Trigger screenshot generation using screenshot.js.
    4. Compile a test .docx document using build_docx.py combined with test_content.json inputs.
    5. Validate output document integrity (including checking that drawings are actually embedded).

The test suite ran successfully and confirmed the correctness of all components.

Starting End-to-End Skill Autotests...
=== Testing template.docx Integrity ===
Found 16 PNG files in template.docx media folder.
Found 16 unique image hashes out of 16 PNGs.
[OK] template.docx integrity check passed successfully!
=== Testing screenshot.js ===
Running command: node E:\AI\zcode\object\skills\course-design-report\scripts\screenshot.js --code E:\AI\zcode\object\skills\course-design-report\test\temp_test_code.js --lang javascript --out E:\AI\zcode\object\skills\course-design-report\test\test_carbon_code.png --url http://localhost:3000
STDOUT: BROWSER CONSOLE: Warning: The prop `disableClick` of `Dropzone` is deprecated. Use onClick={evt => evt.preventDefault()} instead. This prop will be removed in the next major version.
BROWSER CONSOLE: Access to font at 'http://cdn.jsdelivr.net/font-hack/2.020/fonts/woff2/hack-regular-webfont.woff2?v=2.020' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
BROWSER CONSOLE: Failed to load resource: net::ERR_FAILED
BROWSER CONSOLE: Access to font at 'http://cdn.jsdelivr.net/font-hack/2.020/fonts/woff/hack-regular-webfont.woff?v=2.020' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
BROWSER CONSOLE: Failed to load resource: net::ERR_FAILED
OK: E:\AI\zcode\object\skills\course-design-report\test\test_carbon_code.png
STDERR:
[OK] screenshot.js test passed successfully!
=== Testing build_docx.py ===
Running command: C:\Users\user\AppData\Local\Programs\Python\Python313\python.exe E:\AI\zcode\object\skills\course-design-report\scripts\build_docx.py --content E:\AI\zcode\object\skills\course-design-report\test\test_content.json --template E:\AI\zcode\object\skills\course-design-report\assets\template.docx --out E:\AI\zcode\object\skills\course-design-report\test\test_report.docx
STDOUT:
STDERR: OK: E:\AI\zcode\object\skills\course-design-report\test\test_report.docx
[OK] build_docx.py test passed successfully!
SUCCESS: ALL TESTS PASSED SUCCESSFULLY! The skill is fully verified and functional.