The MS-DOC format uses a Compound File Binary (CFB) container with multiple streams:
CFB Parser — Extracts streams from OLE container
FIB Parser — Reads File Information Block
CLX Parser — Recovers text via Piece Table
SPRM Decoder — Decodes property modifiers
FKP Reader — Reads format/property key pages
Styles Parser — Parses style definitions
Properties — Converts properties to state objects
Main Parser — Orchestrates the full pipeline
HTML Renderer — Converts parsed data to HTML+CSS
License
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
MS-DOC Viewer - MoonBit
High-performance MS-DOC (.doc binary Word) parser and renderer, compiled from MoonBit to JS, WASM, and WASM-GC backends.
Features
Multi-Target Build Architecture
One MoonBit source codebase, four build targets:
moon build --target js --releasecore.js(~375KB)moon build --target js --release workerworker.js(~380KB)moon build --target wasm --releasecore.wasm(~133KB)moon build --target wasm-gc --releasecore.wasm(~97KB)Build all targets at once:
Which Target to Use?
wasm:js-stringbuiltinsUsage
JS Target (Browser / Node.js)
Web Worker Target
WASM Target (Browser)
WASM-GC Target (Browser + MoonBit Runtime)
Also works with MoonBit’s own runtime:
MoonBit WASM Linear Memory ABI
This section documents the calling convention for MoonBit’s
wasm(linear memory) target.Object Layout
All MoonBit objects in WASM linear memory follow this pattern:
ptr - 8): Reference count (managed by MoonBit runtime)ptr - 4): Tag/type info (lower 8 bits) | length (upper 28 bits)length & 0x0FFFFFFFgives element countFixedArray[Byte] (Bytes)
String
Strings are UTF-16 encoded (2 bytes per character).
Function Return Convention
Functions that can raise return
(tag: i32, result: i32):resultis an error string pointerresultis the return value pointerKey Differences Between WASM Targets
wasm:js-stringbuiltinsexport-memory-name: "memory"use-js-builtin-string: trueAPI Reference
Core Functions
parse_ms_doc(bytes)FixedArray[Byte]MsDocParseResultrender_ms_doc(bytes)FixedArray[Byte]RenderResultparse_ms_doc_to_html(bytes)FixedArray[Byte]StringWASM-GC Bridge Functions
render_ms_doc_wasm(hex)"CSS|||HTML"parse_ms_doc_to_html_wasm(hex)"CSS|||HTML"parse_ms_doc_wasm(hex)Worker Functions
worker_parse(bytes)FixedArray[Byte]worker_render(bytes)FixedArray[Byte]"CSS|||HTML"worker_parse_to_html(bytes)FixedArray[Byte]"CSS|||HTML"Building from Source
Prerequisites
Build
Run Demos
Serve the project root with any HTTP server, then open:
demo/index.html— Landing pagedemo/js.html— JS target demodemo/wasm.html— WASM linear memory demodemo/wasm-gc.html— WASM-GC demodemo/worker.html— Web Worker demoProject Structure
Architecture
The MS-DOC format uses a Compound File Binary (CFB) container with multiple streams:
License
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.