Extract native Markdown codec from AndroidDocumentsPlugin#91
Merged
Conversation
Moves the pure-JVM Markdown byte handling into a focused MarkdownCodec helper: encoding-name normalization, charset lookup, BOM detection and emission (UTF-32 sniffed before its UTF-16 prefix), strict encode/decode with the REPORT coding actions, and the 5 MB byte validation. The supporting value types (DocumentReadException, MarkdownWriteOptions, DecodedMarkdown) become package-visible top-level classes so every existing plugin reference and catch clause compiles unchanged. The plugin keeps all Capacitor, URI, ContentResolver, and Activity lifecycle responsibilities: readText/writeText stream I/O stays put and now feeds bytes through the codec, and the mutable default-encoding / auto-detect settings remain plugin state passed into decode per call. Error codes, messages, and byte-level behavior are unchanged. Adds MarkdownCodecTest (8 JUnit tests, pure JVM) covering round trips, BOM writing/detection incl. the UTF-32/UTF-16 prefix priority, the auto-detect-off default-match rule, the size limit, name normalization, and both encode/decode failure codes, and wires gradlew testDebugUnitTest into the Android debug workflow so native tests gate CI from now on.
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sixth PR of the semantic-decomposition series, first on the native side: moves the pure-JVM Markdown byte handling out of
AndroidDocumentsPlugin.javainto a focusedMarkdownCodechelper. Behavior-preserving — error codes, messages, and byte-level output are unchanged.Boundary
MarkdownCodec(package-private, static, zero Android dependencies) owns:DOCUMENT_ENCODING_UNSUPPORTEDmapping,CodingErrorAction.REPORTand theDOCUMENT_ENCODING_FAILEDmapping,DOCUMENT_TOO_LARGE), exposed constant included since the plugin's streaming read enforces the same limit.The supporting value types —
DocumentReadException,MarkdownWriteOptions,DecodedMarkdown— are promoted from private inner classes to package-visible top-level classes, chosen deliberately so every existing plugin reference, method signature, and catch clause compiles unchanged.The plugin keeps everything the TODO says it must: Capacitor call handling, URI parsing,
ContentResolverstream I/O (readText/writeTextstay put and feed bytes through the codec), Activity lifecycle, and the mutable default-encoding/auto-detect settings — which remain plugin state passed intodecodeper call, soconfigureMarkdownSettingssemantics are identical.Testing
MarkdownCodecTest(8 JUnit tests, pure JVM, no emulator needed): UTF-8 round trip with CJK content, BOM write + detect, the UTF-32LE-vs-UTF-16LE sniff priority, the auto-detect-off rule that still honors a BOM matching the default encoding, the 5 MB rejection code, name normalization (unknown/null/untrimmed), and bothDOCUMENT_ENCODING_FAILEDpaths (unmappable char on encode, malformed bytes on decode). All 8 pass viagradlew testDebugUnitTest.testDebugUnitTestbefore assembling, so native unit tests gate merges from this PR onward.compileDebugJavaWithJavacandassembleDebuggreen locally; the web bundle is untouched (Java-only diff), and the TS-side encoding contract is unchanged (encoding/hasEncodingBompayload fields, error-code strings).