Package atessera.publ
Class HtmlTranslator
java.lang.Object
atessera.publ.HtmlTranslator
- All Implemented Interfaces:
AutoCloseable
Translates a
PublicationContent into a set of HTML chapter
files with resolved cross-references.
This translator produces HTML output suitable for web viewing. It employs a two-pass algorithm to resolve cross-references and auto-numbering before the final rendering:
- First pass (
fillRefs()) — scans all sections to collect labels and assign hierarchical numbers (chapter, section, subsection, equation, listing, figure). Builds internal maps:refs— maps a label to its human-readable number (e.g."1.2").refIds— maps a label to a random HTML anchor id.refChapNums— maps a label to the chapter number where it appears.biblio— maps a citation key to its formatted bibliography text.
- Second pass (
translate()) — renders each Markdown section through anHtmlTargetthat resolves references using the maps built in the first pass. The rendered content is split at chapter boundaries (determined by level-1 headings) and stored in theoutputmap, keyed by file name (e.g."Introduction.html","Chapter1.html").
Auto-numbering
Headings receive hierarchical numbers in Russian academic style:
- Level 1 → Глава~1., Глава~2., ...
- Level 2 → 1.1, 1.2, ...
- Level 3 → 1.1.1, 1.1.2, ...
Equations, listings, and figures within a chapter are numbered relative to that chapter (e.g. equation 1.1, 1.2, ...).
Cross-references
Regular references ([label]) are rendered as HTML links
(<a href="ChapterN.html#anchor">number</a>). Page references
are not yet supported and produce a placeholder.
Thread safety
Instances of this class are not thread-safe. Each
translation should use its own instance. The class implements
AutoCloseable for consistency, though no resources currently
require cleanup.
Typical usage
PublicationContent content = PublicationContent.fromJson(jsonString);
try (HtmlTranslator translator = new HtmlTranslator(content)) {
translator.translate();
// Access results via translator.output
}
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
HtmlTranslator
Constructs a new HTML translator.- Parameters:
publ- the publication content to translate; must not benull- Throws:
NullPointerException- ifpublisnullIOException
-
-
Method Details
-
close
public void close()No-op cleanup method required byAutoCloseable.- Specified by:
closein interfaceAutoCloseable
-