{h1: Text formatting, an experiment} Ever since I started writing Bitter, I've been wondering how to apply functional programming concepts to creating a better text formatter. Before continuing, make sure you have read my {a @href /bitter-syntax-highlighter: introduction to the Bitter syntax highlighter} as it contains some important ideas on which I will be elaborating in this article. For now I'm going to call this idea for a language 'Terror', as it's a text formatter and probably going to be full of errors. {h1: What would it look like?} Obviously the syntax cannot be identical to Bitter, as all Bitter needs to do is wrap pieces of text with 'tags'. Here, we actually need a way to define HTML. So I've introduced three new functions: {dl: {dt: {code: element(name)}} {dd: Define a new element} {dt: {code: attribute(name, value)}} {dd: Define a new attribute} {dt: {code: text(value)}} {dd: Define a new text node} } Each {code: name} or {code: value} accepts a string, possibly containing references to matched data: {code: attribute('class', '$1')}. {pre.language-php: } So, as you can see, this example looks for any Textile style headers, and creates elements to represent them. If you where to pass it this text: {pre: h1. Heading one h2. Heading two} Then you'd end up with this output: {pre.language-html: