Skip to content

feat: Implement book doctype support in converters #312

@nlopes

Description

@nlopes

Summary

The book doctype is recognized by the parser and converters, but the only book-specific behavior currently implemented is setting <body class="book"> in HTML output. All other book-specific features (parts, chapters, special sections) are missing.

Current State

  • Doctype::Book enum exists in converters/core/src/doctype.rs
  • HTML converter outputs <body class="book"> when doctype is book
  • No other book-specific behavior is implemented

What's Missing

Feature Description
Level 0 sections Parser rejects = Part Title syntax (parts)
Chapter detection Level 1 sections not treated as chapters
:chapter-signifier: Attribute not recognized or used
:partnums: / :part-signifier: Attributes ignored
Chapter numbering :sectnums: doesn't number chapters with signifier
Special sections Preface, dedication, colophon not recognized

Implementation Plan

Phase 1: Level 0 Section Support (Parts)

Goal: Allow parsing and rendering level 0 sections (parts) when doctype=book

Parser changes (acdc-parser/src/grammar/document.rs):

  • Currently level 0 sections are rejected after document title
  • Need to allow = Part Title syntax when doctype=book
  • Options: Pass doctype through parsing context, or accept level 0 and validate during conversion

Converter changes (converters/html/src/section.rs):

match (section.level, doctype) {
    (0, Doctype::Book) => {
        // Render as part: <div class="sect0"><h1>Part Title</h1>...</div>
    }
    // ... existing handling
}

Success criteria:

  • Level 0 sections parse without error when doctype=book
  • Parts render with <div class="sect0"> and <h1>
  • Article doctype continues to reject level 0 sections

Phase 2: Chapter Detection & Rendering

Goal: Recognize level 1 sections as chapters in book doctype, support chapter signifier

Changes needed:

  1. Add chapter-signifier to default attributes (converters/core/src/lib.rs)
  2. Detect chapters: level 1 + doctype=book
  3. Render chapter titles with signifier when :sectnums: enabled:
    <h2>Chapter 1. Introduction</h2>
  4. Add chapter CSS class: <div class="sect1 chapter">

Success criteria:

  • Level 1 sections in book mode render with chapter signifier
  • Chapter numbering works with :sectnums:
  • Custom :chapter-signifier: values respected

Phase 3: Multi-Part Structure

Goal: Support books organized into parts with chapters

Changes needed:

  1. Part introduction handling - content between part title and first chapter
  2. Part-level numbering state tracking
  3. Support for :partnums: and :part-signifier: attributes
  4. Chapter numbering options:
    • Continuous across parts (Ch 1, 2, 3 in Part I; Ch 4, 5, 6 in Part II)
    • Or reset per part (match asciidoctor behavior)

Success criteria:

  • Books with level 0 sections render as multi-part
  • Part introductions appear before first chapter
  • Chapter numbering works correctly across parts

Phase 4: Special Sections

Goal: Recognize and render special section types

Special section types to support:

  • [preface] - Preface section
  • [dedication] - Dedication section
  • [colophon] - Colophon section (book-specific)
  • [appendix] - Appendix sections

Changes needed:

  1. Detect special sections by style attribute
  2. Apply appropriate CSS classes
  3. Handle level 0 special sections (auto-adjust to level 1 per AsciiDoctor spec)

Success criteria:

  • Special sections identified and marked with appropriate CSS classes
  • Level 0 special sections treated as level 1
  • All special section types supported

Key Files to Modify

  • acdc-parser/src/grammar/document.rs - Level 0 section parsing
  • acdc-parser/src/model/mod.rs - Potentially add SectionType enum
  • converters/html/src/section.rs - Chapter/part rendering
  • converters/html/src/html_visitor.rs - State tracking for numbering
  • converters/core/src/lib.rs - Default attributes (chapter-signifier)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions