Skip to content

Commit 8dd3770

Browse files
committed
Replaced the HTML Parser
Replaced the HTML-Parser with the inbuilt HTML parser.
1 parent d8c1499 commit 8dd3770

File tree

238 files changed

+32
-29278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+32
-29278
lines changed

includes/CustomOptions.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

includes/Description.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22
require_once __DIR__ . '/vendor/autoload.php';
3-
require_once 'CustomOptions.php';
4-
5-
use PHPHtmlParser\Dom;
63

74
/**
85
* Stores the description of the code.
@@ -49,19 +46,14 @@ public function getNext($index) {
4946
* @param string $dom A string that has the content of the <desc>-element.
5047
*/
5148
public function setTexts(&$dom) {
52-
53-
$content = new Dom();
54-
55-
$content->loadStr($dom, getOptions());
56-
57-
$positions = $content->getElementsByTag('position');
49+
$positions = $dom->getElementsByTagName('position');
5850
$numberOfPos = sizeof($positions);
5951

6052
$hasOne = false;
6153

6254
for($i = 0; $i < $numberOfPos; ++$i) {
6355
$key = $positions[$i]->getAttribute('line');
64-
$content = $positions[$i]->innerHtml;
56+
$content = $positions->item($i)->nodeValue;
6557

6658
if($key == 1)
6759
$hasOne = true;

includes/MultiCodeBlock.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static function renderMultiCodeBlock( $input, array $args, Parser $parser
3939
$replaced = str_replace($code, '', $input);
4040
$dom = getDOM($replaced);
4141

42-
$codevariants = $dom->getElementsbyTag('codeblock')->toArray();
43-
$descriptions = $dom->getElementsbyTag('desc')->toArray();
42+
$codevariants = $dom->getElementsbyTagName('codeblock');
43+
$descriptions = $dom->getElementsbyTagName('desc');
4444

4545
$size = sizeof($codevariants);
4646
$return = "";
@@ -49,7 +49,9 @@ public static function renderMultiCodeBlock( $input, array $args, Parser $parser
4949
$h1 = new \Highlight\Highlighter();
5050

5151
for($i = 0; $i < $size; ++$i) {
52-
$codeblock = createCodeBlock($codevariants[$i], $code[$i], $descriptions[$i], $parser, $h1);
52+
$desc = $descriptions->item($i);
53+
54+
$codeblock = createCodeBlock($code[$i], $desc, $codevariants[$i]->getAttribute('lang'), $parser, $h1);
5355
$return .= '<div class="tab-content '.($i == 0 ? 'tc-active' : '').'" data-tab="'.$i.'">'.$codeblock[0].'</div>';
5456
array_push($languages, $codeblock[1]);
5557
}

includes/MultiCodeBlockBuilder.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<?php
22
require_once __DIR__ . '/vendor/autoload.php';
3-
require_once 'CustomOptions.php';
43

54
require_once 'Description.php';
65
require_once 'Code.php';
76

8-
use PHPHtmlParser\Dom;
9-
107
/**
118
* Returns the DOM-Parser with custom options and the HTML-Tree
129
*
@@ -15,8 +12,13 @@
1512
* @return PHPHtmlParser\Dom The DOM-Element that has the HTML-Tree
1613
*/
1714
function getDOM(&$content) {
18-
$dom = new Dom();
19-
$dom->loadStr($content, getOptions());
15+
$dom = new DOMDocument();
16+
17+
$dom->validateOnParse = false;
18+
19+
libxml_use_internal_errors(true);
20+
$dom->loadHTML($content);
21+
libxml_clear_errors();
2022

2123
return $dom;
2224
}
@@ -72,17 +74,15 @@ function replaceLang(string $lang) {
7274
*
7375
* @return array The codeblock as the first element and the language as the second element.
7476
*/
75-
function createCodeBlock(&$codevariant, &$code, &$description, Parser &$parser, \Highlight\Highlighter &$h1) {
76-
77-
$lang = $codevariant->getAttribute("lang");
77+
function createCodeBlock(&$code, &$description, $lang, Parser &$parser, \Highlight\Highlighter &$h1) {
7878
if($lang == null) {
7979
return array('<span style="color: red; font-size: 700;">No Lang Attribute</span>', 'No lang');
8080
}
8181

8282
$lang = strtolower($lang);
8383

8484
$code = new Code($code, $lang);
85-
$desc = new Description(($description == null ? null : $description->innerHtml));
85+
$desc = new Description($description);
8686
$highlight = $code->highlight($h1);
8787

8888
$isObject = true;

includes/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"require": {
3-
"scrivo/highlight.php": "v9.18.1.6",
4-
"paquettg/php-html-parser": "^3.1"
3+
"scrivo/highlight.php": "v9.18.1.6"
54
}
65
}

0 commit comments

Comments
 (0)