aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohsin Kaleem <mohkale@kisara.moe>2023-04-22 11:44:44 +0100
committerGitHub <noreply@github.com>2023-04-22 11:44:44 +0100
commit2686e7b17dcf5a003262644812a8620b2a1968e7 (patch)
treea105a81c0598494176b90d71c3128d9416f812c8
parent568862dc844217a2eb1fec763d4f70f9db59555a (diff)
Add html-tidy formatter (#173)
-rw-r--r--CHANGELOG.md2
-rw-r--r--apheleia.el16
-rw-r--r--test/formatters/installers/html-tidy.bash1
-rw-r--r--test/formatters/samplecode/html-tidy/in.html1
-rw-r--r--test/formatters/samplecode/html-tidy/out.html19
5 files changed, 39 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fbe0681..c19a978 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,12 +28,14 @@ The format is based on [Keep a Changelog].
for [Bazel Build](https://bazel.build/) ([#171]).
* [`cmake-format`](https://github.com/cheshirekow/cmake_format)
for [CMake](https://cmake.org/) ([#172]).
+* [`html-tidy`](https://www.html-tidy.org/) for HTML/XML ([#173]).
[#168]: https://github.com/radian-software/apheleia/pull/168
[#169]: https://github.com/radian-software/apheleia/pull/169
[#170]: https://github.com/radian-software/apheleia/pull/170
[#171]: https://github.com/radian-software/apheleia/pull/171
[#172]: https://github.com/radian-software/apheleia/pull/172
+[#173]: https://github.com/radian-software/apheleia/pull/173
[#174]: https://github.com/radian-software/apheleia/pull/174
[#182]: https://github.com/radian-software/apheleia/pull/182
[#187]: https://github.com/radian-software/apheleia/pull/187
diff --git a/apheleia.el b/apheleia.el
index 5ca8351..40f8a18 100644
--- a/apheleia.el
+++ b/apheleia.el
@@ -62,6 +62,22 @@
(gofumpt . ("gofumpt"))
(goimports . ("goimports"))
(google-java-format . ("google-java-format" "-"))
+ (html-tidy "tidy"
+ "--quiet" "yes"
+ "--tidy-mark" "no"
+ "--vertical-space" "yes"
+ "-indent"
+ (when (derived-mode-p 'nxml-mode)
+ "-xml")
+ (apheleia-formatters-indent
+ "--indent-with-tabs"
+ "--indent-spaces"
+ (cond
+ ((derived-mode-p 'nxml-mode)
+ 'nxml-child-indent)
+ ((derived-mode-p 'web-mode)
+ 'web-mode-indent-style)))
+ (apheleia-formatters-fill-column "-wrap"))
(isort . ("isort" "-"))
(jq "jq" "."
(apheleia-formatters-js-indent "--tab" "--indent"))
diff --git a/test/formatters/installers/html-tidy.bash b/test/formatters/installers/html-tidy.bash
new file mode 100644
index 0000000..d384625
--- /dev/null
+++ b/test/formatters/installers/html-tidy.bash
@@ -0,0 +1 @@
+apt-get install -y tidy
diff --git a/test/formatters/samplecode/html-tidy/in.html b/test/formatters/samplecode/html-tidy/in.html
new file mode 100644
index 0000000..3cbbf29
--- /dev/null
+++ b/test/formatters/samplecode/html-tidy/in.html
@@ -0,0 +1 @@
+<!DOCTYPE html><html lang="en"><head><title>Hello world</title></head><body><ul><li>1</li><li>2</li><li><ul><li>3</li></ul></li></ul></body></html>
diff --git a/test/formatters/samplecode/html-tidy/out.html b/test/formatters/samplecode/html-tidy/out.html
new file mode 100644
index 0000000..59b2a4b
--- /dev/null
+++ b/test/formatters/samplecode/html-tidy/out.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Hello world</title>
+</head>
+<body>
+ <ul>
+ <li>1</li>
+
+ <li>2</li>
+
+ <li>
+ <ul>
+ <li>3</li>
+ </ul>
+ </li>
+ </ul>
+</body>
+</html>