@phtml/doctype v4.1.0
pHTML Doctype
pHTML Doctype lets you automatically add the doctype in HTML.
<html>
<title>pHTML Doctype</title>
</html>
<!-- becomes -->
<!doctype html><html>
<title>pHTML Doctype</title>
</html>Usage
Transform HTML files directly from the command line:
npx phtml source.html output.html -p @phtml/doctypeNode
Add pHTML Doctype to your project:
npm install @phtml/doctype --save-devUse pHTML Doctype to process your HTML:
const phtmlDoctype = require('@phtml/doctype');
phtmlDoctype.process(YOUR_HTML /*, processOptions, pluginOptions */);Or use it as a pHTML plugin:
const phtml = require('phtml');
const phtmlDoctype = require('@phtml/doctype');
phtml([
phtmlDoctype(/* pluginOptions */)
]).process(YOUR_HTML /*, processOptions */);pHTML Doctype runs in all Node environments, with special instructions for:
| Node | CLI | Eleventy | Gulp | Grunt |
|---|
Options
doctype
The doctype option specifies the doctype being added to the page.
phtmlDoctype({ doctype: 'html4' });<html>
<title>pHTML Doctype</title>
</html>
<!-- becomes -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<title>pHTML Doctype</title>
</html>Options include case-insensitive, space-insentive variations of the following:
HTMLorHTML 5HTML 4orHTML 4.01 StrictHTML 4.01 TransitionalHTML 4.01 FramesetXHTMLorXHTML 1.1XHTML 1orXHTML 1.0 StrictXHTML 1.0 TransitionalXHTML 1.0 Frameset
replace
The replace option determines whether the doctype will be replaced, whether
or not it exists.
phtmlDoctype({ replace: true });<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<title>pHTML Doctype</title>
</html>
<!-- becomes -->
<!doctype html>
<html>
<title>pHTML Doctype</title>
</html>Optionally, the replace option can be given a string, which will work as a
fallback to the doctype option.
safe
The safe option determines whether the doctype should only be included when a
top level html, head, or body tag is present. By default, this setting is
false and the doctype is added regardless.
phtmlDoctype({ safe: true });<custom-element></custom-element>
<!-- becomes -->
<custom-element></custom-element><html>
<custom-element></custom-element>
</html>
<!-- becomes -->
<!doctype html>
<html>
<custom-element></custom-element>
</html>