@phtml/doctype

4.1.0 • Public • Published

pHTML Doctype pHTML

NPM Version Build Status Support Chat

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 or HTML 5
  • HTML 4 or HTML 4.01 Strict
  • HTML 4.01 Transitional
  • HTML 4.01 Frameset
  • XHTML or XHTML 1.1
  • XHTML 1 or XHTML 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>

Package Sidebar

Install

npm i @phtml/doctype

Weekly Downloads

0

Version

4.1.0

License

CC0-1.0

Unpacked Size

30.6 kB

Total Files

8

Last publish

Collaborators

  • jonathantneal