HTML Viewer
html-viewer demonstrates the complete path from a filesystem-backed HTML file to styled terminal output.
It reads the file with Path and PathContent, parses the text with text::html::HtmlParser into a
text::TextDocument, and renders the document with TerminalDocumentRenderer into a scrollable CursorBuffer.
Use This Demo When You Need…
A complete example for loading text files through the Core path APIs.
A practical reference for turning HTML into
TextDocumenttrees.A terminal viewer that scrolls rendered document content with
CursorBufferandBufferView.
Run the Demo
Start the demo from the build directory:
$ ./cmake-build-debug/demo-apps/cterm/html-viewer
Use the arrow keys to scroll, page up and page down to move by pages, S to cycle the document style, and Q or
Esc to quit.
You can pass your own input file and render once into standard output:
$ ./cmake-build-debug/demo-apps/cterm/html-viewer --print --style=simple my-document.html
Captured Output (80x25)
HTML Parser and TextDocument Demo
This demo reads an HTML file through Path and PathContent, parses it with
HtmlParser, stores the result in a TextDocument, and renders that document into
a scrollable terminal buffer. Use the cursor keys to move line by line, page up
and page down to jump, press s to cycle between document styles, and press q
when you want to quit.
What This Demonstrates
• Reading UTF-8 text with Path::content().readTextOrThrow().
• Converting an HTML fragment or document into a semantic TextDocument.
• Rendering headings, paragraphs, emphasis, strong text, links, lists, and
code blocks.
• Keeping the rendered document in a CursorBuffer for scrolling.
Pipeline
1. Convert the command-line file argument into a Core Path.
2. Read the file content as an el::String.
3. Parse the HTML into a TextDocument.
‣ Document boilerplate such as head is ignored.
‣ Malformed tags are recovered as text where possible.
4. Render the semantic document to terminal cells.
Definition List
HtmlParser
The tolerant parser that converts HTML input into a TextDocument.
TextDocument
The mutable tree of document nodes used by the text and terminal renderers.
TerminalDocumentRenderer
The renderer that writes TextDocument nodes to a CursorWriter.
CursorBuffer
The terminal buffer that stores rendered output and can grow vertically.
Code Block
auto html = path.content().readTextOrThrow();
auto document = el::html::HtmlParser{el::AnyString{html}}.parse();
el::TerminalDocumentRenderer{}.renderTo(buffer, document);
--------------------------------------------------------------------------------
Links render as link text only, for example erbsland.dev. The source file for
this document lives in the demo directory, and you can pass your own HTML file
as the optional command-line argument.
Features Demonstrated
Path::fromNativeOrThrow()andPathContent::readTextOrThrow()for file input.HtmlParseras the public tolerant HTML parser.TextDocumentas the semantic document tree shared between parser and renderer.TerminalDocumentRendererwith the plain, simple, and styled default document styles.CursorBufferplusBufferViewfor a retained scrollable document viewport.
Relevant Source Files
If you want to explore the implementation, start with demos/cterm/HtmlViewer/src/HtmlViewerApp.cpp.
This file contains the option setup, Core path-based file loading, HTML parsing, document rendering, and viewport navigation.