-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindenter
executable file
·78 lines (61 loc) · 2.15 KB
/
indenter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env php
<?php
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
require __DIR__ . '/../vendor/autoload.php';
} else {
require __DIR__ . '/vendor/autoload.php';
}
function error($error)
{
echo $error;
exit(1);
}
$options = getopt('', ['input:', 'indentation_character:', 'inline:', 'block:']);
if (!isset($_SERVER['argv'][1])) {
echo '
Indent HTML.
Options:
--input=./input_file.html
Input file
--indentation_character=" "
Character(s) used for indentation. Defaults to 4 whitespace characters.
--inline=""
A list of comma separated "inline" element names.
--block=""
A list of comma separated "block" element names.
Examples:
./indenter --input="./input.html"
Indent "input.html" file and print the output to STDOUT.
./indenter --input="./input.html" | tee ./output.html
Indent "input.html" file and dump the output to "output.html".
./indenter --input="./input.html" --indentation_character="\t"
Indent "input.html" file using tab to indent the markup.
./indenter --input="./input.html" --inline="div,p"
Indent "input.html" file treating <div> and <p> elements as inline.
./indenter --input="./input.html" --block="span,em"
Indent "input.html" file treating <span> and <em> elements as block.
';
exit;
}
if (!isset($options['input'])) {
error('Missing "input" parameter.');
} elseif (!file_exists($options['input'])) {
error('"input" file does not exist.');
}
$indenter = new \Qubus\Support\Indenter(
isset($options['indentation_character'])
? ['indentation_character' => $options['indentation_character']]
: []
);
if (isset($options['inline'])) {
foreach (explode(',', $options['inline']) as $element_name) {
$indenter->setElementType($element_name, \Qubus\Support\Indenter::ELEMENT_TYPE_INLINE);
}
}
if (isset($options['block'])) {
foreach (explode(',', $options['block']) as $element_name) {
$indenter->setElementType($element_name, \Qubus\Support\Indenter::ELEMENT_TYPE_BLOCK);
}
}
$output = $indenter->indent(file_get_contents($options['input']));
echo $output;