Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #20 from deanblackborough/v0.60.1
Browse files Browse the repository at this point in the history
V0.60.1
  • Loading branch information
deanblackborough authored Apr 12, 2017
2 parents 26a9003 + d5503c3 commit f8e1490
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 66 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
116 changes: 50 additions & 66 deletions src/DBlackborough/Quill/Parser/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,80 @@ 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',
'assign' => 'previous'
),
'2' => array(
'tag' => 'h2'
'tag' => 'h2',
'type' => 'block',
'assign' => 'previous'
),
'3' => array(
'tag' => 'h3'
'tag' => 'h3',
'type' => 'block',
'assign' => 'previous'
),
'4' => array(
'tag' => 'h4'
'tag' => 'h4',
'type' => 'block',
'assign' => 'previous'
),
'5' => array(
'tag' => 'h5'
'tag' => 'h5',
'type' => 'block',
'assign' => 'previous'
),
'6' => array(
'tag' => 'h6'
'tag' => 'h6',
'type' => 'block',
'assign' => 'previous'
),
'7' => array(
'tag' => 'h7'
'tag' => 'h7',
'type' => 'block',
'assign' => 'previous'
)
),
'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'
)
);
}

Expand Down Expand Up @@ -138,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('</p>', '</h1>', '</h2>', '</h3>', '</h4>', '</h5>', '</h6>', '</h7>')) === true) {
if ($assigned_tag['close'] !== null && $assigned_tag['type'] === 'block') {
$block = true;
continue;
}
Expand All @@ -152,41 +176,12 @@ private function lastItemClosed()
}
$this->content[$last_item]['tags'][] = array(
'open' => null,
'close' => '</' . $this->options['block'] . '>',
'close' => '</' . $this->options['block']['tag'] . '>',
'type' => 'block'
);
}
}

/**
* 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('<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<h7>')) === 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
*
Expand Down Expand Up @@ -251,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) {
Expand All @@ -272,6 +270,7 @@ private function assignTags()
$this->content[$tag_counter]['tags'][] = array(
'open' => $open,
'close' => '</' . $tag['tag'] . '>',
'type' => $tag['type']
);
}
}
Expand Down Expand Up @@ -300,8 +299,9 @@ private function openParagraphs()
$open_paragraph = true;

$content['tags'][] = array(
'open' => '<' . $this->options['block'] . '>',
'open' => '<' . $this->options['block']['tag'] . '>',
'close' => null,
'type' => 'block'
);

$this->content[$i]['tags'] = $content['tags'];
Expand Down Expand Up @@ -341,22 +341,6 @@ public function content()
return $this->content;
}

/**
* Do we need to assign th 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
*
Expand Down Expand Up @@ -394,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('<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<h7>');
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'] . '>'
'close' => '</' . $this->options['block']['tag'] . '>',
'type' => 'block'
);
}
}
Expand Down

0 comments on commit f8e1490

Please sign in to comment.