Dimitar Roszenov Ruszev Dimitar Roszenov Ruszev - 5 months ago 12x
HTML Question

Handlebars wraps <!DOCTYPE html>

I am trying to get my

setup working, nothing fancy.

In my
I have:

handlebars.registerHelper('doctype', function() {
return new handlebars.SafeString('<!DOCTYPE html>');

in my partial template
I have:


And the result html begins with:

<p>&lt;!DOCTYPE html&gt;</p>

– which is obviously not what I need.

Any suggestions?

PS. Using a plain doctype definition in my layout file had the same effect. Using
handlebars ^4.0.5

Edit 1:
After trying around a bit, i can supply another symptom: The result of a
call seems to be wrapped in a
tag if it is placed before the
block. This is not specific to the doctype declaration, »normal« html elements seem to be affected as well.

Edit 2:
Now i have distilled 2x2 cases for the functioning of

a) a conventional element (e.g.
) inside the
block gets rendered, as expected, without changes.

b) a conventional element before the
block gets rendered ok, but is placed inside a

c) a doctype element inside the
block gets rendered as pure text, like this:
&lt;!DOCTYPE html&gt;

d) a doctype element before the
block will be rendered in the same manner but wrapped in a


Seems to be a metalsmith-related matter, not inherent to handlebars. A given (erroneous!) order of plugin invocations causes the issue: calling use(layouts(…)) before calling use(markdown(…)) is the cause. (so probably the markdown plugin does the wrapping.) Sorry for the trouble.