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
|
// 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>))/');
|
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
|
* Converts a string with html inside into an odt compatible string
|
||||||
* @param string The text to convert
|
* @param string The text to convert
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function htmlToOdt($htmlText) {
|
public static function htmlToOdt($htmlText)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
Default styles:
|
Default styles:
|
||||||
|
|
||||||
@ -59,7 +61,8 @@ class HtmlToOdtConverter {
|
|||||||
* @param array $tags An array with html tags generated by the getDataFromHtml() function
|
* @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
|
* @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 ($customStyles == null) $customStyles = array();
|
||||||
if ($fontDeclarations == null) $fontDeclarations = array();
|
if ($fontDeclarations == null) $fontDeclarations = array();
|
||||||
|
|
||||||
@ -69,7 +72,7 @@ class HtmlToOdtConverter {
|
|||||||
// Check if the current item is a tag or just plain text
|
// Check if the current item is a tag or just plain text
|
||||||
if (isset($tag['text'])) {
|
if (isset($tag['text'])) {
|
||||||
$odtResult .= $tag['text'];
|
$odtResult .= $tag['text'];
|
||||||
} else if (isset($tag['name'])) {
|
} elseif (isset($tag['name'])) {
|
||||||
switch ($tag['name']) {
|
switch ($tag['name']) {
|
||||||
case 'br':
|
case 'br':
|
||||||
$odtResult .= '<text:line-break/>';
|
$odtResult .= '<text:line-break/>';
|
||||||
@ -145,7 +148,8 @@ class HtmlToOdtConverter {
|
|||||||
* Checks if the given text is a html string
|
* Checks if the given text is a html string
|
||||||
* @param string $text The text to check
|
* @param string $text The text to check
|
||||||
*/
|
*/
|
||||||
public static function isHtmlTag($text) {
|
public static function isHtmlTag($text)
|
||||||
|
{
|
||||||
return preg_match(HTML_REGEX_PATTERN, $text);
|
return preg_match(HTML_REGEX_PATTERN, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +157,8 @@ class HtmlToOdtConverter {
|
|||||||
* Checks if the given text includes a html string
|
* Checks if the given text includes a html string
|
||||||
* @param string $text The text to check
|
* @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);
|
$result = preg_match_all(HTML_REGEX_PATTERN, $text);
|
||||||
return is_numeric($result) && $result > 0;
|
return is_numeric($result) && $result > 0;
|
||||||
}
|
}
|
||||||
@ -162,7 +167,8 @@ class HtmlToOdtConverter {
|
|||||||
* Returns an array of html elements
|
* Returns an array of html elements
|
||||||
* @param string $html A string with html tags
|
* @param string $html A string with html tags
|
||||||
*/
|
*/
|
||||||
private static function getDataFromHtml($html) {
|
private static function getDataFromHtml($html)
|
||||||
|
{
|
||||||
$tags = array();
|
$tags = array();
|
||||||
$tempHtml = $html;
|
$tempHtml = $html;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user