Fixing style errors.
This commit is contained in:
parent
8ce1f5f360
commit
f026b959a2
@ -3,14 +3,16 @@
|
||||
// Learn more about this regex pattern: https://regexr.com/4vi60
|
||||
define('HTML_REGEX_PATTERN', '/<([A-Za-z]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(.*)<\/\1>))/');
|
||||
|
||||
class HtmlToOdtConverter {
|
||||
class HtmlToOdtConverter
|
||||
{
|
||||
|
||||
/**
|
||||
* Converts a string with html inside into an odt compatible string
|
||||
* @param string The text to convert
|
||||
* @return array
|
||||
*/
|
||||
public static function htmlToOdt($htmlText) {
|
||||
public static function htmlToOdt($htmlText)
|
||||
{
|
||||
/*
|
||||
Default styles:
|
||||
|
||||
@ -40,7 +42,7 @@ class HtmlToOdtConverter {
|
||||
'<style:style style:name="subText" style:family="text"><style:text-properties style:text-position="sub 58%" /></style:style>',
|
||||
'<style:style style:name="supText" style:family="text"><style:text-properties style:text-position="super 58%" /></style:style>'
|
||||
);
|
||||
|
||||
|
||||
$odtText = self::replaceHtmlWithOdtTag(self::getDataFromHtml($htmlText), $customStyles, $fontDeclarations);
|
||||
|
||||
foreach ($customStyles as $key => $value) {
|
||||
@ -59,7 +61,8 @@ class HtmlToOdtConverter {
|
||||
* @param array $tags An array with html tags generated by the getDataFromHtml() function
|
||||
* @param array $customStyles An array of style defenitions that should be included inside the odt file
|
||||
*/
|
||||
private static function replaceHtmlWithOdtTag($tags, &$customStyles, &$fontDeclarations) {
|
||||
private static function replaceHtmlWithOdtTag($tags, &$customStyles, &$fontDeclarations)
|
||||
{
|
||||
if ($customStyles == null) $customStyles = array();
|
||||
if ($fontDeclarations == null) $fontDeclarations = array();
|
||||
|
||||
@ -69,7 +72,7 @@ class HtmlToOdtConverter {
|
||||
// Check if the current item is a tag or just plain text
|
||||
if (isset($tag['text'])) {
|
||||
$odtResult .= $tag['text'];
|
||||
} else if (isset($tag['name'])) {
|
||||
} elseif (isset($tag['name'])) {
|
||||
switch ($tag['name']) {
|
||||
case 'br':
|
||||
$odtResult .= '<text:line-break/>';
|
||||
@ -145,7 +148,8 @@ class HtmlToOdtConverter {
|
||||
* Checks if the given text is a html string
|
||||
* @param string $text The text to check
|
||||
*/
|
||||
public static function isHtmlTag($text) {
|
||||
public static function isHtmlTag($text)
|
||||
{
|
||||
return preg_match(HTML_REGEX_PATTERN, $text);
|
||||
}
|
||||
|
||||
@ -153,7 +157,8 @@ class HtmlToOdtConverter {
|
||||
* Checks if the given text includes a html string
|
||||
* @param string $text The text to check
|
||||
*/
|
||||
public static function hasHtmlTag($text) {
|
||||
public static function hasHtmlTag($text)
|
||||
{
|
||||
$result = preg_match_all(HTML_REGEX_PATTERN, $text);
|
||||
return is_numeric($result) && $result > 0;
|
||||
}
|
||||
@ -162,7 +167,8 @@ class HtmlToOdtConverter {
|
||||
* Returns an array of html elements
|
||||
* @param string $html A string with html tags
|
||||
*/
|
||||
private static function getDataFromHtml($html) {
|
||||
private static function getDataFromHtml($html)
|
||||
{
|
||||
$tags = array();
|
||||
$tempHtml = $html;
|
||||
|
||||
@ -231,4 +237,4 @@ class HtmlToOdtConverter {
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user