]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'assign_ids_to_nested_headers' of https://github.com/Julesdevops/BookSta...
authorDan Brown <redacted>
Mon, 22 Nov 2021 16:34:28 +0000 (16:34 +0000)
committerDan Brown <redacted>
Mon, 22 Nov 2021 16:34:28 +0000 (16:34 +0000)
1  2 
app/Entities/Tools/PageContent.php

index a6ba352a834c0f5f9709c03ec79fe42f326d2138,c8204a18186893c874f03dcdb65e820e03c3d638..c60cf03113a9cceaa980f040325b5df8cacd0e8d
@@@ -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
      {
              }
          }
  
+         // 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) {
       */
      protected function setUniqueId(\DOMNode $element, array &$idMap): array
      {
 -        if (get_class($element) !== 'DOMElement') {
 +        if (!$element instanceof \DOMElement) {
              return ['', ''];
          }
  
              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);