@phtml/doctype
v4.1.0
Published
Automatically add the doctype in HTML
Downloads
3
Maintainers
Readme
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/doctype
Node
Add pHTML Doctype to your project:
npm install @phtml/doctype --save-dev
Use 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:
HTML
orHTML 5
HTML 4
orHTML 4.01 Strict
HTML 4.01 Transitional
HTML 4.01 Frameset
XHTML
orXHTML 1.1
XHTML 1
orXHTML 1.0 Strict
XHTML 1.0 Transitional
XHTML 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>