fix(slides): reindent xml-get output with a stdlib-only formatter#2018
fix(slides): reindent xml-get output with a stdlib-only formatter#2018tianyouskrrr wants to merge 1 commit into
Conversation
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).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughSlides XML fetching now pretty-prints XML for ChangesSlides XML formatting
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
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@7f9c6d9bfb91f057bbe9f171d95340a6d75b2603🧩 Skill updatenpx skills add larksuite/cli#codex/cli-xml-pretty-print-stdlib -y -g |
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Summary
Reland of #1987 (reverted in #2013):
slides +xml-getagain reindents presentation/slide XML on the text output surfaces — with the formatter rebuilt on the Go standard library only. The BSD-licensedgithub.com/beevik/etreedependency that triggered the revert is gone;go.modgains nothing.--rawand--outputreindent 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.pretty_printedfield (unchanged from the reverted PR).--raw/--outputcontent fails (non-strict XML), the command falls back to the original content, warns on stderr, and reportspretty_printed: falsein--outputfile metadata (unchanged).How the new formatter works (and why it needs no XML library)
encoding/xmlserves purely as a tokenizer: every token is mapped back to its byte range in the original input viaDecoder.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: , ,	, , , ...), entity lexical forms, attribute quoting, and in-tag whitespace all survive byte-for-byte by construction;pretty_printed: true.Fidelity evidence
 -between-inline-siblings case, idempotency, malformed rejection, all three output-surface behaviors incl. fallbacks).TestPrettyPrintXMLPreservesLexicalFormsEtreeChangedwith the old etree output recorded alongside.p), masking-era placeholder regression, and a real-fixture convergence test (format(minified fixture) == format(shipped fixture), idempotent) plus benchmarks.Test plan
make unit-testgo vet ./...gofmt -l .go mod tidy(removesgithub.com/beevik/etree; nothing else changes)make buildgo run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/mainapi getraw response (both scopes),--raw/--outputidentical formatted output,pretty_printed/sizemetadata correctSummary by CodeRabbit
New Features
--rawor saved with--outputis now formatted for easier reading.Documentation
Bug Fixes