Skip to content

PlateauPerspectives/docx2navTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

docx2navTree - Document to Structured JSON Converter

License: GPL v3 Python 3.8+

Convert Microsoft Word documents into structured JSON content suitable for web applications, content management systems, or RAG (Retrieval-Augmented Generation) pipelines.

Features

  • Multi-language support - Process books in multiple languages from a single repo
  • Automatic TOC extraction - Identifies chapters and sections from Table of Contents
  • NavTree v2 output - Structured JSON with per-node metadata (index.toml)
  • Image extraction - Extracts all images including WMF to PNG conversion
  • Table processing - Preserves complex table structures
  • Markdown export - Optional parallel Markdown output

How This Repo Works

This is a template repository. It contains the build tools but no content.

To use it with your own documents, fork it to a private repository and add your content there. The .gitignore is structured so you can easily enable content tracking in your fork.

Quick Start (Template)

Use the included sample document to verify the toolchain works:

make install-deps
make build

Setting Up Your Fork

  1. Fork this repo to your own (private) GitHub account
  2. Edit .gitignore β€” remove the first section labeled "Content files β€” TEMPLATE ONLY"
  3. Add your content to lang-store/<lang>/ (see below)
  4. Commit your content files β€” they are now tracked in your private fork

.gitignore Structure

The .gitignore has three clearly marked sections:

Section Template repo Your fork
Content files β€” TEMPLATE ONLY Ignored Remove this section to track content
Generated output Ignored Keep ignored
Standard ignores Ignored Keep ignored

Content Organization

All source content lives under lang-store/, organized by language:

lang-store/
β”œβ”€β”€ eng/
β”‚   β”œβ”€β”€ book_config.toml       # Book metadata and settings
β”‚   β”œβ”€β”€ original-book.docx     # Source Word document
β”‚   └── exceptions.eng.conf    # TOC numbering fixes (optional)
β”œβ”€β”€ fra/
β”‚   β”œβ”€β”€ book_config.toml
β”‚   β”œβ”€β”€ source-document.docx
β”‚   └── cover.png
└── rus/
    β”œβ”€β”€ book_config.toml
    β”œβ”€β”€ source-document.docx
    └── exceptions.rus.conf

The build system auto-discovers files in each language directory.

Book Configuration

Each language needs a book_config.toml. Copy from book_config.toml.example:

canonical_id = "my-book-title"
language = "eng"
title = "My Book Title"
is_original = true
pictures_location = "root"

If title is left empty, it will be extracted from the DOCX metadata or first paragraph.

Building

# Build a specific language (default: eng)
make build L=eng
make build L=fra

# Build with images
make all L=eng

# See available languages
make help

Output Structure (NavTree v2)

Generated output goes to export/ (JSON) and export_md/ (Markdown) β€” both are gitignored.

The folder hierarchy IS the navigation tree. Each section gets its own folder with index.toml (metadata) and content.json (content blocks).

export/
β”œβ”€β”€ {lang}/
β”‚   └── {book_id}/
β”‚       β”œβ”€β”€ config.toml                 # Global settings
β”‚       β”œβ”€β”€ search-positions.json       # content_id β†’ tree positions
β”‚       β”œβ”€β”€ 01/                         # Chapter 1
β”‚       β”‚   β”œβ”€β”€ index.toml              # Chapter metadata
β”‚       β”‚   β”œβ”€β”€ content.json            # Chapter intro content
β”‚       β”‚   β”œβ”€β”€ 01/                     # Section 1.1
β”‚       β”‚   β”‚   β”œβ”€β”€ index.toml
β”‚       β”‚   β”‚   β”œβ”€β”€ content.json
β”‚       β”‚   β”‚   └── 01/                 # Subsection 1.1.1
β”‚       β”‚   β”‚       β”œβ”€β”€ index.toml
β”‚       β”‚   β”‚       └── content.json
β”‚       β”‚   └── 02/                     # Section 1.2
β”‚       β”‚       β”œβ”€β”€ index.toml
β”‚       β”‚       └── content.json
β”‚       └── 02/                         # Chapter 2
└── pictures/
    └── {lang}/
        └── {book_id}/
            └── 01/
                └── 01/
                    └── 001.png

export_md/                              # Parallel Markdown export
└── {lang}/
    β”œβ”€β”€ README.md
    β”œβ”€β”€ style.css
    └── 01/
        β”œβ”€β”€ intro.md
        └── 01.md

See docs/navtree-v2-format.md for the full format specification.

Make Commands

make build           # Build JSON/Markdown for one language
make all             # Build JSON/Markdown + extract images
make rebuild-all     # Clean and rebuild from scratch
make clean           # Remove generated files
make check-deps      # Verify dependencies installed
make verify          # Check image integrity
make status          # Show project status
make stats           # Display content statistics

Use L=<lang> to select language: make build L=fra

System Requirements

  • Python 3.8+ with python-docx
  • ImageMagick 7+ - Image processing
  • Ghostscript - PDF to PNG conversion
  • LibreOffice - WMF to PDF conversion (optional, for Windows Metafile images)

Installation

macOS:

brew install imagemagick ghostscript
brew install --cask libreoffice
make install-deps

Linux (Ubuntu/Debian):

sudo apt-get install imagemagick ghostscript libreoffice python3-pip
make install-deps

Document Preparation

Important: Convert automatic numbering to fixed text before processing.

Word/LibreOffice automatic numbering stores section numbers invisibly, causing missing sections in the output.

Quick Fix:

Exception Handling

If your document has known numbering inconsistencies, create an exceptions file in your language directory (e.g., lang-store/eng/exceptions.eng.conf):

# Format: wrong_number = correct_number
10.7.7 = 10.7.5
21.4.3 = 21.2.3

Documentation

License

GNU General Public License v3.0 (GPL-3.0) - See LICENSE file.

About

πŸš€ Automated system to convert Microsoft Word documents into interactive web-based readers. Extracts chapters, sections, images, and tables into optimized JSON with a React viewer. Perfect for large documents like handbooks and manuals.

Topics

Resources

License

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors