From c5d5adea09a50614912f7ec1d3193c433f378bc4 Mon Sep 17 00:00:00 2001
From: Dean Blackborough
Date: Tue, 11 Apr 2017 22:43:09 +0100
Subject: [PATCH 1/2] Tag type
- Removed redundanct method
- Added tag type into array, we can check against this rather than the
tag directly as the tags could change.
---
src/DBlackborough/Quill/Parser/Html.php | 79 +++++++++++--------------
1 file changed, 33 insertions(+), 46 deletions(-)
diff --git a/src/DBlackborough/Quill/Parser/Html.php b/src/DBlackborough/Quill/Parser/Html.php
index 1b87726..4f315b9 100644
--- a/src/DBlackborough/Quill/Parser/Html.php
+++ b/src/DBlackborough/Quill/Parser/Html.php
@@ -34,56 +34,73 @@ protected function defaultOptions()
return array(
'attributes' => array(
'bold' => array(
- 'tag' => 'strong'
+ 'tag' => 'strong',
+ 'type' => 'inline'
),
'header' => array(
'1' => array(
- 'tag' => 'h1'
+ 'tag' => 'h1',
+ 'type' => 'block'
),
'2' => array(
- 'tag' => 'h2'
+ 'tag' => 'h2',
+ 'type' => 'block'
),
'3' => array(
- 'tag' => 'h3'
+ 'tag' => 'h3',
+ 'type' => 'block'
),
'4' => array(
- 'tag' => 'h4'
+ 'tag' => 'h4',
+ 'type' => 'block'
),
'5' => array(
- 'tag' => 'h5'
+ 'tag' => 'h5',
+ 'type' => 'block'
),
'6' => array(
- 'tag' => 'h6'
+ 'tag' => 'h6',
+ 'type' => 'block'
),
'7' => array(
- 'tag' => 'h7'
+ 'tag' => 'h7',
+ 'type' => 'block'
)
),
'italic' => array(
- 'tag' => 'em'
+ 'tag' => 'em',
+ 'type' => 'inline'
),
'link' => array(
'tag' => 'a',
+ 'type' => 'inline',
'attributes' => array(
'href' => null
)
),
'script' => array(
'sub' => array(
+ 'type' => 'inline',
'tag' => 'sub'
),
'super' => array(
+ 'type' => 'inline',
'tag' => 'sup'
)
),
'strike' => array(
- 'tag' => 's'
+ 'tag' => 's',
+ 'type' => 'inline'
),
'underline' => array(
- 'tag' => 'u'
+ 'tag' => 'u',
+ 'type' => 'inline'
),
),
- 'block' => 'p'
+ 'block' => array(
+ 'tag' => 'p',
+ 'type' => 'block'
+ )
);
}
@@ -152,41 +169,11 @@ private function lastItemClosed()
}
$this->content[$last_item]['tags'][] = array(
'open' => null,
- 'close' => '' . $this->options['block'] . '>',
+ 'close' => '' . $this->options['block']['tag'] . '>',
);
}
}
- /**
- * Check to see if the first content item is a block element, if it isn't add the default block element
- * defined by the block option
- */
- private function firstItemBlockElement()
- {
- $assigned_tags = $this->content[0]['tags'];
- $block = false;
-
- if (count($assigned_tags) > 0) {
- foreach ($assigned_tags as $assigned_tag) {
- // Block element check
- if (in_array($assigned_tag['open'], array('', '', '', '', '', '', '')) === true) {
- $block = true;
- continue;
- }
- }
- }
-
- if ($block === false) {
- $this->content[0]['tags'][] = array(
- 'open' => '<' . $this->options['block'] . '>',
- 'close' => null
- );
- foreach ($assigned_tags as $assigned_tag) {
- $this->content[0]['tags'][] = $assigned_tag;
- }
- }
- }
-
/**
* Split the inserts if multiple newlines are found and generate a new insert
*
@@ -300,7 +287,7 @@ private function openParagraphs()
$open_paragraph = true;
$content['tags'][] = array(
- 'open' => '<' . $this->options['block'] . '>',
+ 'open' => '<' . $this->options['block']['tag'] . '>',
'close' => null,
);
@@ -342,7 +329,7 @@ public function content()
}
/**
- * Do we need to assign th tags to the current element or the previous?
+ * Do we need to assign the tags to the current element or the previous?
*
* @param string $tag
*
@@ -399,7 +386,7 @@ private function closeOpenParagraphs()
$open_paragraph = false;
$this->content[$i-1]['tags'][] = array(
'open' => null,
- 'close' => '' . $this->options['block'] . '>'
+ 'close' => '' . $this->options['block']['tag'] . '>'
);
}
}
From d5503c3b2447d50ac39150e5ef28bd8c41b82492 Mon Sep 17 00:00:00 2001
From: Dean Blackborough
Date: Wed, 12 Apr 2017 22:26:24 +0100
Subject: [PATCH 2/2] Bugfix
* Parser no longer checks the HTML tags directly, all tags will soon be
configurable so checking against the default values makes no sense.
---
CHANGELOG.md | 6 +++
src/DBlackborough/Quill/Parser/Html.php | 57 ++++++++++++-------------
2 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e2a600..fee234b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,12 @@
Full changelog for PHP Quill Renderer
+## v0.60.1 - 2017-04-12
+
+* HTML parser no longer checks against HTML tags directly (h1, h2 etc), uses tag type. [Bugfix]
+* Added `assign` index to options array, no longer need to check HTML tag directly. [Bugfix]
+* Removed redundant code.
+
## v0.60.0 - 2017-03-27
* I simplified the usage of renderer ready for additional output formats, instantiate Quill class to use renderer and then simply call render().
diff --git a/src/DBlackborough/Quill/Parser/Html.php b/src/DBlackborough/Quill/Parser/Html.php
index 4f315b9..3c8dbd1 100644
--- a/src/DBlackborough/Quill/Parser/Html.php
+++ b/src/DBlackborough/Quill/Parser/Html.php
@@ -35,36 +35,43 @@ protected function defaultOptions()
'attributes' => array(
'bold' => array(
'tag' => 'strong',
- 'type' => 'inline'
+ 'type' => 'inline',
),
'header' => array(
'1' => array(
'tag' => 'h1',
- 'type' => 'block'
+ 'type' => 'block',
+ 'assign' => 'previous'
),
'2' => array(
'tag' => 'h2',
- 'type' => 'block'
+ 'type' => 'block',
+ 'assign' => 'previous'
),
'3' => array(
'tag' => 'h3',
- 'type' => 'block'
+ 'type' => 'block',
+ 'assign' => 'previous'
),
'4' => array(
'tag' => 'h4',
- 'type' => 'block'
+ 'type' => 'block',
+ 'assign' => 'previous'
),
'5' => array(
'tag' => 'h5',
- 'type' => 'block'
+ 'type' => 'block',
+ 'assign' => 'previous'
),
'6' => array(
'tag' => 'h6',
- 'type' => 'block'
+ 'type' => 'block',
+ 'assign' => 'previous'
),
'7' => array(
'tag' => 'h7',
- 'type' => 'block'
+ 'type' => 'block',
+ 'assign' => 'previous'
)
),
'italic' => array(
@@ -155,7 +162,7 @@ private function lastItemClosed()
if (count($assigned_tags) > 0) {
foreach ($assigned_tags as $assigned_tag) {
// Block element check
- if (in_array($assigned_tag['close'], array('
', '', '', '', '', '', '', '')) === true) {
+ if ($assigned_tag['close'] !== null && $assigned_tag['type'] === 'block') {
$block = true;
continue;
}
@@ -170,6 +177,7 @@ private function lastItemClosed()
$this->content[$last_item]['tags'][] = array(
'open' => null,
'close' => '' . $this->options['block']['tag'] . '>',
+ 'type' => 'block'
);
}
}
@@ -238,8 +246,11 @@ private function assignTags()
if ($has_tags === true) {
foreach ($tags as $tag) {
-
- $assign_tag_to_current_element = $this->assignTagCurrentElement($tag['tag']);
+ if (array_key_exists('assign', $tag) === false) {
+ $assign_tag_to_current_element = true;
+ } else {
+ $assign_tag_to_current_element = false;
+ }
$open = '<' . $tag['tag'];
if (array_key_exists('attributes', $tag) === true) {
@@ -259,6 +270,7 @@ private function assignTags()
$this->content[$tag_counter]['tags'][] = array(
'open' => $open,
'close' => '' . $tag['tag'] . '>',
+ 'type' => $tag['type']
);
}
}
@@ -289,6 +301,7 @@ private function openParagraphs()
$content['tags'][] = array(
'open' => '<' . $this->options['block']['tag'] . '>',
'close' => null,
+ 'type' => 'block'
);
$this->content[$i]['tags'] = $content['tags'];
@@ -328,22 +341,6 @@ public function content()
return $this->content;
}
- /**
- * Do we need to assign the tags to the current element or the previous?
- *
- * @param string $tag
- *
- * @return boolean
- */
- private function assignTagCurrentElement($tag)
- {
- if (in_array($tag, array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7')) === false) {
- return true;
- } else {
- return false;
- }
- }
-
/**
* Remove empty elements from the contents array, occurs when a tag is assigned to any earlier element
*
@@ -381,12 +378,12 @@ private function closeOpenParagraphs()
if ($open_paragraph === true && $i !== $opened_at) {
if (array_key_exists('tags', $content) === true) {
foreach ($content['tags'] as $tags) {
- $block_elements = array('', '', '', '', '', '', '');
- if (in_array($tags['open'], $block_elements) === true) {
+ if ($tags['type'] == 'block') {
$open_paragraph = false;
$this->content[$i-1]['tags'][] = array(
'open' => null,
- 'close' => '' . $this->options['block']['tag'] . '>'
+ 'close' => '' . $this->options['block']['tag'] . '>',
+ 'type' => 'block'
);
}
}