I just took a look at your example, and your main issue was that you
have to separate the HTML <body> with the <head>. Here is a hackish
way to achieve that (using regular expressions, which is not
reliable):
ehtml = function(content) {
content = htmltools::HTML(gsub('^.*?<body\\s*>|</body>.*$', '', content))
d = htmltools::htmlDependency(
'TeX4ht', '1.0.0', src = getwd(), stylesheet = 'summarym-enclosed.css')
htmltools::attachDependencies(content, d)
}
Note summarym-enclosed.css was hard-coded in the function, and you'd
better replace it with a filename automatically elicited from the
HTML. I'm not sure if there is a way for htlatex to produce the body
and css separately, so you don't have to hack at the generated HTML.