Skip to content

Bootstrap docforge Rust CLI with IR-based converter architecture and CI checks - #1

Merged
TPJHtpjh merged 3 commits into
mainfrom
copilot/initialize-docforge-cli-project
Jun 4, 2026
Merged

Bootstrap docforge Rust CLI with IR-based converter architecture and CI checks#1
TPJHtpjh merged 3 commits into
mainfrom
copilot/initialize-docforge-cli-project

Conversation

Copilot AI commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

This PR initializes docforge as a Rust CLI for Markdown/HTML/DOCX/PDF document conversion using a shared intermediate representation. It wires complete project structure, converter interfaces, and a working Markdown→HTML flow while leaving complex format internals as explicit stubs.

  • Core architecture (IR pattern)

    • Added src/core/ir.rs with unified Document, DocNode, and InlineNode.
    • Added src/core/converter.rs with Converter trait, DocumentFormat, RenderedDocument, and thiserror-based ConverterError.
  • Converter modules

    • Added modular converter layout under src/converters/:
      • markdown.rs: implemented parsing to IR (headings/paragraph text path) and Markdown rendering from IR.
      • html.rs: implemented IR→HTML rendering.
      • docx.rs, pdf.rs: structural todo!("Implement specific logic") stubs for crate-specific logic.
    • Included a direct Markdown→HTML helper example via pulldown-cmark.
  • CLI wiring

    • Replaced scaffold main.rs with clap-driven CLI (--input, --output).
    • Added extension-based format routing (md/markdown, html/htm, docx, pdf) and conversion flow through IR.
  • Project setup and repo hygiene

    • Added required dependencies in Cargo.toml (clap, anyhow, thiserror, pulldown-cmark, htmd, docx-rs, printpdf, serde, serde_json).
    • Added rust-toolchain.toml pinned to stable.
    • Added Rust .gitignore.
    • Added GitHub Actions workflow for cargo fmt --check, cargo clippy --all-targets -- -D warnings, and cargo test --all-targets with explicit least-privilege token permissions.
  • Focused coverage

    • Added tests/conversion_flow.rs to validate:
      • Markdown→HTML helper output.
      • Markdown parse-to-IR + HTML render-from-IR flow.
pub trait Converter {
    fn parse_to_ir(&self, input: &[u8]) -> Result<Document, ConverterError>;
    fn render_from_ir(&self, document: &Document) -> Result<RenderedDocument, ConverterError>;
}
Original prompt

Act as an expert Rust developer. Initialize a robust CLI project named "docforge".
The goal of this tool is to convert documents between Markdown, HTML, and DOCX formats, and export any of them to PDF.

Please set up the project with the following requirements:

  1. Tech Stack & Dependencies (in Cargo.toml):

    • CLI: clap (with derive feature)
    • Error handling: anyhow (for bin) and thiserror (for lib)
    • Markdown: pulldown-cmark
    • HTML: htmd
    • Word: docx-rs
    • PDF Generation: printpdf
    • Serialization: serde, serde_json
  2. Architecture (Intermediate Representation Pattern):

    • Create a src/core/ir.rs defining the unified document model: Document, DocNode (enum for Heading, Paragraph, etc.), and InlineNode.
    • Create a src/core/converter.rs defining a trait Converter with methods for parsing to IR and rendering from IR.
  3. File Structure:

    • src/main.rs: CLI entry point using clap, routing input files to the correct converter based on extension.
    • src/lib.rs: Expose core modules.
    • src/converters/: Create modular files (markdown.rs, html.rs, docx.rs, pdf.rs) implementing the Converter trait.
  4. Implementation Guidelines:

    • Wire up the CLI and the IR structures completely.
    • For complex crate-specific parsing/rendering logic (like DOCX XML traversal or PDF coordinate drawing), write clean structural stubs with todo!("Implement specific logic") to avoid API hallucinations and ensure the project compiles perfectly on the first try.
    • Implement a basic Markdown to HTML conversion as a working example.
  5. Engineering & CI:

    • Include a standard Rust .gitignore.
    • Add a rust-toolchain.toml pinning to the latest stable version.
    • Create a basic GitHub Actions workflow (.github/workflows/rust.yml) that runs cargo fmt --check, cargo clippy -- -D warnings, and cargo test.

Ensure the code is idiomatic, well-documented, and strictly follows Rust best practices.

Copilot AI changed the title [WIP] Initialize CLI project docforge for document conversion Bootstrap docforge Rust CLI with IR-based converter architecture and CI checks Jun 4, 2026
Copilot AI requested a review from TPJHtpjh June 4, 2026 01:55
@TPJHtpjh
TPJHtpjh marked this pull request as ready for review June 4, 2026 02:02
@TPJHtpjh
TPJHtpjh merged commit 64b26ee into main Jun 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants