From: Dan Brown Date: Mon, 22 Nov 2021 16:34:28 +0000 (+0000) Subject: Merge branch 'assign_ids_to_nested_headers' of https://github.com/Julesdevops/BookSta... X-Git-Tag: v21.11.1~1^2~7 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/4ddbc9556bf02ecd31aff093ed4acb200c9fcfd6?hp=-c Merge branch 'assign_ids_to_nested_headers' of https://github.com/Julesdevops/BookStack into Julesdevops-assign_ids_to_nested_headers --- 4ddbc9556bf02ecd31aff093ed4acb200c9fcfd6 diff --combined app/Entities/Tools/PageContent.php index a6ba352a8,c8204a181..c60cf0311 --- a/app/Entities/Tools/PageContent.php +++ b/app/Entities/Tools/PageContent.php @@@ -156,7 -156,7 +156,7 @@@ class PageConten /** * Parse a base64 image URI into the data and extension. * - * @return array{extension: array, data: string} + * @return array{extension: string, data: string} */ protected function parseBase64ImageUri(string $uri): array { @@@ -193,6 -193,15 +193,15 @@@ } } + // Set ids on nested header nodes + $nestedHeaders = $xPath->query('//body//*//h1|//body//*//h2|//body//*//h3|//body//*//h4|//body//*//h5|//body//*//h6'); + foreach ($nestedHeaders as $nestedHeader) { + [$oldId, $newId] = $this->setUniqueId($nestedHeader, $idMap); + if ($newId && $newId !== $oldId) { + $this->updateLinks($xPath, '#' . $oldId, '#' . $newId); + } + } + // Ensure no duplicate ids within child items $idElems = $xPath->query('//body//*//*[@id]'); foreach ($idElems as $domElem) { @@@ -230,7 -239,7 +239,7 @@@ */ protected function setUniqueId(\DOMNode $element, array &$idMap): array { - if (get_class($element) !== 'DOMElement') { + if (!$element instanceof \DOMElement) { return ['', '']; } @@@ -242,7 -251,7 +251,7 @@@ return [$existingId, $existingId]; } - // Create an unique id for the element + // Create a unique id for the element // Uses the content as a basis to ensure output is the same every time // the same content is passed through. $contentId = 'bkmrk-' . mb_substr(strtolower(preg_replace('/\s+/', '-', trim($element->nodeValue))), 0, 20);