From 5dd96f00fe30cf7f906a73f3aafb82027fe5dbc2 Mon Sep 17 00:00:00 2001 From: "Paul M. Jones" Date: Thu, 5 Mar 2015 19:33:23 -0600 Subject: [PATCH 1/2] make sure HTML is retained in headings --- src/Process/Headings/HeadingsProcess.php | 2 +- tests/BookFixture.php | 2 +- tests/Process/ConversionProcessTest.php | 2 +- tests/Process/HeadingsProcessTest.php | 2 +- tests/Process/RenderingProcessTest.php | 2 +- tests/Process/TocProcessTest.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Process/Headings/HeadingsProcess.php b/src/Process/Headings/HeadingsProcess.php index 0e1f042..a353055 100644 --- a/src/Process/Headings/HeadingsProcess.php +++ b/src/Process/Headings/HeadingsProcess.php @@ -130,7 +130,7 @@ protected function addHeading(DomNode $node) { $heading = $this->newHeading($node); $this->headings[] = $heading; - $node->nodeValue = $heading->getNumber() . " {$node->nodeValue}"; + $node->nodeValue = $heading->getNumber() . $node->C14N(); $node->setAttribute('id', $heading->getId()); } diff --git a/tests/BookFixture.php b/tests/BookFixture.php index 0685314..9e6b4f3 100644 --- a/tests/BookFixture.php +++ b/tests/BookFixture.php @@ -36,7 +36,7 @@ class BookFixture Text under title. -## Subtitle A +## Subtitle `code` A Text under subtitle A. diff --git a/tests/Process/ConversionProcessTest.php b/tests/Process/ConversionProcessTest.php index e442156..e02dff5 100644 --- a/tests/Process/ConversionProcessTest.php +++ b/tests/Process/ConversionProcessTest.php @@ -33,7 +33,7 @@ public function testConversion() $this->process->__invoke($this->fixture->page); $expect = '

Title

Text under title.

-

Subtitle A

+

Subtitle code A

Text under subtitle A.

Sub-subtitle

Text under sub-subtitle.

diff --git a/tests/Process/HeadingsProcessTest.php b/tests/Process/HeadingsProcessTest.php index 3a59e88..d3c8421 100644 --- a/tests/Process/HeadingsProcessTest.php +++ b/tests/Process/HeadingsProcessTest.php @@ -52,7 +52,7 @@ public function testHeadings() ), array( 'number' => '1.1.1.', - 'title' => 'Subtitle A', + 'title' => 'Subtitle code A', 'id' => '1.1.1', 'href' => '/chapter/section.html', 'level' => 3, diff --git a/tests/Process/RenderingProcessTest.php b/tests/Process/RenderingProcessTest.php index 2ae3a34..e4c5c02 100644 --- a/tests/Process/RenderingProcessTest.php +++ b/tests/Process/RenderingProcessTest.php @@ -125,7 +125,7 @@ public function testRendering()
1.1. Title
-
1.1.1. Subtitle A
+
1.1.1. Subtitle code A
1.1.1.1. Sub-subtitle
diff --git a/tests/Process/TocProcessTest.php b/tests/Process/TocProcessTest.php index fad030b..37d761b 100644 --- a/tests/Process/TocProcessTest.php +++ b/tests/Process/TocProcessTest.php @@ -76,7 +76,7 @@ public function testTocIndex() ), array( 'number' => '1.1.1.', - 'title' => 'Subtitle A', + 'title' => 'Subtitle code A', 'id' => '1.1.1', 'href' => '/chapter/section.html', 'level' => 3, @@ -125,7 +125,7 @@ public function testTocRoot() ), array( 'number' => '1.1.1.', - 'title' => 'Subtitle A', + 'title' => 'Subtitle code A', 'id' => '1.1.1', 'href' => '/chapter/section.html', 'level' => 3, From d848cefd07d18e6d9f593c759f233e50f9d1a0a0 Mon Sep 17 00:00:00 2001 From: "Paul M. Jones" Date: Thu, 5 Mar 2015 23:36:25 -0600 Subject: [PATCH 2/2] keep HTML in heading when adding number --- src/Process/Headings/HeadingsProcess.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Process/Headings/HeadingsProcess.php b/src/Process/Headings/HeadingsProcess.php index a353055..c4b257b 100644 --- a/src/Process/Headings/HeadingsProcess.php +++ b/src/Process/Headings/HeadingsProcess.php @@ -9,6 +9,7 @@ use DomDocument; use DomNode; use DomNodeList; +use DomText; use DomXpath; class HeadingsProcess implements ProcessInterface @@ -130,7 +131,11 @@ protected function addHeading(DomNode $node) { $heading = $this->newHeading($node); $this->headings[] = $heading; - $node->nodeValue = $heading->getNumber() . $node->C14N(); + + $number = new DOMText(); + $number->nodeValue = $heading->getNumber() . ' '; + $node->insertBefore($number, $node->firstChild); + $node->setAttribute('id', $heading->getId()); }