Skip to content

Commit 6032e39

Browse files
committed
Strip tags and maintain whitespace
1 parent 783e618 commit 6032e39

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Parser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function parse()
102102
$returnValue = $element->ownerDocument->saveXML($element);
103103

104104
if ($this->format === Format::PLAIN_TEXT) {
105-
$returnValue = strip_tags($returnValue);
105+
$returnValue = Utils::stripTagsMaintainWhitespace($returnValue);
106106
}
107107

108108
$returnValue = trim($returnValue);

src/Utils.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace DivineOmega\WikitextParser;
4+
5+
class Utils
6+
{
7+
public static function stripTagsMaintainWhitespace(string $html)
8+
{
9+
$plaintext = $html;
10+
$plaintext = str_replace('<', ' <', $plaintext);
11+
$plaintext = strip_tags($plaintext);
12+
$plaintext = str_replace(' ', ' ', $plaintext);
13+
14+
return $plaintext;
15+
}
16+
}

0 commit comments

Comments
 (0)