<?php
/* .-= ds_lib.php4 =======================================================-. *\
* | DragonSpeak Manipulation Library 1.0 | *
* |=======================================================================| *
* | This library was derived from Ecu's DragonSpeak parser and provides | *
* | functions to display DragonSpeak with HTML-based syntax hilighting | *
* | along with possible some other features. | *
* | | *
* | Rewritten by Artex <artex@furcadia.com> http://icerealm.quickfox.org/ | *
\* '-=====================================================================-' */
/*** Configuration ***/
// These colors will be used in syntax hilighting. If you don't want to use
// them, but would rather rely on custom CSS, use ds_hilight($data,true).
'ds_line' => '#409070',
'ds_variable' => '#904090',
'ds_number' => '#907040',
'ds_remark' => '#4070A0'
);
/*** Functions ***/
// Purpose: Application of syntax hilighting on specific DragonSpeak data.
// Returns: A string with the DragonSpeak syntax hilighting applied to it.
function ds_hilight( $data, $custom_css = false )
{
global $ds_colors;
// Setting the <span/> tags.
if( $custom_css )
{
$span_ds_line = "<span class='ds_line'>";
$span_ds_variable = "<span class='ds_variable'>";
$span_ds_number = "<span class='ds_number'>";
$span_ds_remark = "<span class='ds_remark'>";
}
else
{
$span_ds_line = "<span style='color: $ds_colors[ds_line];'>";
$span_ds_variable = "<span style='color: $ds_colors[ds_variable];'>";
$span_ds_number = "<span style='color: $ds_colors[ds_number];'>";
$span_ds_remark = "<span style='color: $ds_colors[ds_remark]; font-style: italic;'>";
}
$span_off = "</span>";
// If this is a string, turn this into an array.
$buffer = '';
// Parsing line-by-line.
foreach( $data as $line )
{
// Converting all <, > and & so they're not mistaken with HTML.
$order = array( "<", ">" );
$replace = array( "<", ">" );
// Marking remarked text for the future so it won't be colored - we already did.
$order = '/^(\s*)([\*&a-zA-Z].*)/';
$replace = "*\\1$span_ds_remark\\2$span_off";
// Spaces
$order = array( " ", " ", " ", " ", " " );
$replace = " ";
$line = str_replace( "\t", " ", $line );
// Handle DSPK & Endtriggers Line
if( $line[0] != '*' )
{
'/(?<=[^\d])(\d+)(?=[^\d])(?![^()\r\n]{0,10}\))(?![^{}\r\n]{0,10}\})/',
'/(\(\s*\d+\s*:\s*\d+\s*\))/',
'/(\(\s*(?:\d+|%\w+(?:\.[xy]))\s*(?:,\s*(?:\d+|%\w+(?:\.[xy]))\s*)?\))/',
'/(%\w+(?:\.[xy]))/',
'/(%\w+(?:))/',
'/({.*?})/',
'/^\s/',
"/\n/"
);
"$span_ds_number\\0$span_off",
"$span_ds_line\\0$span_off",
"$span_ds_number\\0$span_off",
"$span_ds_variable\\0$span_off",
"$span_ds_variable\\0$span_off",
"$span_ds_number\\0$span_off",
" ",
""
);
}
else
{
}
// End of line.
}
// Returning converted data.
return $buffer;
}
?>