Permalink
Browse files

Added support for additional GeShi highlighting options

Also see https://www.dokuwiki.org/wiki:syntax_highlighting_details.

This also improves function 'ODTUtility::generateODTfromHTMLCode()':
It now supports the 'start' attribute for 'ol' elements and the 'class'
attribute for 'li' elements.
  • Loading branch information...
LarsGit223 committed Apr 28, 2018
1 parent b34d220 commit caaddb83eef6f53a6bcd5601984b353886b184ce
Showing with 66 additions and 7 deletions.
  1. +60 −1 ODT/ODTUtility.php
  2. +6 −6 renderer/page.php
@@ -665,6 +665,29 @@ protected static function createTextStyle (ODTInternalParams $params, $element,
}
}
protected static function createParagraphStyle (ODTInternalParams $params, $element, $attributes, $styleName=NULL) {
// Create automatic style
if ($styleName == NULL || !$params->document->styleExists($styleName)) {
// Get properties
$properties = array();
self::getHTMLElementProperties ($params, $properties, $element, $attributes);
if ($styleName == NULL) {
$properties ['style-name'] = ODTStyle::getNewStylename ('span');
} else {
// Use callers style name. He needs to be sure that it's unique!
$properties ['style-name'] = $styleName;
}
$params->document->createParagraphStyle($properties, false);
// Return style name
return $properties ['style-name'];
} else {
// Style already exists
return $styleName;
}
}
public static function generateODTfromHTMLCode(ODTInternalParams $params, $HTMLCode, array $options){
$elements = array ('sup' => array ('open' => '<text:span text:style-name="sup">',
'close' => '</text:span>'),
@@ -781,6 +804,7 @@ public static function generateODTfromHTMLCode(ODTInternalParams $params, $HTMLC
$checked = array();
$first = true;
$firstTag = '';
$olStartValue = NULL;
for ($out = 0 ; $out < count($parsed) ; $out++) {
if ($checked [$out] !== NULL) {
continue;
@@ -850,9 +874,44 @@ public static function generateODTfromHTMLCode(ODTInternalParams $params, $HTMLC
case 'ol':
$checked [$out] = '<text:list text:style-name="'.$ol_list_style.'" text:continue-numbering="false">';
$checked [$in] = '</text:list>';
if (preg_match('/start="[^"]*"/', $found ['attributes'], $matches) == 1) {
$olStartValue = substr($matches [0], 7);
$olStartValue = trim($olStartValue, '"');
}
break;
case 'li':
$checked [$out] = '<text:list-item><text:p text:style-name="'.$p_list_style.'">';
// Create ODT span using CSS style from attributes
$haveClass = false;
if (!empty($options ['class'])) {
if (preg_match('/class="[^"]*"/', $found ['attributes'], $matches) == 1) {
$class_attr = substr($matches [0], 7);
$class_attr = trim($class_attr, '"');
$class_attr = 'class="'.$options ['class'].' '.$class_attr.'"';
$found ['attributes'] = str_replace($matches [0], $class_attr, $found ['attributes']);
$haveClass = true;
}
}
$style_name = NULL;
if ($options ['style_names'] == 'prefix_and_class') {
if (preg_match('/class="[^"]*"/', $found ['attributes'], $matches) == 1) {
$class_attr = substr($matches [0], 7);
$class_attr = trim($class_attr, '"');
$style_name = $options ['style_names_prefix'].$class_attr;
$haveClass = true;
}
}
if ($haveClass) {
$style_name = self::createParagraphStyle ($params, 'li', $found ['attributes'], $style_name);
} else {
$style_name = $p_list_style;
}
$checked [$out] = '<text:list-item';
if ($olStartValue !== NULL) {
$checked [$out] .= ' text:start-value="'.$olStartValue.'"';
$olStartValue = NULL;
}
$checked [$out] .= '><text:p text:style-name="'.$style_name.'">';
$checked [$in] = '</text:p></text:list-item>';
break;
default:
@@ -1013,8 +1013,8 @@ function preformatted($text) {
* @param string $language programming language to use for syntax highlighting
* @param string $filename file path label
*/
function file($text, $language=null, $filename=null) {
$this->_highlight('file', $text, $language);
function file($text, $language=null, $filename=null, $options=null) {
$this->_highlight('file', $text, $language, $options);
}
function quote_open() {
@@ -1032,8 +1032,8 @@ function quote_close() {
* @param string $language programming language to use for syntax highlighting
* @param string $filename file path label
*/
function code($text, $language=null, $filename=null) {
$this->_highlight('code', $text, $language);
function code($text, $language=null, $filename=null, $options=null) {
$this->_highlight('code', $text, $language, $options);
}
/**
@@ -1103,15 +1103,15 @@ protected function createGeshiListStyle () {
* @param string $text
* @param string $language
*/
function _highlight($type, $text, $language=null) {
function _highlight($type, $text, $language=null, $options = null) {
if (is_null($language)) {
$this->_preformatted($text, $style_name);
return;
}
// Use cached geshi
$highlighted_code = p_xhtml_cached_geshi($text, $language, '');
$highlighted_code = p_xhtml_cached_geshi($text, $language, '', $options);
// Create Geshi styles required for ODT and get ODT sourcecode style
$this->createGeshiListStyle ();

0 comments on commit caaddb8

Please sign in to comment.