Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar table of contents are unable to be generated when using Setext headers #1337

Closed
caendesilva opened this issue Mar 19, 2023 · 6 comments · Fixed by #1338
Closed

Sidebar table of contents are unable to be generated when using Setext headers #1337

caendesilva opened this issue Mar 19, 2023 · 6 comments · Fixed by #1338

Comments

@caendesilva
Copy link
Member

caendesilva commented Mar 19, 2023

New issue description

Okay, here is the updated issue as I have scoped down the repro and root issue.

Minimal reproducible example code:

$markdown = "Level 1\n=======\nLevel 2\n-------\nLevel 3\n-------\n";

$result = (new GeneratesTableOfContents($markdown))->execute();

Results in:

TypeError : substr(): Argument #3 ($length) must be of type ?int, bool given

Original description

This seems to be a very confusing combination of edge cases.

But for some reason, when using the following configuration:

'output_directories' => [
    \Hyde\Pages\DocumentationPage::class => '',
],

And a documentation page with Setext headers, like so: (Using front matter makes no difference)

Foo Bar
=======

This is a test.

You get the following crash when running the build command:

Creating Documentation Pages...
 0/1 [>---------------------------]   0%
   Illuminate\View\ViewException

  substr(): Argument #3 ($length) must be of type ?int, bool given (View: H:\monorepo\packages\framework\resources\views\components\docs\sidebar-item.blade.php) (View: H:\monorepo\packages\framework\resources\views\components\docs\sidebar-item.blade.php) (View: H:\monorepo\packages\framework\resources\views\components\docs\sidebar-item.blade.php) (View: H:\monorepo\packages\framework\resources\views\components\docs\sidebar-item.blade.php)

  at H:\monorepo\packages\framework\src\Framework\Actions\GeneratesTableOfContents.php:55
     51▕         $converter = new MarkdownConverter($environment);
     52▕         $html = $converter->convert("[[END_TOC]]\n".$this->markdown)->getContent();
     53▕
     54▕         // Return everything before the [[END_TOC]] marker.
  ➜  55▕         return substr($html, 0, strpos($html, '<p>[[END_TOC]]'));
     56▕     }
     57▕ }
     58▕

  1   H:\monorepo\vendor\illuminate\view\Engines\PhpEngine.php:60
      Illuminate\View\Engines\CompilerEngine::handleViewException(Object(Illuminate\View\ViewException))

  2   H:\monorepo\packages\framework\src\Framework\Actions\GeneratesTableOfContents.php:55
      Illuminate\View\ViewException::("substr(): Argument #3 ($length) must be of type ?int, bool given (View: H:\monorepo\packages\framework\resources\views\components\docs\sidebar-item.blade.php) (View: H:\monorepo\packages\framework\resources\views\components\docs\sidebar-item.blade.php) (View: H:\monorepo\packages\framework\resources\views\components\docs\sidebar-item.blade.php)")
@caendesilva
Copy link
Member Author

caendesilva commented Mar 21, 2023

Adding to the mystery, I cannot reproduce this when running tests... 65afc73

Edit, okay so I can repro in test WHEN the page source file is explicitly saved to disk. a5d7112 This is so weird, but at least I can get a proper stacktrace now.

@caendesilva
Copy link
Member Author

caendesilva commented Mar 21, 2023

Okay so now I've started to narrow down this issue, and it's becoming less weird. This is applicable to ATX headers as well, the issue is when using H1 headers and root output directories, for reasons not yet to be known. Nevermind 2eeb4c5

@caendesilva
Copy link
Member Author

Okay, so apparently the END_TOC marker is not added when using Setext:

HTML dump for ATX

<ul class="table-of-contents">\n
<li>\n
<a href="#chapter-i-down-the-rabbit-hole">CHAPTER I. DOWN THE RABBIT-HOLE.</a>\n
</li>\n
</ul>\n
<p>[[END_TOC]]</p>\n
<h1><a id="content-adventures-in-wonderland" href="#adventures-in-wonderland" class="heading-permalink" aria-hidden="true" title="Permalink"></a>Adventures in Wonderland</h1>\n
<h2><a id="content-chapter-i-down-the-rabbit-hole" href="#chapter-i-down-the-rabbit-hole" class="heading-permalink" aria-hidden="true" title="Permalink"></a>CHAPTER I. DOWN THE RABBIT-HOLE.</h2>\n
<p>So she was considering in her own mind, as well as she could, for the hot day made her feel very sleepy and stupid.</p>\n

HTML dump for Setext

<ul class="table-of-contents">\n
<li>\n
<a href="#chapter-i-down-the-rabbit-hole">CHAPTER I. DOWN THE RABBIT-HOLE.</a>\n
</li>\n
</ul>\n
<h1><a id="content-endtocadventures-in-wonderland" href="#endtocadventures-in-wonderland" class="heading-permalink" aria-hidden="true" title="Permalink"></a>[[END_TOC]]\n
Adventures in Wonderland</h1>\n
<h2><a id="content-chapter-i-down-the-rabbit-hole" href="#chapter-i-down-the-rabbit-hole" class="heading-permalink" aria-hidden="true" title="Permalink"></a>CHAPTER I. DOWN THE RABBIT-HOLE.</h2>\n
<p>So she was considering in her own mind, as well as she could, for the hot day made her feel very sleepy and stupid.</p>\n

@caendesilva
Copy link
Member Author

I think this is because we append the END_TOC marker first in the document, but maybe that is stripped from the converter input downstream?

@caendesilva caendesilva changed the title ViewException when using Setext headers in documentation pages when output directory is set to root Sidebar table of contents are unable to be generated when using Setext headers Mar 22, 2023
@caendesilva
Copy link
Member Author

Okay, output dir is unrelated. OP updated to reflect

caendesilva added a commit that referenced this issue Mar 22, 2023
caendesilva added a commit that referenced this issue Mar 22, 2023
@caendesilva caendesilva reopened this Mar 22, 2023
caendesilva added a commit that referenced this issue Mar 22, 2023
This reverts commit 65afc73.
@caendesilva
Copy link
Member Author

Fixed in #1343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant