dita_writer Module

class dita_sop_converter.dita_writer.DitaWriter(output_dir)

Bases: object

Write DITA topics, maps, and media assets from in-memory models.

Responsibilities

  • Normalize topic IDs into file-safe, DITA-safe identifiers.

  • Serialize TopicModel objects to .dita files.

  • Serialize MapModel to a DITA map (.ditamap).

  • Persist image media referenced by ImageBlock instances.

This class is intentionally conservative: failures in image conversion should not prevent topic/map generation. Media problems are logged and fall back to pass-through behavior where possible.

Layout / step table semantics

  • TableBlock.kind == "layout-2col" in non-task topics is treated as a layout table that unwraps into sections/paragraphs.

  • layout-2col tables in TASK topics are further inspected for Step/Action headers. When detected, they are converted into <steps>/<step>/<cmd>/<info> structures and the original table is omitted from the DITA output.

write_map(map_model)

Serialize a MapModel as a DITA map .ditamap file.

The method normalizes the map ID, verifies referenced topics exist, and writes a standard DITA map DOCTYPE declaration.

Return type:

None

Parameters:

map_model (MapModel)

Parameters

map_model :

Populated MapModel with entries.

write_topics(topics)

Serialize all topics into topics/*.dita and return map entries.

Return type:

typing.List[dita_sop_converter.model.MapEntry]

Parameters:

topics (List[TopicModel])

Parameters

topics :

List of fully populated TopicModel instances.

Returns

list[MapEntry]

Map entries pointing at the topic files, in the same order.

Parameters:

output_dir (str)