Skip to content

Commit

Permalink
Remove extra body tags from processed contents
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Jan 31, 2023
1 parent f936b12 commit e641ad3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Processor/HtmlIdProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ public function __invoke(array &$data, Content $content): void

private function setIdFromContent(\DOMElement $element): void
{
if (!$id = $element->getAttribute('id')) {
if (!$element->getAttribute('id')) {
$element->setAttribute('id', $this->slugify($element->textContent));
}
}

private function setIdFromHashedContent(\DOMElement $element): void
{
if (!$id = $element->getAttribute('id')) {
if (!$element->getAttribute('id')) {
$element->setAttribute('id', $this->hash($element->textContent));
}
}

private function setIdForImage(\DOMElement $element): void
{
if (!$id = $element->getAttribute('id')) {
if (!$element->getAttribute('id')) {
$name = $element->getAttribute('alt') ?: basename($element->getAttribute('src'));
$element->setAttribute('id', $this->slugify($name));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Service/NaiveHtmlCrawlerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public function save(Content $content, array &$data, string $property): void
$key = "{$content->getType()}:{$content->getSlug()}";

if (isset($this->crawlers[$key][$property])) {
$data[$property] = $this->crawlers[$key][$property]->html();
$data[$property] = $this->crawlers[$key][$property]->filterXPath('//body')->first()->html();
unset($this->crawlers[$key][$property]);
}
}

public function saveAll(Content $content, array &$data): void
{
foreach ($this->crawlers as $key => $crawlers) {
foreach ($this->crawlers as $crawlers) {
foreach ($crawlers as $property => $crawler) {
$data[$property] = $crawler->html();
$data[$property] = $crawler->filterXPath('//body')->first()->html();
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Service/Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ protected function blockAdmonition($line, $block = null)

return $block;
}

return null;
}

protected function blockAdmonitionContinue($line, $block = null)
{
// A blank newline has occurred, or text without indent:
if (isset($block['interrupted']) || $line['indent'] < 4) {
return;
return null;
}

$previous = $block['$admonitionContentRef'] ?? "\n";
Expand Down
2 changes: 1 addition & 1 deletion src/Service/SharedHtmlCrawlerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function saveAll(Content $content, array &$data): void
}

foreach ($this->crawlers[$key] as $property => $crawler) {
$data[$property] = $crawler->html();
$data[$property] = $crawler->filterXPath('//body')->first()->html();
}

unset($this->crawlers[$key]);
Expand Down
6 changes: 5 additions & 1 deletion tests/Unit/Processor/ResolveContentLinksProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public function testResolveLinks(): void
<a href="/other-contents-route-path/another-contents#some-anchor">Another content with anchor</a>
</body>
HTML,
$data['content']
<<<HTML
<body>
{$data['content']}
</body>
HTML,
);
}
}

0 comments on commit e641ad3

Please sign in to comment.