realistschuckle/gohaml — Issue #4: Needs CDATA blocks (perhaps haml filters)
Author: bmatsuo
Created: 2011-11-21 16:28:51+00:00
State: open

Haml has [special blocks](http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#filters) for outputting javascript/css (and generic CDATA) blocks.

Bundled with these features is the ability to embed other markup styles.

Embedding other markup isn't very important, but CDATA blocks are nice in some circumstances where page-specific javascript is used. So, filter blocks might as well be implemented anyway.

I'd be willing to help implement this. I imagine an interface

```go
type Filter interface{
// content is indented and ends with "\n".
// output should be indented and end with "\n".
Filter(content, indent string) string
}
```

And so CDATA, css, and javascript blocks can all be implemented is simple functions

```go
func cdataHelper(pre, post, content, indent string) string {
return fmt.Sprintf("%s%s%s\n%s\n%s%s%s\n",indent, pre, post, content, indent, pre, post)
}

func cdata(content, indent string) string { return cdataHelper("", "", content, indent) }
func css(content, indent string) string {
return fmt.Sprintf(`%s\n`, indent, cdataHelper("", "", content, indent), indent)
}
func javascript(content, indent string) string {
return fmt.Sprintf(`%s\n`, indent, cdataHelper("", "", content, indent), indent)
}
```

The parsers could be usable in the parser via a map.

```go
type FilterMap map[string]func(input, indent string) string
```

Note: I haven't actually compiled any of this, so there could be some small errors.