Skip to content

Commit

Permalink
Updated page includes to be top-level for code blocks
Browse files Browse the repository at this point in the history
This change means that code blocks are now included still wrapped in
their pre tags, as we do for tables and lists.
Previously the <code> inner content would be included which would lead
to a generally bad/broken presentation.

Hopefully should not be a breaking change as section include tags for
code was tricky to get to, and it was in a semi-broken state.

For #2406
  • Loading branch information
ssddanbrown committed Nov 15, 2021
1 parent 85154ff commit e29d03a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Entities/Tools/PageContent.php
Expand Up @@ -390,7 +390,7 @@ protected function parsePageIncludes(string $html): string
*/
protected function fetchSectionOfPage(Page $page, string $sectionId): string
{
$topLevelTags = ['table', 'ul', 'ol'];
$topLevelTags = ['table', 'ul', 'ol', 'pre'];
$doc = $this->loadDocumentFromHtml($page->html);

// Search included content for the id given and blank out if not exists.
Expand Down
23 changes: 21 additions & 2 deletions tests/Entity/PageContentTest.php
Expand Up @@ -62,7 +62,9 @@ public function test_saving_page_with_includes()

public function test_page_includes_do_not_break_tables()
{
/** @var Page $page */
$page = Page::query()->first();
/** @var Page $secondPage */
$secondPage = Page::query()->where('id', '!=', $page->id)->first();

$content = '<table id="table"><tbody><tr><td>test</td></tr></tbody></table>';
Expand All @@ -72,8 +74,25 @@ public function test_page_includes_do_not_break_tables()
$page->html = "{{@{$secondPage->id}#table}}";
$page->save();

$this->asEditor();
$pageResp = $this->get($page->getUrl());
$pageResp = $this->asEditor()->get($page->getUrl());
$pageResp->assertSee($content, false);
}

public function test_page_includes_do_not_break_code()
{
/** @var Page $page */
$page = Page::query()->first();
/** @var Page $secondPage */
$secondPage = Page::query()->where('id', '!=', $page->id)->first();

$content = '<pre id="bkmrk-code"><code>var cat = null;</code></pre>';
$secondPage->html = $content;
$secondPage->save();

$page->html = "{{@{$secondPage->id}#bkmrk-code}}";
$page->save();

$pageResp = $this->asEditor()->get($page->getUrl());
$pageResp->assertSee($content, false);
}

Expand Down

0 comments on commit e29d03a

Please sign in to comment.