Skip to content

Commit

Permalink
Fixed problem with matching opening and closing tags in HTML code inc…
Browse files Browse the repository at this point in the history
…luding nested span tags.
  • Loading branch information
lpaulsen93 committed Apr 1, 2017
1 parent d8d36a8 commit 52ba770
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions ODT/ODTSpan.php
Expand Up @@ -175,6 +175,7 @@ public static function generateSpansfromHTMLCode(ODTInternalParams $params, $HTM
$entry ['tag-orig'] = $tagged;
}
}
$entry ['matched'] = false;
$parsed [] = $entry;

$pos = $found [1]+1;
Expand All @@ -192,18 +193,21 @@ public static function generateSpansfromHTMLCode(ODTInternalParams $params, $HTM
if ($checked [$out] !== NULL) {
continue;
}
$found = $parsed [$out];
$found = &$parsed [$out];
if ($found ['content'] !== NULL) {
$checked [$out] = $params->document->replaceXMLEntities($found ['content']);
} else if ($found ['tag-open'] !== NULL) {
$closed = false;

for ($in = $out+1 ; $in < count($parsed) ; $in++) {
$search = $parsed [$in];
$search = &$parsed [$in];
if ($search ['tag-close'] !== NULL &&
$found ['tag-open'] == $search ['tag-close'] &&
$search ['matched'] === false &&
(array_key_exists($found ['tag-open'], $spans) || $found ['tag-open'] == 'span')) {

$closed = true;
$search ['matched'] = true;

// Known and closed tag, convert to ODT
if ($found ['tag-open'] != 'span') {
Expand Down
12 changes: 9 additions & 3 deletions ODT/ODTUtility.php
Expand Up @@ -678,6 +678,8 @@ public static function generateODTfromHTMLCode(ODTInternalParams $params, $HTMLC
'close' => '</text:span>'),
'del' => array ('open' => '<text:span text:style-name="del">',
'close' => '</text:span>'),
'span' => array ('open' => '',
'close' => ''),
'a' => array ('open' => '',
'close' => ''),
'ol' => array ('open' => '',
Expand Down Expand Up @@ -756,6 +758,7 @@ public static function generateODTfromHTMLCode(ODTInternalParams $params, $HTMLC
$entry ['tag-orig'] = $tagged;
}
}
$entry ['matched'] = false;
$parsed [] = $entry;

$pos = $found [1]+1;
Expand All @@ -775,7 +778,7 @@ public static function generateODTfromHTMLCode(ODTInternalParams $params, $HTMLC
if ($checked [$out] !== NULL) {
continue;
}
$found = $parsed [$out];
$found = &$parsed [$out];
if ($found ['content'] !== NULL) {
if ($options ['escape_content'] !== 'false') {
$checked [$out] = $params->document->replaceXMLEntities($found ['content']);
Expand All @@ -786,11 +789,14 @@ public static function generateODTfromHTMLCode(ODTInternalParams $params, $HTMLC
$closed = false;

for ($in = $out+1 ; $in < count($parsed) ; $in++) {
$search = $parsed [$in];
$search = &$parsed [$in];
if ($search ['tag-close'] !== NULL &&
$found ['tag-open'] == $search ['tag-close'] &&
(array_key_exists($found ['tag-open'], $elements) || $found ['tag-open'] == 'span')) {
$search ['matched'] === false &&
array_key_exists($found ['tag-open'], $elements)) {

$closed = true;
$search ['matched'] = true;

// Remeber the first element
if ($first) {
Expand Down

0 comments on commit 52ba770

Please sign in to comment.