### Setup Document Styles Usage Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/styles.md Example demonstrating how to use the `setup_document_styles` function with default configuration. ```rust use md2docx::styles::setup_document_styles; use md2docx::config::Config; use docx_rs::Docx; let config = Config::default(); let mut docx = Docx::new(); docx = setup_document_styles(docx, &config); ``` -------------------------------- ### Size Configuration Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Example of how to set font sizes for body and headings in a TOML configuration file. ```toml [sizes] body = 11.0 heading1 = 15.0 heading2 = 13.0 ``` -------------------------------- ### Font Configuration Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Example of how to specify font settings in a TOML configuration file. ```toml [fonts] body_ja = "游明朝" body_en = "Times New Roman" heading_ja = "游ゴシック" heading_en = "Arial" ``` -------------------------------- ### PageConfig TOML Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Example configuration for page dimensions and margins using TOML. ```toml [page] width = 11906 height = 16838 margin_left = 2000 margin_right = 2000 ``` -------------------------------- ### Page Layout Customization Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/README.md Example TOML configuration for adjusting page width and left margin. ```toml [page] width = 12000 # より広い margin_left = 2500 # 左余白を大きく ``` -------------------------------- ### Setup Document Styles in Converter Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/styles.md Illustrates the usage of `setup_document_styles` within the context of a converter function, likely `convert_to_docx`. ```rust // convert_to_docx() より抜粋 let docx = styles::setup_document_styles(docx, config); ``` -------------------------------- ### Setup Document Styles Signature Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/styles.md Function signature for `setup_document_styles`. It takes a Docx instance and a Config, returning a Docx instance with styles applied. ```rust pub fn setup_document_styles(docx: Docx, config: &Config) -> Docx ``` -------------------------------- ### IndentConfig TOML Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Example configuration for body and heading indentation using TOML. ```toml [indent] body_left = 210 body_first_line = 210 heading1_left = 420 heading1_hanging = 420 ``` -------------------------------- ### mdd Configuration Example (TOML) Source: https://github.com/nokonoko1203/md2docx/blob/main/README.md Example TOML configuration file for mdd, demonstrating settings for fonts, sizes, page layout, indentation, bullet points, and numbering formats. ```toml [fonts] body_ja = "游明朝" body_en = "Century" heading_ja = "游ゴシック" heading_en = "Century" [sizes] body = 10.5 table_body = 9.5 table_header = 9.5 heading1 = 14.0 heading2 = 12.0 heading3 = 11.0 heading4 = 11.0 heading5 = 10.5 [page] width = 11906 height = 16838 margin_top = 1985 margin_right = 1701 margin_bottom = 1701 margin_left = 1701 margin_header = 851 margin_footer = 992 margin_gutter = 0 [indent] body_left = 210 body_first_line = 210 body_right = 210 body_left_chars = 100 heading1_left = 420 heading1_hanging = 420 heading2_left = 612 heading2_hanging = 612 heading3_left = 783 heading3_hanging = 783 heading4_left = 709 heading4_hanging = 709 heading5_left = 709 heading5_hanging = 709 heading6_left = 709 heading6_hanging = 709 [bullet] level0 = "●" level1 = "■" level2 = "▲" [numbering] figure_format = "sequential" table_format = "sequential" ``` -------------------------------- ### Markdown Ordered List Example with Nesting Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/feature-overview.md Illustrates a nested ordered list starting from a specific number. Supports arbitrary nesting and mixing with bulleted lists, with automatic indentation adjustment. ```markdown 3. 項目3から開始 4. 項目4 5. 項目5 - トップレベル - ネスト1 - ネスト2 1. 番号付きに変更 1. さらにネスト ``` -------------------------------- ### Font Customization Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/README.md Example TOML configuration for changing body and heading fonts for Japanese text. ```toml [fonts] body_ja = "HGS創英角ポップ体" heading_ja = "ヒラギノ角ゴ Pro" ``` -------------------------------- ### Install mdd CLI Tool Source: https://github.com/nokonoko1203/md2docx/blob/main/README.md Install the mdd CLI tool using Cargo. Ensure you have Rust 1.70 or higher. ```sh cargo install --path . ``` -------------------------------- ### Numbering Format Customization Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/README.md Example TOML configuration for setting figure and table numbering to use chapter-based formatting. ```toml [numbering] figure_format = "chapter" # 図番号を章番号付き table_format = "chapter" # 表番号も章番号付き ``` -------------------------------- ### Basic HeadingManager Usage Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-heading.md Demonstrates the basic usage of HeadingManager, including initializing, generating automatic numbers, using existing numbers, and stripping numbers from titles. Shows how counters reset when higher-level headings change. ```rust use md2docx::heading::HeadingManager; use md2docx::ir::Inline; let mut mgr = HeadingManager::new(); // H1 見出し(自動番号) let content1 = vec![Inline::Text("プロジェクト概要".to_string())]; let num = mgr.next_heading(1, &content1); println!("見出し1の番号: {}", num); // "1" // H2 見出し(自動番号) let content2 = vec![Inline::Text("背景".to_string())]; let num = mgr.next_heading(2, &content2); println!("見出し2の番号: {}", num); // "1.1" // H1 見出し(既存の番号を使用) let content3 = vec![Inline::Text("5 別の章".to_string())]; let num = mgr.next_heading(1, &content3); println!("見出し1の番号: {}", num); // "5" // タイトルだけ抽出 let title = mgr.strip_number(1, "5 別の章"); println!("タイトル: {}", title); // "別の章" // H3 見出し(H1 が 5 に変わったのでリセット) let content4 = vec![Inline::Text("詳細".to_string())]; let num = mgr.next_heading(3, &content4); println!("見出し3の番号: {}", num); // "5.0.1" ``` -------------------------------- ### Initialize HeadingManager Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-heading.md Initializes a new HeadingManager instance. All counters start at 0. ```rust pub fn new() -> Self ``` -------------------------------- ### Example: Create Nested List Items Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/types.md Demonstrates how to construct a `ListItem` with nested `Block` elements, such as a sub-list. This is useful for representing hierarchical lists in Markdown. ```rust Block::BulletList { items: vec![ ListItem { content: vec![Inline::Text("項目1".to_string())], children: vec![], // ネストなし }, ListItem { content: vec![Inline::Text("項目2".to_string())], children: vec![ Block::BulletList { items: vec![ ListItem { content: vec![Inline::Text("子項目".to_string())], children: vec![], } ] } ], } ] } ``` -------------------------------- ### Indent Adjustment Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/README.md Example TOML configuration for adjusting first-line body indent and heading left indent. ```toml [indent] body_first_line = 420 # 字下げを大きく heading1_left = 500 # 見出し1の左インデント ``` -------------------------------- ### Bullet Character Customization Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/README.md Example TOML configuration for changing bullet characters for different list nesting levels. ```toml [bullet] level0 = "→" level1 = "•" level2 = "◦" ``` -------------------------------- ### Automatic Heading Numbering Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/README.md Demonstrates hierarchical automatic numbering for headings from H1 to H5. Existing numbers are prioritized, and duplicates are avoided. ```markdown # 1 見出し1 ## 1.1 見出し2 ### 1.1.1 見出し3 #### (1) 見出し4 ##### ① 見出し5 ``` -------------------------------- ### Space Removal Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/README.md Shows the removal of extra spaces between English and Japanese text. ```text Hello 世界 → Hello世界 日本語 ABC → 日本語ABC ``` -------------------------------- ### Markdown Bulleted List Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/feature-overview.md Demonstrates a nested bulleted list using hyphens. The converter automatically inserts appropriate bullet characters for each nesting level. ```markdown - トップレベル - ネスト1 - ネスト2 ``` -------------------------------- ### Image Scaling Calculation Example Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/feature-overview.md Illustrates the calculation for image scaling based on page width and margins. Images exceeding the available text width are automatically scaled down while maintaining aspect ratio. ```text ページ幅: 11906 twip 左余白: 1701 twip 右余白: 1701 twip 本文幅: 8504 twip 画像幅が 8504 twip を超える場合 → スケーリング ``` -------------------------------- ### 変換スクリプト (build.sh) Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md Bash スクリプトで、指定されたディレクトリ (`docs/`) の Markdown ファイルを、設定ファイル (`config.toml`) を使用して一括変換し、指定されたディレクトリ (`output/`) に出力します。 ```bash #!/bin/bash set -e CONFIG="config.toml" INPUT_DIR="docs" OUTPUT_DIR="output" mkdir -p "$OUTPUT_DIR" for md_file in "$INPUT_DIR"/*.md; do base=$(basename "$md_file" .md) output="$OUTPUT_DIR/${base}.docx" echo "変換中: $md_file -> $output" mdd "$md_file" -c "$CONFIG" -o "$output" done echo "完了!" ``` -------------------------------- ### setup_document_styles Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/styles.md Applies Sample.docx compliant styles and numbering definitions to a Word document, configuring headings, body text, and bullet points. ```APIDOC ## setup_document_styles ### Description Applies Sample.docx compliant styles and numbering definitions to a Word document, configuring headings, body text, and bullet points globally. ### Signature ```rust pub fn setup_document_styles(docx: Docx, config: &Config) -> Docx ``` ### Parameters - `docx` (Docx) - The Docx instance from docx_rs. - `config` (&Config) - Configuration object for fonts, sizes, and indentation. ### Returns - `Docx` - A new Docx instance with styles and numbering definitions applied. ### Usage Example ```rust use md2docx::styles::setup_document_styles; use md2docx::config::Config; use docx_rs::Docx; let config = Config::default(); let mut docx = Docx::new(); docx = setup_document_styles(docx, &config); ``` ``` -------------------------------- ### 変換スクリプトの実行権限付与と実行 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 作成した Bash スクリプト (`build.sh`) に実行権限を付与し、実行するコマンドです。 ```bash chmod +x build.sh ./build.sh ``` -------------------------------- ### デフォルト設定の確認 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md `mdd --help` コマンドを実行すると、利用可能なオプションとデフォルト設定に関する情報が表示されます。 ```bash mdd --help ``` -------------------------------- ### バージョン確認 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md インストール後、PATH が通っていれば `mdd --version` コマンドでバージョンを確認できます。 ```bash mdd --version ``` -------------------------------- ### Configuration File Loading Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/feature-overview.md Demonstrates loading a TOML configuration file with the -c option. Only specified items in the TOML file override default values. Command-line options like -o take precedence for their specific settings. ```bash # TOML に [sizes] body=11 と書かれていても、 # TOML に [fonts] は記載がなければデフォルト mdd input.md -c partial.toml ``` -------------------------------- ### カスタム設定ファイルを適用して変換 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md `-c` オプションで作成したカスタム設定ファイル (`custom.toml`) を指定し、入力ファイル (`input.md`) を変換して `output.docx` に出力します。 ```bash mdd input.md -c custom.toml -o output.docx ``` -------------------------------- ### パターン 3: 複数 Markdown ファイルの一括変換 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md Bash スクリプトを使用して、カレントディレクトリにある全ての `.md` ファイルを `config.toml` 設定で一括変換します。 ```bash #!/bin/bash for file in *.md; do mdd "$file" -c config.toml done ``` -------------------------------- ### パターン 2: 組織の標準スタイルで報告書作成 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 共有された標準スタイル設定ファイル (`brand-standard.toml`) を使用して、報告書 Markdown (`report.md`) を Word 文書 (`final_report.docx`) に変換します。 ```bash # brand-standard.toml を共有 mdd report.md -c brand-standard.toml -o final_report.docx ``` -------------------------------- ### Get Current H1 Counter Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-heading.md Returns the current H1 counter value. This is useful for generating figure or table numbers that are dependent on the chapter number. ```rust pub fn current_h1_number(&self) -> u32 ``` -------------------------------- ### 基本的な Markdown から DOCX への変換 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 最もシンプルな使用方法です。入力 Markdown ファイルを指定すると、同じディレクトリに DOCX ファイルが出力されます。 ```bash # 入力: document.md # 出力: document.docx(同じディレクトリ) mdd document.md ``` -------------------------------- ### PATH が通っていない場合の対処法 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md `mdd: command not found` エラーが発生した場合、`~/.cargo/bin` が PATH に含まれていない可能性があります。PATH を確認し、必要に応じて追加してシェルを再起動してください。 ```bash echo $PATH # ~/.cargo/bin が含まれているか確認 # 含まれていなければ追加(~/.bashrc や ~/.zshrc): export PATH="$HOME/.cargo/bin:$PATH" # 再度ログイン source ~/.bashrc ``` -------------------------------- ### Get Next Heading Number Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-heading.md Updates the heading number based on the level and returns a formatted number string. If the text already contains a number, it respects that number and synchronizes the counters. Use this when generating a new heading. ```rust pub fn next_heading(&mut self, level: u8, content: &[Inline]) -> String ``` -------------------------------- ### HeadingManager::new Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-heading.md Initializes a new HeadingManager instance with all counters set to zero. ```APIDOC ## new ### Description Initializes a new HeadingManager instance. All counters start at 0. ### Signature ```rust pub fn new() -> Self ``` ### Returns `Self` - A new instance. ``` -------------------------------- ### Use Custom Configuration File with mdd Source: https://github.com/nokonoko1203/md2docx/blob/main/README.md Convert a Markdown file using a custom TOML configuration file specified with the -c or --config option. ```sh mdd document.md -o output.docx -c mdd.toml ``` -------------------------------- ### パターン 1: ブログ記事を Word 形式で配布 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md Markdown ファイル (`article.md`) を指定して、Word 文書 (`article_for_distribution.docx`) に変換するシンプルな例です。 ```bash mdd article.md -o article_for_distribution.docx ``` -------------------------------- ### 画像挿入時の相対パス解決 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 画像が挿入されない場合、実行ディレクトリと画像ファイルの相対パス関係を確認してください。入力ファイルと同じディレクトリから実行するか、絶対パスを指定します。 ```bash # 入力ファイルと同じディレクトリから実行すること cd docs/ mdd report.md # OK: images/ が同じディレクトリにある ``` -------------------------------- ### Markdown サンプルファイルの変換実行 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 上記 Markdown サンプルファイル (`minimal.md`) を変換するコマンドです。出力ファイル名を `report.docx` と指定しています。 ```bash mdd minimal.md -o report.docx ``` -------------------------------- ### md2docx のインストール Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md Rust 1.70 以上が必要です。リポジトリをクローンし、Cargo を使用してインストールします。ビルドのみを行うことも可能です。 ```bash git clone https://github.com/nokonoko1203/md2docx.git cd md2docx # Cargo でインストール cargo install --path . # または、ビルドのみ cargo build --release ``` -------------------------------- ### Config::load Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Loads configuration from a TOML file. This method constructs a `Config` instance by reading settings from a specified TOML file. It returns an `Err` if the file does not exist or if there's a TOML parsing error. ```APIDOC ## Config::load ### Description Loads configuration from a TOML file. This method constructs a `Config` instance by reading settings from a specified TOML file. It returns an `Err` if the file does not exist or if there's a TOML parsing error. ### Method `load` ### Parameters #### Path Parameters - **path** (`&Path`) - Required - The path to the TOML configuration file. ### Return Value `Result` - Returns a `Config` instance on success. ### Usage Example ```rust let config = Config::load(Path::new("config.toml"))?; ``` ``` -------------------------------- ### 設定ファイルを使用して変換 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md `-c` オプションで TOML 形式の設定ファイルを指定し、出力ファイル名を `-o` で指定して変換します。 ```bash mdd document.md -c config.toml -o output.docx ``` -------------------------------- ### カスタム設定ファイル例 (custom.toml) Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md フォント、サイズ、ページ設定、箇条書き記号、番号付けフォーマットなどをカスタマイズするための TOML 設定ファイルの例です。 ```toml [fonts] body_ja = "HGS創英角ポップ体" body_en = "Times New Roman" heading_ja = "HGS創英角ポップ体" heading_en = "Times New Roman" [sizes] body = 11.0 heading1 = 15.0 heading2 = 13.0 [page] width = 11906 margin_top = 2000 margin_left = 2000 margin_right = 2000 [bullet] level0 = "▪" level1 = "◦" [numbering] figure_format = "chapter" table_format = "chapter" ``` -------------------------------- ### 出力先ファイルを指定して変換 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md `-o` オプションを使用して、出力する DOCX ファイル名を指定できます。 ```bash mdd document.md -o report.docx ``` -------------------------------- ### Batch Convert Markdown Files with Configuration Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/README.md Use a shell script to iterate through all Markdown files in the current directory and convert them to DOCX format using the 'mdd' command with a specified configuration file. This is useful for processing multiple files simultaneously. ```bash for md in *.md; do mdd "$md" -c config.toml done ``` -------------------------------- ### 表番号の重複解消 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 表番号の重複は、`sequential` と `chapter` のような異なる番号付けフォーマットが混在している場合に発生します。設定ファイルでフォーマットを統一してください。 ```toml [numbering] figure_format = "sequential" table_format = "sequential" # または figure_format = "chapter" table_format = "chapter" ``` -------------------------------- ### Build mdd Release Binary Source: https://github.com/nokonoko1203/md2docx/blob/main/README.md Build the release version of the mdd binary. The executable will be located in `target/release/mdd`. ```sh cargo build --release ``` -------------------------------- ### GFM Table Syntax Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/feature-overview.md Use GitHub Flavored Markdown syntax with pipes (|) to separate columns for creating tables. ```markdown | ヘッダー1 | ヘッダー2 | |----------|----------| | セル1 | セル2 | | セル3 | セル4 | ``` -------------------------------- ### Load Config from TOML Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Loads configuration from a TOML file. Returns an error if the file does not exist or if there's a TOML parsing error. ```rust pub fn load(path: &Path) -> Result ``` ```rust let config = Config::load(Path::new("config.toml"))?; ``` -------------------------------- ### パターン 5: Markdown で改ページを挿入 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md Markdown ファイル内で `\pagebreak` を使用すると、その位置で強制的に改ページが行われ、次のコンテンツが新しいページから開始されます。 ```markdown # 第1部 内容... \pagebreak # 第2部 新しいページから始まる内容... \pagebreak # 第3部 さらに新しいページ... ``` -------------------------------- ### Default Config Implementation Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Provides a default instance of the Config struct with all fields set to their default values. ```rust impl Default for Config ``` -------------------------------- ### Configure Page Margins in TOML Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/feature-overview.md Set page margins including top, bottom, left, right, header, footer, and gutter using TOML configuration. Values are in twips. ```toml [page] margin_top = 1985 # 上 margin_bottom = 1701 # 下 margin_left = 1701 # 左 margin_right = 1701 # 右 margin_header = 851 # ヘッダー区間 margin_footer = 992 # フッター区間 margin_gutter = 0 # とじしろ ``` -------------------------------- ### Markdown サンプル Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 変換対象となる Markdown ファイルの例です。見出し、リスト、表、コードブロック、リンクなどが含まれています。 ```markdown # 第1章 プロジェクト概要です。 ## 背景 - 要件1 - 要件2 - 詳細a - 詳細b | 項目 | 値 | |------|-----| | 名前 | 値1 | | 説明 | 値2 | ### 実装 ```rust fn main() { println!("Hello, World!"); } ``` 詳細は [Rust 公式](https://www.rust-lang.org/) を参照。 ``` ``` -------------------------------- ### Basic mdd Conversion Source: https://github.com/nokonoko1203/md2docx/blob/main/README.md Convert a Markdown file to DOCX. The output file will be named 'document.docx' by default. ```sh mdd document.md ``` -------------------------------- ### Specify Output File for mdd Source: https://github.com/nokonoko1203/md2docx/blob/main/README.md Convert a Markdown file and specify a custom name for the output DOCX file using the -o or --output option. ```sh mdd document.md -o output.docx ``` -------------------------------- ### Add mdd to PATH Source: https://github.com/nokonoko1203/md2docx/blob/main/README.md Add the mdd binary directory to your system's PATH environment variable if it's not already there. This allows you to run the 'mdd' command from any directory. ```sh export PATH="$HOME/.cargo/bin:$PATH" ``` -------------------------------- ### md2docx Processing Flow Diagram Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/architecture.md This diagram illustrates the step-by-step process of the md2docx tool, from input files to the final Docx output. ```text ┌─────────────────────────────────────────────┐ │ Markdown ファイル入力 & TOML 設定ファイル │ └─────────────────────┬───────────────────────┘ │ ▼ ┌───────────────────────┐ │ main.rs: CLI 解析 │ │ (clap) │ └───────────┬───────────┘ │ ┌─────────────┼─────────────┐ │ │ │ ▼ ▼ ▼ 入力MD 設定TOML ベースパス 読み込み 読み込み 決定 │ │ │ └─────────────┼─────────────┘ │ ▼ ┌───────────────────────┐ │ parser.rs │ │ Markdown → IR │ │ (pulldown_cmark) │ └───────────┬───────────┘ │ ▼ ┌──────────────────────────┐ │ IR: Vec │ │ Block, Inline, ListItem, │ │ Alignment, ... │ └───────────┬──────────────┘ │ ▼ ┌──────────────────────────┐ │ converter.rs │ │ IR → Docx │ │ (docx_rs, image) │ │ │ │ - 見出し番号管理 │ │ (heading.rs) │ │ - スタイル適用 │ │ (styles.rs) │ │ - 図・表番号管理 │ │ - 画像スケーリング │ └───────────┬──────────────┘ │ ▼ ┌──────────────────────────┐ │ Docx インスタンス │ │ (docx_rs) │ └───────────┬──────────────┘ │ ▼ ┌──────────────────────────┐ │ Docx::build().pack() │ │ (ZIP 圧縮 & XML 出力) │ └───────────┬──────────────┘ │ ▼ ┌──────────────────────────┐ │ output.docx ファイル生成 │ └───────────┘ ``` -------------------------------- ### 改ページエラーの修正方法 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md `\pagebreak` が段落内に混在しているとエラーが発生します。改ページは独立した行に記述してください。 ```markdown #間違い 本文 \pagebreak 続き # 正しい 本文 \pagebreak 続き ``` -------------------------------- ### Config Struct Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md The main configuration structure that holds all conversion settings. It aggregates settings for fonts, sizes, page layout, indentation, bullets, and numbering formats. ```APIDOC ## Config Struct ### Description The main configuration structure that holds all conversion settings. It aggregates settings for fonts, sizes, page layout, indentation, bullets, and numbering formats. ### Fields - **fonts** (`FontConfig`) - Holds font settings for body and headings in Japanese and English. - **sizes** (`SizeConfig`) - Holds font size settings for body, tables, and headings. - **page** (`PageConfig`) - Holds page layout settings. - **indent** (`IndentConfig`) - Holds indentation settings. - **bullet** (`BulletConfig`) - Holds bullet point formatting settings. - **numbering** (`NumberingConfig`) - Holds numbering list formatting settings. ### Default Implementation A `Default` implementation is available, allowing you to create a `Config` instance with default values using `Config::default()`. ``` -------------------------------- ### Numbering Configuration Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Define numbering formats for figures and tables. Options include 'sequential' for simple numbering or 'chapter' for chapter-based numbering. ```rust pub struct NumberingConfig { pub figure_format: String, // デフォルト: "sequential" pub table_format: String, // デフォルト: "sequential" } ``` -------------------------------- ### Block 列挙体の定義 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/types.md Markdown ドキュメントの構造を表す最上位の中間表現。各バリアントはドキュメント内の論理的なブロック要素に対応します。 ```rust pub enum Block { Heading { level: u8, content: Vec, }, PageBreak, Paragraph { content: Vec, }, BulletList { items: Vec, }, OrderedList { items: Vec, start: u64, }, Table { headers: Vec>, rows: Vec>>, alignments: Vec, }, CodeBlock { lang: Option, code: String, }, Image { alt: String, path: String, }, BlockQuote { children: Vec, }, ThematicBreak, } ``` -------------------------------- ### 画像挿入時の絶対パス指定 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 相対パスの問題を避けるため、Markdown 内で画像の絶対パスを指定することも可能です。 ```markdown ![alt](/absolute/path/to/image.png) ``` -------------------------------- ### PageConfig Structure Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Defines the page dimensions and margins in twip units. Defaults to A4 portrait. ```rust pub struct PageConfig { pub width: u32, // デフォルト: 11906 pub height: u32, // デフォルト: 16838 pub margin_top: i32, // デフォルト: 1985 pub margin_right: i32, // デフォルト: 1701 pub margin_bottom: i32, // デフォルト: 1701 pub margin_left: i32, // デフォルト: 1701 pub margin_header: i32, // デフォルト: 851 pub margin_footer: i32, // デフォルト: 992 pub margin_gutter: i32, // デフォルト: 0 } ``` -------------------------------- ### パターン 4: Markdown でカスタム章番号を指定 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md Markdown ファイル内で `# 5 カスタム章番号` のように記述することで、以降の見出しの自動採番を特定の番号から開始させることができます。 ```markdown # 5 カスタム章番号 以降の自動採番は 5 から始まり、6, 7, … になる ``` -------------------------------- ### Config Structure Signature Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md The main configuration structure that holds all conversion settings. It aggregates settings for fonts, sizes, page layout, indentation, bullets, and numbering. ```rust pub struct Config { pub fonts: FontConfig, pub sizes: SizeConfig, pub page: PageConfig, pub indent: IndentConfig, pub bullet: BulletConfig, pub numbering: NumberingConfig, } ``` -------------------------------- ### プロジェクトディレクトリ構成例 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md Markdown ファイル、設定ファイル、出力ディレクトリ、画像ファイルなどを含む典型的なプロジェクトディレクトリの構成例です。 ```text project/ ├── README.md ├── config.toml # 共有設定ファイル ├── docs/ │ ├── introduction.md │ ├── features.md │ ├── architecture.md │ └── images/ │ ├── diagram1.png │ ├── screenshot.jpg │ └── flowchart.svg # 自動 PNG 変換される └── output/ ├── introduction.docx ├── features.docx └── architecture.docx ``` -------------------------------- ### Markdown Heading Conversion Data Flow Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/architecture.md Illustrates the process of converting a markdown heading to a Word document heading, including parsing, numbering management, and style application. ```text Markdown: "1 プロジェクト概要" ↓ Parser: Block::Heading { level: 1, content: [Text("1 プロジェクト概要")] } ↓ Converter: 1. heading_mgr.next_heading(1, content) → "1" を検出、テキストを同期 2. strip_number(1, "1 プロジェクト概要") → "プロジェクト概要" 抽出 3. Word Paragraph にスタイル "1" 適用、numbering ID=2, ilvl=0 ↓ Word: 見出し1、自動番号付き "1 プロジェクト概要" ``` -------------------------------- ### Convert IR Blocks to DOCX Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-converter.md Converts a sequence of IR blocks into a Docx object using the provided configuration and base path. This function handles automatic numbering, image scaling, and table formatting. It returns a `Docx` object that can be packed into a .docx file. ```rust use md2docx::converter::convert_to_docx; use md2docx::config::Config; use md2docx::parser::parse_markdown; use std::path::Path; let markdown = "# 見出し\n\n本文です。\n\n![図](img.png)"; let blocks = parse_markdown(markdown)?; let config = Config::load(Path::new("config.toml")).unwrap_or_default(); let docx = convert_to_docx(&blocks, &config, Path::new("."))?; let file = std::fs::File::create("output.docx")?; docx.build().pack(file)?; ``` -------------------------------- ### SizeConfig Struct Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Defines the font sizes for body text, tables, and different heading levels in points (pt). This allows fine-grained control over text scaling within the document. ```APIDOC ## SizeConfig Struct ### Description Defines the font sizes for body text, tables, and different heading levels in points (pt). This allows fine-grained control over text scaling within the document. ### Fields - **body** (`f64`) - Default: 10.5 - Font size for body text (pt). - **table_body** (`f64`) - Default: 9.5 - Font size for table body text (pt). - **table_header** (`f64`) - Default: 9.5 - Font size for table header text (pt). - **heading1** (`f64`) - Default: 14.0 - Font size for heading level 1 (pt). - **heading2** (`f64`) - Default: 12.0 - Font size for heading level 2 (pt). - **heading3** (`f64`) - Default: 11.0 - Font size for heading level 3 (pt). - **heading4** (`f64`) - Default: 11.0 - Font size for heading level 4 (pt). - **heading5** (`f64`) - Default: 10.5 - Font size for heading level 5 (pt). ### Usage Example (TOML) ```toml [sizes] body = 11.0 heading1 = 15.0 heading2 = 13.0 ``` ``` -------------------------------- ### SizeConfig Structure Signature Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Specifies font sizes in points (pt) for body text, table elements, and different heading levels. ```rust pub struct SizeConfig { pub body: f64, pub table_body: f64, pub table_header: f64, pub heading1: f64, pub heading2: f64, pub heading3: f64, pub heading4: f64, pub heading5: f64, } ``` -------------------------------- ### convert_to_docx Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-converter.md Converts a sequence of intermediate representation (IR) blocks and configuration into Word (.docx) format, returning a Docx object. It automatically handles heading numbering, image scaling, and table numbering. ```APIDOC ## convert_to_docx Converts a sequence of intermediate representation (IR) blocks and configuration into Word (.docx) format, returning a Docx object. It automatically handles heading numbering, image scaling, and table numbering. ### Signature ```rust pub fn convert_to_docx(blocks: &[Block], config: &Config, base_path: &Path) -> Result ``` ### Parameters #### Path Parameters - **blocks** (*&[Block]*) - Required - IR block sequence obtained from `parse_markdown()` - **config** (*&Config*) - Required - Configuration object specifying font, page settings, indentation, bullet points, and numbering format - **base_path** (*&Path*) - Required - Base directory used for resolving relative paths (e.g., images). Typically the parent directory of the input Markdown file. ### Response #### Success Response - **Docx** (*Docx*) - A Docx object (docx_rs type) that can be written to a .docx file using `Docx::build().pack(file)`. #### Error Response - **Image Loading Failure**: If an image file at the specified path cannot be loaded. This is output as a warning to stderr, and `[Image: alt]` text is inserted into the document. - **Image Format Conversion Failure**: If conversion to PNG fails. Similar to loading failure, a warning is output, and alternative text is used. ### Request Example ```rust use md2docx::converter::convert_to_docx; use md2docx::config::Config; use md2docx::parser::parse_markdown; use std::path::Path; let markdown = "# Heading\n\nThis is the body text.\n\n![Figure](img.png)"; let blocks = parse_markdown(markdown)?; let config = Config::load(Path::new("config.toml")).unwrap_or_default(); let docx = convert_to_docx(&blocks, &config, Path::new("."))?; let file = std::fs::File::create("output.docx")?; docx.build().pack(file)?; ``` ``` -------------------------------- ### Markdown Image Conversion Data Flow Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/architecture.md Details the steps involved in converting a markdown image to a Word document image with automatic numbering and scaling. ```text Markdown: "![図説](img.png)" ↓ Parser: Block::Image { alt: "図説", path: "img.png" } ↓ Converter: 1. base_path と path を結合 → 絶対パス生成 2. 画像ファイルを読み込み 3. image クレートで PNG に変換 4. ページ幅に合わせてスケーリング(アスペクト比保持) 5. docx_rs で Pic オブジェクト生成 6. 図番号: chapter モード なら "図1.1", sequential なら "図1" を付与 ↓ Word: センター揃え画像 + 図番号キャプション ``` -------------------------------- ### フォント設定の注意点 Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/quick-start.md 指定したフォントがシステムにインストールされていない場合、フォントが正しく反映されません。より汎用的なフォント(例: Noto Sans JP)の使用を検討してください。 ```toml [fonts] body_ja = "Noto Sans JP" # Google Fonts など、より汎用的なフォント heading_ja = "Noto Sans JP" ``` -------------------------------- ### Markdown Heading with Existing Number Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/feature-overview.md Demonstrates how to specify an existing number for a H1 heading. The automatic numbering will continue from this specified number. ```markdown # 8 既存番号がある場合 自動採番は 8 から始まり、次の H1 は 9 になる ``` -------------------------------- ### IndentConfig Structure Source: https://github.com/nokonoko1203/md2docx/blob/main/_autodocs/api-reference-config.md Defines indentation settings for paragraphs and headings at each level, in twip units or character units. ```rust pub struct IndentConfig { pub body_left: i32, // デフォルト: 210 pub body_first_line: i32, // デフォルト: 210 pub body_right: i32, // デフォルト: 210 pub body_left_chars: i32, // デフォルト: 100 pub heading1_left: i32, // デフォルト: 420 pub heading1_hanging: i32, // デフォルト: 420 pub heading2_left: i32, // デフォルト: 612 pub heading2_hanging: i32, // デフォルト: 612 pub heading3_left: i32, // デフォルト: 783 pub heading3_hanging: i32, // デフォルト: 783 pub heading4_left: i32, // デフォルト: 709 pub heading4_hanging: i32, // デフォルト: 709 pub heading5_left: i32, // デフォルト: 709 pub heading5_hanging: i32, // デフォルト: 709 pub heading6_left: i32, // デフォルト: 709 pub heading6_hanging: i32, // デフォルト: 709 } ```