排版日志
This walkthrough documents the technical changes and verification steps completed to address the formatting template requirements for the course-design-report skill.
Changes Made
Section titled “Changes Made”1. Fixed Carbon SSR Crash
Section titled “1. Fixed Carbon SSR Crash”- Problem: Next.js server-side pre-rendered the home and embed pages. CodeMirror (from
react-codemirror2package) referencesdocumentglobally at import time, which crashed the Next.js server in Node environments. - Solution: Created CodeMirrorWrapper.js to wrap
react-codemirror2and useReact.forwardRefto pass references. - Integration: Updated Carbon.js to dynamically import
CodeMirrorWrappervianext/dynamicwithssr: 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
snippetIdis 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.pyreplaced all 9 Java code block placeholders with a single hardcoded dummy screenshot (carbon_code.png). - Solution: Completely rewrote rebuild_template.py to:
- Extract the actual text content of the 9 separate code blocks from the source document
template_source.docx. - Implement code-splitting logic: If a code block is longer than 30 lines, split it into chunks of up to 30 lines.
- Invoke
screenshot.jsvia Node to generate unique Carbon screenshots (with no background border, transparent background, mac theme, anduserwatermark) for each chunk. - Replace the original placeholder paragraphs in the document with the respective images and add sequential captions (and “(续)” captions for splits).
- Extract the actual text content of the 9 separate code blocks from the source document
- Result: Successfully created 14 unique code screenshots and rebuilt the final template.docx (1.2 MB).
4. Page Layout and Section Separation
Section titled “4. Page Layout and Section Separation”- 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:
- Remove the trailing page break from
write_tocand dynamically insert a section break viadoc.add_section()after writing the cover and TOC pages. - Unlink Section 1 (body section)‘s header and footer from Section 0 by setting
is_linked_to_previous = False. - Enable
different_first_page_header_footer = Trueon Section 0 and clear its first page header/footer (making the cover header-free and footer-free). - Populate the page number PAGE field only in the footer of Section 1 (main body).
- Move
apply_page_setup(doc)to run at the end of document compilation to format all sections.
- Remove the trailing page break from
5. Autotests Verified
Section titled “5. Autotests Verified”- Autotesting: test_skill.py validates the full pipeline:
- Verify the integrity of
template.docxby asserting that all embedded images are unique (checked using SHA-256 hashes). - Dynamically create a test JS code file at runtime.
- Trigger screenshot generation using
screenshot.js. - Compile a test
.docxdocument usingbuild_docx.pycombined withtest_content.jsoninputs. - Validate output document integrity (including checking that drawings are actually embedded).
- Verify the integrity of
Verification Results
Section titled “Verification Results”The test suite ran successfully and confirmed the correctness of all components.
E2E Autotest Output:
Section titled “E2E Autotest Output:”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:3000STDOUT: 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_FAILEDBROWSER 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_FAILEDOK: 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.docxSTDOUT: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.