mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-10 17:01:42 +08:00
Includes: Added ID de-duplicating and more thorough clean-up
This commit is contained in:
parent
71c93c8878
commit
b569827114
@ -5,8 +5,6 @@ namespace BookStack\Entities\Tools;
|
|||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
use BookStack\Entities\Tools\Markdown\MarkdownToHtml;
|
use BookStack\Entities\Tools\Markdown\MarkdownToHtml;
|
||||||
use BookStack\Exceptions\ImageUploadException;
|
use BookStack\Exceptions\ImageUploadException;
|
||||||
use BookStack\Facades\Theme;
|
|
||||||
use BookStack\Theming\ThemeEvents;
|
|
||||||
use BookStack\Uploads\ImageRepo;
|
use BookStack\Uploads\ImageRepo;
|
||||||
use BookStack\Uploads\ImageService;
|
use BookStack\Uploads\ImageService;
|
||||||
use BookStack\Util\HtmlContentFilter;
|
use BookStack\Util\HtmlContentFilter;
|
||||||
@ -293,10 +291,16 @@ class PageContent
|
|||||||
$parser = new PageIncludeParser($doc, $contentProvider);
|
$parser = new PageIncludeParser($doc, $contentProvider);
|
||||||
$nodesAdded = 1;
|
$nodesAdded = 1;
|
||||||
|
|
||||||
for ($includeDepth = 0; $includeDepth < 3 && $nodesAdded !== 0; $includeDepth++) {
|
for ($includeDepth = 0; $includeDepth < 1 && $nodesAdded !== 0; $includeDepth++) {
|
||||||
$nodesAdded = $parser->parse();
|
$nodesAdded = $parser->parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($includeDepth > 1) {
|
||||||
|
$idMap = [];
|
||||||
|
$changeMap = [];
|
||||||
|
$this->updateIdsRecursively($doc->getBody(), 0, $idMap, $changeMap);
|
||||||
|
}
|
||||||
|
|
||||||
if (!config('app.allow_content_scripts')) {
|
if (!config('app.allow_content_scripts')) {
|
||||||
HtmlContentFilter::removeScriptsFromDocument($doc);
|
HtmlContentFilter::removeScriptsFromDocument($doc);
|
||||||
}
|
}
|
||||||
|
@ -145,6 +145,7 @@ class PageIncludeParser
|
|||||||
$parentText = $parent->textContent;
|
$parentText = $parent->textContent;
|
||||||
$tagPos = strpos($parentText, $tag->tagContent);
|
$tagPos = strpos($parentText, $tag->tagContent);
|
||||||
$before = $tagPos < (strlen($parentText) / 2);
|
$before = $tagPos < (strlen($parentText) / 2);
|
||||||
|
$this->toCleanup[] = $tag->domNode->parentNode;
|
||||||
|
|
||||||
if ($before) {
|
if ($before) {
|
||||||
$parent->parentNode->insertBefore($tag->domNode, $parent);
|
$parent->parentNode->insertBefore($tag->domNode, $parent);
|
||||||
@ -206,8 +207,10 @@ class PageIncludeParser
|
|||||||
{
|
{
|
||||||
foreach ($this->toCleanup as $element) {
|
foreach ($this->toCleanup as $element) {
|
||||||
$element->normalize();
|
$element->normalize();
|
||||||
if ($element->parentNode && !$element->hasChildNodes()) {
|
while ($element->parentNode && !$element->hasChildNodes()) {
|
||||||
$element->parentNode->removeChild($element);
|
$parent = $element->parentNode;
|
||||||
|
$parent->removeChild($element);
|
||||||
|
$element = $parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,6 +179,15 @@ class PageIncludeParserTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_multi_source_elem_whole_document_with_nested_content_origin()
|
||||||
|
{
|
||||||
|
$this->runParserTest(
|
||||||
|
'<p><strong>{{@45}}</strong></p>',
|
||||||
|
['45' => '<p>Testing</p><blockquote>This</blockquote>'],
|
||||||
|
'<p>Testing</p><blockquote>This</blockquote>',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_multiple_tags_in_same_origin_with_inline_content()
|
public function test_multiple_tags_in_same_origin_with_inline_content()
|
||||||
{
|
{
|
||||||
$this->runParserTest(
|
$this->runParserTest(
|
||||||
@ -202,7 +211,7 @@ class PageIncludeParserTest extends TestCase
|
|||||||
$this->runParserTest(
|
$this->runParserTest(
|
||||||
'<div><p>This <strong>{{@45#content}}</strong> content is {{@45#content}}</p>{{@45#content}}</div>',
|
'<div><p>This <strong>{{@45#content}}</strong> content is {{@45#content}}</p>{{@45#content}}</div>',
|
||||||
['45' => '<pre id="content">block</pre>'],
|
['45' => '<pre id="content">block</pre>'],
|
||||||
'<div><pre id="content">block</pre><p>This <strong></strong> content is </p><pre id="content">block</pre><pre id="content">block</pre></div>',
|
'<div><pre id="content">block</pre><p>This content is </p><pre id="content">block</pre><pre id="content">block</pre></div>',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user