Skip to content

Commit 2636850

Browse files
committed
Split config preparation code into a new function from htmldoc::minify().
Fixed variable existence bug in `index.php`. Updated dependencies.
1 parent acfda1c commit 2636850

File tree

4 files changed

+60
-50
lines changed

4 files changed

+60
-50
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"require": {
1717
"php": ">=8.0",
1818
"hexydec/tokenise": "1.0.1",
19-
"hexydec/cssdoc": "1.1.0",
20-
"hexydec/jslite": "1.0.0"
19+
"hexydec/cssdoc": "1.1.1",
20+
"hexydec/jslite": "1.0.1"
2121
},
2222
"autoload": {
2323
"classmap": ["src/"]

composer.lock

+28-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
require(__DIR__.'/vendor/autoload.php');
2+
require __DIR__.'/vendor/autoload.php';
33

44
$error = null;
55
\set_error_handler(function (int $type, string $msg) use (&$error) {
@@ -13,13 +13,13 @@
1313
$base = $_POST['base'] ?? null;
1414
$input = '';
1515
$output = '';
16-
$minify = Array();
17-
$timing = Array(
16+
$minify = [];
17+
$timing = [
1818
'start' => \microtime(true)
19-
);
20-
$mem = Array(
19+
];
20+
$mem = [
2121
'start' => \memory_get_peak_usage()
22-
);
22+
];
2323

2424
// create object and retrieve config
2525
$doc = new hexydec\html\htmldoc();
@@ -132,7 +132,7 @@
132132
.minify__form-error {
133133
padding: 10px;
134134
background: red;
135-
font-weight bold;
135+
font-weight: bold;
136136
color: #FFF;
137137
margin: 10px 10px 0 10px;
138138
}
@@ -262,9 +262,11 @@
262262
</table>
263263
<?php } ?>
264264
</div>
265-
<?php if ($output) { ?>
266-
<input type="hidden" name="base" value="<?= \htmlspecialchars($base); ?>" />
267-
<iframe class="minify__preview" srcdoc="<?= \htmlspecialchars(\preg_replace('/<head[^>]*>/i', '$0<base href="'.\htmlspecialchars($base).'">', $output)); ?>"></iframe>
265+
<?php if ($output) {
266+
if ($base) { ?>
267+
<input type="hidden" name="base" value="<?= \htmlspecialchars($base); ?>" />
268+
<?php } ?>
269+
<iframe class="minify__preview" srcdoc="<?= \htmlspecialchars($base === null ? $output : \preg_replace('/<head[^>]*>/i', '$0<base href="'.\htmlspecialchars($base).'">', $output)); ?>"></iframe>
268270
<?php } ?>
269271
<div class="minify__options">
270272
<h3>Options</h3>

src/htmldoc.php

+18-11
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,29 @@ protected function collection(array $nodes) : htmldoc {
541541
public function minify(array $minify = []) : void {
542542

543543
// merge config
544-
$minify = \array_replace_recursive($this->config['minify'], $minify);
544+
$minify = $this->getMinifyOptions($minify);
545545

546546
// set minify output parameters
547547
if ($minify['quotes']) {
548548
$this->config['output']['quotestyle'] = 'minimal';
549549
}
550550

551+
// sort classes by occurence, then by string
552+
if (!empty($minify['attributes']['sort']) && !empty($this->cache['attr'])) {
553+
$minify['attributes']['sort'] = $this->sortAttributes($this->cache['attr'], $this->cache['attrvalues']);
554+
}
555+
556+
// minify children
557+
foreach ($this->children AS $item) {
558+
$item->minify($minify);
559+
}
560+
}
561+
562+
protected function getMinifyOptions(array $minify) : array {
563+
564+
// merge config
565+
$minify = \array_replace_recursive($this->config['minify'], $minify);
566+
551567
// set safe options
552568
if ($minify['safe']) {
553569
$minify['urls'] = false;
@@ -568,16 +584,7 @@ public function minify(array $minify = []) : void {
568584
}
569585
$minify['close'] = false;
570586
}
571-
572-
// sort classes by occurence, then by string
573-
if (!empty($minify['attributes']['sort']) && !empty($this->cache['attr'])) {
574-
$minify['attributes']['sort'] = $this->sortAttributes($this->cache['attr'], $this->cache['attrvalues']);
575-
}
576-
577-
// minify children
578-
foreach ($this->children AS $item) {
579-
$item->minify($minify);
580-
}
587+
return $minify;
581588
}
582589

583590
/**

0 commit comments

Comments
 (0)