Reminds me of Edward Kmett's talks on monoidal parsing in which he has Dyck languages as an example.
I'm confused about the need for "linear types", unless you mean a monoid. I'm not sure of a use case where you would want a open fragment of html or a closed one other than to a have a hole, that is something like
f : HtmlBody -> HtmlBody
f x = someOpenFragment + x + someClosedFragment