Syntax Highlighter für TYPO3

GreenBanana GmbH hat für den Eigengebrauch eine TYPO3-Erweiterung programmiert, mit der Quelltext in verschiedenen Sprachen publiziert werden kann.

Websitebetreiber erhalten damit eine einfache Möglichkeit mit wenigen Klicks Quellcode lesbar und übersichtlich darzustellen.

Die Extension ist im offiziellen TYPO3 Extension Repository erhältlich.

Ein herzliches Dankeschen möchten wir an Herr Alex Gorbatchev richten. Er hat die verwendete JavaScript-Library programmiert.

  • Einfache Pflege des anzuzeigenden Quellcodes
  • Mehrwert für die Community dank einfachem Export

Beispiel: PHP

/**
 * initializes the flexform and all config options ;-)
 */
function init(){
    $this->pi_initPIflexForm(); // Init and get the flexform data of the plugin
    $this->lConf = array(); // Setup our storage array...
    // Assign the flexform data to a local variable for easier access
    $piFlexForm = $this->cObj->data['pi_flexform'];
    // Traverse the entire array based on the language...
    // and assign each configuration option to $this->lConf array...
    foreach ( $piFlexForm['data'] as $sheet => $data ) {
        foreach ( $data as $lang => $value ) {
            foreach ( $value as $key => $val ) {
                $this->lConf[$key] = $this->pi_getFFvalue($piFlexForm, $key, $sheet);
            }
        }
    }
}

Beispiel: JavaScript

/**
 * Creates new toolbar for a highlighter.
 * @param {Highlighter} highlighter    Target highlighter.
 */
create : function(highlighter)
{
	var div = document.createElement('DIV'),
		items = sh.toolbar.items
		;
	
	div.className = 'toolbar';
	for (var name in items) 
	{
		var constructor = items[name],
			command = new constructor(highlighter),
			element = command.create()
			;
		highlighter.toolbarCommands[name] = command;
		if (element == null)
			continue;
		if (typeof(element) == 'string')
			element = sh.toolbar.createButton(element, highlighter.id, name);	
		element.className += 'item ' + name;
		div.appendChild(element);
	}
	return div;
},

Beispiel: XML

<T3DataStructure>
    <sheets>
        <sheet1>
            <ROOT>
                <TCEforms>
                    <sheetTitle>Syntax-Highlighter</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <codesnippet>
                        <TCEforms>
                            <label>Code Snippet</label>
                            <config>
                                <type>text</type>
                                <cols>30</cols>
                                <rows>20</rows>
                            </config>
                        </TCEforms>
                    </codesnippet>
                    <language>
                        <TCEforms>
                            <label>Language</label>
							<config>
							 <type>select</type>
							 <items type="array">
							   <numIndex index="0" type="array">
							    <numIndex index="0">Plain</numIndex>
							    <numIndex index="1">plain</numIndex>
							   </numIndex>
							   <numIndex index="1" type="array">
							    <numIndex index="0">Bash</numIndex>
							    <numIndex index="1">bash</numIndex>
							    </numIndex>						   
							  </items>
							</config>
                        </TCEforms>
                    </language>
                </el>
            </ROOT>
        </sheet1>		
    </sheets>
</T3DataStructure>