Skip to content

⚒ Simple, lightweight, customizable (X)HTML and XML formatter / beautifier

License

Notifications You must be signed in to change notification settings

Machy8/xhtml-formatter

Repository files navigation

XML + (X)HTML formatter / beautifier

Build Status

Installation

composer require machy8/xhtml-formatter

Usage

Compiles this 💩

<!DOCTYPE html>
<html lang="en">
    <head><meta charset="utf-8"><title>title</title>
    <link rel="stylesheet" href="style.css">
<script src="script.js"></script></head><body><!-- page content --></body></html>

into this 😱😭

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>
			title
		</title>
		<link rel="stylesheet" href="style.css">
		<script src="script.js"></script>
	</head>
	<body>
		<!-- page content -->
	</body>
</html>

and all you need is

use XhtmlFormatter\Formatter;

$formatter = new Formatter();

$output = $formatter->format($string);

and if you want to disable formatting

<div>
	<formatter-off>
		<p>
			<b>Unformatted code goes <u>here</u></b>!
		</p>
	</formatter-off>
</div>

Setup

$formatter

	// Change the content type from CONTENT_HTML (default) to CONTENT_XML or CONTENT_XHTML
	->setContentType(Formatter::CONTENT_XML)

	// Add new unpaired element
	->addUnpairedElement('element', Formatter::CONTENT_XML)

	// Add skipped elements
	->addSkippedElement('elementA elementB')

	// Indent file by 4 spaces instead of tabs
	->setSpacesIndentationMethod(4);

About

⚒ Simple, lightweight, customizable (X)HTML and XML formatter / beautifier

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages