0.0
No commit activity in last 3 years
No release in over 3 years
Easily implement an HTML renderer by creating a subclass and adding some methods, similar to RedCarpet. (Examples are included for rendering HTML to ANSI and plain text.)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

HTML Renderer

Overview

An extensible HTML renderer.

Comes with two built-in renderers:

  • HTMLRenderer::ANSI (outputs colored text to the termnial)
  • HTMLRenderer::Text (outputs plain text)

Usage

Render to ANSI:

ansi_text = HTMLRenderer::ANSI.render("<b>hello html</b>")
ansi_text = HTMLRenderer::ANSI.render(open("file.html"))

Render to plain text:

plain_text = HTMLRenderer::Text.render(open("file.html"))

Extending it

The API design uses the same philosophy as RedCarpet.

To create a new renderer, subclass HTMLRenderer::Base, then add a method to handle each type of element. Whatever the method returns is output by the renderer.

Example renderer: HTMLRenderer::ANSI