diff --git a/README.md b/README.md index f0c4fbf1e6..ff493afba6 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,55 @@ The built-in formatters are: highlighted text for use in the terminal. `theme` must be an instance of `Rouge::Theme`, or a `Hash` structure with `:theme` entry. +#### Writing your own HTML formatter + +If the above formatters are not sufficient, and you wish to customize the layout +of the HTML document, we suggest writing your own HTML formatter. This can be +accomplished by subclassing `Rouge::Formatters::HTML` and overriding specific +methods: + +``` ruby +class MyFormatter < Rouge::Formatters::HTML + + # this is the main entry method. override this to customize the behavior of + # the HTML blob as a whole. it should receive an Enumerable of (token, value) + # pairs and yield out fragments of the resulting html string. see the docs + # for the methods available on Token. + def stream(tokens, &block) + yield "