Skip to content

fix(slides): reindent xml-get output with a stdlib-only formatter#2018

Open
tianyouskrrr wants to merge 1 commit into
mainfrom
codex/cli-xml-pretty-print-stdlib
Open

fix(slides): reindent xml-get output with a stdlib-only formatter#2018
tianyouskrrr wants to merge 1 commit into
mainfrom
codex/cli-xml-pretty-print-stdlib

Conversation

@tianyouskrrr

@tianyouskrrr tianyouskrrr commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Reland of #1987 (reverted in #2013): slides +xml-get again reindents presentation/slide XML on the text output surfaces — with the formatter rebuilt on the Go standard library only. The BSD-licensed github.com/beevik/etree dependency that triggered the revert is gone; go.mod gains nothing.

  • --raw and --output reindent the XML so each structural element (presentation/slide/shape/style/...) sits on its own line. Reindentation never enters the schema's mixed-content text-bearing elements (p, span, strong, em, u, del, a, shadow, outline, chartTitle, chartSubTitle) and never touches leaf elements, so document text is never altered.
  • The default JSON envelope carries the server's XML verbatim — never parsed, byte-exact, no pretty_printed field (unchanged from the reverted PR).
  • If formatting --raw/--output content fails (non-strict XML), the command falls back to the original content, warns on stderr, and reports pretty_printed: false in --output file metadata (unchanged).

How the new formatter works (and why it needs no XML library)

encoding/xml serves purely as a tokenizer: every token is mapped back to its byte range in the original input via Decoder.InputOffset, and the output is assembled exclusively from verbatim slices of the input plus \n+indent runs inserted between the children of structural elements. Nothing is parsed-and-reserialized, so:

  • CDATA sections, whitespace character references in any spelling ( ,  , 	, 
, 
, ...), entity lexical forms, attribute quoting, and in-tag whitespace all survive byte-for-byte by construction;
  • the character-reference masking machinery the etree implementation needed is deleted, not ported — ~90 lines of code and a whole failure class gone;
  • the full document is decoded before anything is emitted, so malformed input still errors into the existing fallback path — including element-free responses (plain text, comment-only), which the tolerant decoder would otherwise pass through while misreporting pretty_printed: true.

Fidelity evidence

  • Every contract test from the reverted PR carries over without weakening a single assertion (golden strings, escaped-reference table incl. hex/zero-padded/CR/LF spellings, leaf whitespace, CDATA, the bare  -between-inline-siblings case, idempotency, malformed rejection, all three output-surface behaviors incl. fallbacks).
  • A differential probe against the etree implementation over 53 inputs (including the real ~60KB chart-demo deck) was byte-identical except six cases, each of which now preserves the original bytes more faithfully (e.g. non-whitespace character references keep their lexical form, single-quoted attributes keep their quoting, whitespace-only CDATA between structural children is kept). Each divergence is pinned in TestPrettyPrintXMLPreservesLexicalFormsEtreeChanged with the old etree output recorded alongside.
  • New engine-level tests: malformed-input table (incl. late-error no-partial-output), structural table (comments/PIs/prolog/DOCTYPE/CRLF/multi-byte UTF-8/namespace-prefixed p), masking-era placeholder regression, and a real-fixture convergence test (format(minified fixture) == format(shipped fixture), idempotent) plus benchmarks.
  • Perf on the 60KB chart demo: ~0.74ms minified / ~0.85ms preformatted per format, ~40% fewer allocations than the etree implementation on identical input.

Test plan

  • make unit-test
  • go vet ./...
  • gofmt -l .
  • go mod tidy (removes github.com/beevik/etree; nothing else changes)
  • make build
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/main
  • Live verification on a real presentation: envelope content byte-identical to api get raw response (both scopes), --raw/--output identical formatted output, pretty_printed/size metadata correct

Summary by CodeRabbit

  • New Features

    • XML returned through --raw or saved with --output is now formatted for easier reading.
    • Output metadata indicates whether formatting succeeded.
    • Formatting failures preserve the original XML and display a warning.
  • Documentation

    • Updated command-line help and dry-run messages to describe formatted XML output.
  • Bug Fixes

    • Preserved verbatim XML envelope responses and content when formatting is not requested.

Reland of #1987 (reverted in #2013 over the BSD attribution gap of
github.com/beevik/etree) with the formatter rebuilt on the Go standard
library only — no third-party dependency.

encoding/xml serves purely as a tokenizer; the output is assembled
exclusively from verbatim byte slices of the server content plus
indentation inserted between structural elements. Nothing is
parsed-and-reserialized, so CDATA sections, whitespace character
references in any spelling, entity lexical forms, attribute quoting,
and in-tag whitespace survive byte-for-byte — the character-reference
masking machinery of the etree implementation is no longer needed.

Behavior is unchanged from the reverted PR: --raw stdout and --output
files are reindented (never inside the schema's mixed-content
text-bearing elements), the default JSON envelope carries the server's
XML verbatim without parsing, and formatting failures fall back to the
original content with a stderr warning and pretty_printed: false in
--output file metadata. All contract tests carry over unweakened; a
differential probe against the etree implementation over 53 inputs was
byte-identical except six cases where the new formatter preserves the
original bytes more faithfully (each pinned in tests).
@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ebb6e66-4af1-48dd-b0b4-afc662d36c1e

📥 Commits

Reviewing files that changed from the base of the PR and between af8507e and 7f9c6d9.

📒 Files selected for processing (4)
  • shortcuts/slides/slides_xml_get.go
  • shortcuts/slides/slides_xml_get_test.go
  • shortcuts/slides/slides_xml_prettyprint.go
  • shortcuts/slides/slides_xml_prettyprint_test.go

📝 Walkthrough

Walkthrough

Slides XML fetching now pretty-prints XML for --raw and --output, preserves envelope content verbatim, and reports formatting fallbacks. A new byte-preserving formatter and extensive tests cover malformed input, lexical preservation, idempotency, and output behavior.

Changes

Slides XML formatting

Layer / File(s) Summary
Byte-preserving XML formatter
shortcuts/slides/slides_xml_prettyprint.go
Strictly tokenizes XML, preserves raw lexical content, and reindents structural elements while keeping text-bearing subtrees verbatim.
SlidesXMLGet output integration
shortcuts/slides/slides_xml_get.go
Formats --raw and --output content, records pretty_printed for files, and falls back to original XML with a warning on formatting failure.
Formatter validation
shortcuts/slides/slides_xml_prettyprint_test.go
Adds golden, malformed-input, lexical-preservation, idempotency, fixture, and benchmark coverage.
SlidesXMLGet validation
shortcuts/slides/slides_xml_get_test.go
Verifies formatted output, verbatim envelopes, fallback behavior, metadata, warnings, and updated flag descriptions.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SlidesXMLGet
  participant prettyPrintXMLOrOriginal
  participant Output
  SlidesXMLGet->>prettyPrintXMLOrOriginal: format raw or output XML
  prettyPrintXMLOrOriginal->>Output: return formatted or original XML
  SlidesXMLGet->>Output: write XML and metadata
Loading

Possibly related PRs

  • larksuite/cli#1585: Introduced the SlidesXMLGet shortcut and shares the same command area.
  • larksuite/cli#1887: Refactored SlidesXMLGet output and envelope behavior used by this formatting change.
  • larksuite/cli#2013: Directly conflicts on whether SlidesXMLGet preserves server XML or pretty-prints it.

Suggested labels: feature

Suggested reviewers: ethan-zhx, fangshuyu-768

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: reindenting slides xml-get output with a standard-library formatter.
Description check ✅ Passed The description covers the summary and test plan well, with detailed implementation notes, though it omits the exact Changes and Related Issues sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/cli-xml-pretty-print-stdlib

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@7f9c6d9bfb91f057bbe9f171d95340a6d75b2603

🧩 Skill update

npx skills add larksuite/cli#codex/cli-xml-pretty-print-stdlib -y -g

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.83051% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.08%. Comparing base (af8507e) to head (7f9c6d9).

Files with missing lines Patch % Lines
shortcuts/slides/slides_xml_prettyprint.go 91.34% 4 Missing and 5 partials ⚠️
shortcuts/slides/slides_xml_get.go 78.57% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2018      +/-   ##
==========================================
+ Coverage   75.06%   75.08%   +0.01%     
==========================================
  Files         902      903       +1     
  Lines       95944    96057     +113     
==========================================
+ Hits        72025    72129     +104     
- Misses      18380    18384       +4     
- Partials     5539     5544       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant