12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107 |
- <?php
-
-
-
-
-
-
-
-
-
-
- define('GESHI_VERSION', '1.0.7.21');
-
-
- if (!defined('GESHI_ROOT')) {
-
- define('GESHI_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
- }
-
- define('GESHI_LANG_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
-
-
-
-
- define('GESHI_NO_LINE_NUMBERS', 0);
-
- define('GESHI_NORMAL_LINE_NUMBERS', 1);
-
- define('GESHI_FANCY_LINE_NUMBERS', 2);
-
-
-
- define('GESHI_HEADER_NONE', 0);
-
- define('GESHI_HEADER_DIV', 1);
-
- define('GESHI_HEADER_PRE', 2);
-
-
-
- define('GESHI_CAPS_NO_CHANGE', 0);
-
- define('GESHI_CAPS_UPPER', 1);
-
- define('GESHI_CAPS_LOWER', 2);
-
-
-
- define('GESHI_LINK', 0);
-
- define('GESHI_HOVER', 1);
-
- define('GESHI_ACTIVE', 2);
-
- define('GESHI_VISITED', 3);
-
-
-
-
-
- define('GESHI_START_IMPORTANT', '<BEGIN GeSHi>');
-
- define('GESHI_END_IMPORTANT', '<END GeSHi>');
-
-
-
-
- define('GESHI_NEVER', 0);
-
- define('GESHI_MAYBE', 1);
-
- define('GESHI_ALWAYS', 2);
-
-
-
- define('GESHI_SEARCH', 0);
-
- define('GESHI_REPLACE', 1);
-
- define('GESHI_MODIFIERS', 2);
-
- define('GESHI_BEFORE', 3);
-
- define('GESHI_AFTER', 4);
-
- define('GESHI_CLASS', 5);
-
-
- define('GESHI_COMMENTS', 0);
-
-
-
- define('GESHI_ERROR_NO_INPUT', 1);
-
- define('GESHI_ERROR_NO_SUCH_LANG', 2);
-
- define('GESHI_ERROR_FILE_NOT_READABLE', 3);
-
- define('GESHI_ERROR_INVALID_HEADER_TYPE', 4);
-
- define('GESHI_ERROR_INVALID_LINE_NUMBER_TYPE', 5);
-
-
-
-
- class GeSHi
- {
-
-
-
-
- public $source = '';
-
-
-
- public $language = '';
-
-
-
- public $language_data = array();
-
-
-
- public $language_path = GESHI_LANG_ROOT;
-
-
-
- public $error = false;
-
-
-
- public $error_messages = array(
- GESHI_ERROR_NO_SUCH_LANG => 'GeSHi could not find the language {LANGUAGE} (using path {PATH})',
- GESHI_ERROR_FILE_NOT_READABLE => 'The file specified for load_from_file was not readable',
- GESHI_ERROR_INVALID_HEADER_TYPE => 'The header type specified is invalid',
- GESHI_ERROR_INVALID_LINE_NUMBER_TYPE => 'The line number type specified is invalid'
- );
-
-
-
- public $strict_mode = false;
-
-
-
- public $use_classes = false;
-
-
-
- public $header_type = GESHI_HEADER_PRE;
-
-
-
- public $lexic_permissions = array(
- 'KEYWORDS' => array(),
- 'COMMENTS' => array('MULTI' => true),
- 'REGEXPS' => array(),
- 'ESCAPE_CHAR' => true,
- 'BRACKETS' => true,
- 'SYMBOLS' => false,
- 'STRINGS' => true,
- 'NUMBERS' => true,
- 'METHODS' => true,
- 'SCRIPT' => true
- );
-
-
-
- public $time = 0;
-
-
-
- public $header_content = '';
-
-
-
- public $footer_content = '';
-
-
-
- public $header_content_style = '';
-
-
-
- public $footer_content_style = '';
-
-
-
- public $force_code_block = false;
-
-
-
- public $link_styles = array();
-
-
-
- public $enable_important_blocks = false;
-
-
-
- public $important_styles = 'font-weight: bold; color: red;';
-
-
-
- public $add_ids = false;
-
-
-
- public $highlight_extra_lines = array();
-
-
-
- public $highlight_extra_lines_styles = array();
-
-
-
- public $highlight_extra_lines_style = 'color: #cc0; background-color: #ffc;';
-
-
-
- public $line_ending = null;
-
-
-
- public $line_numbers_start = 1;
-
-
-
- public $overall_style = '';
-
-
-
- public $code_style = 'font-family: \'Courier New\', Courier, monospace; font-weight: normal;';
-
-
-
- public $overall_class = '';
-
-
-
- public $overall_id = '';
-
-
-
- public $line_style1 = 'font-family: \'Courier New\', Courier, monospace; color: black; font-weight: normal; font-style: normal;';
-
-
-
- public $line_style2 = 'font-weight: bold;';
-
-
-
- public $line_numbers = GESHI_NO_LINE_NUMBERS;
-
-
-
- public $line_nth_row = 0;
-
-
-
- public $tab_width = 8;
-
-
-
- public $use_language_tab_width = false;
-
-
-
- public $link_target = '';
-
-
-
- public $encoding = 'ISO-8859-1';
-
-
-
- public $keyword_links = true;
-
-
-
-
-
- public function GeSHi($source, $language, $path = '')
- {
- $this->set_source($source);
- $this->set_language_path($path);
- $this->set_language($language);
- }
-
-
-
- public function error()
- {
- if ($this->error) {
- $msg = $this->error_messages[$this->error];
- $debug_tpl_vars = array(
- '{LANGUAGE}' => $this->language,
- '{PATH}' => $this->language_path
- );
- foreach ($debug_tpl_vars as $tpl => $var) {
- $msg = str_replace($tpl, $var, $msg);
- }
- return "<br /><strong>GeSHi Error:</strong> $msg (code $this->error)<br />";
- }
- return false;
- }
-
-
-
- public function get_language_name()
- {
- if (GESHI_ERROR_NO_SUCH_LANG == $this->error) {
- return $this->language_data['LANG_NAME'] . ' (Unknown Language)';
- }
- return $this->language_data['LANG_NAME'];
- }
-
-
-
- public function set_source($source)
- {
- $this->source = $source;
- $this->highlight_extra_lines = array();
- }
-
-
-
- public function set_language($language)
- {
- $this->error = false;
- $this->strict_mode = GESHI_NEVER;
-
- $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
- $this->language = strtolower($language);
-
- $file_name = $this->language_path . $this->language . '.php';
-
- if (!is_readable($file_name)) {
- $this->error = GESHI_ERROR_NO_SUCH_LANG;
- return;
- }
-
- $this->load_language($file_name);
- }
-
-
-
- public function set_language_path($path)
- {
- if ($path) {
- $this->language_path = ('/' == substr($path, strlen($path) - 1, 1)) ? $path : $path . '/';
- $this->set_language($this->language);
- }
- }
-
-
-
- public function set_header_type($type)
- {
- if (GESHI_HEADER_DIV != $type && GESHI_HEADER_PRE != $type && GESHI_HEADER_NONE != $type) {
- $this->error = GESHI_ERROR_INVALID_HEADER_TYPE;
- return;
- }
- $this->header_type = $type;
-
- if (GESHI_HEADER_DIV == $type && !$this->overall_style) {
- $this->overall_style = 'font-family: monospace;';
- }
- }
-
-
-
- public function set_overall_style($style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->overall_style = $style;
- } else {
- $this->overall_style .= $style;
- }
- }
-
-
-
- public function set_overall_class($class)
- {
- $this->overall_class = $class;
- }
-
-
-
- public function set_overall_id($id)
- {
- $this->overall_id = $id;
- }
-
-
-
- public function enable_classes($flag = true)
- {
- $this->use_classes = ($flag) ? true : false;
- }
-
-
-
- public function set_code_style($style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->code_style = $style;
- } else {
- $this->code_style .= $style;
- }
- }
-
-
-
- public function set_line_style($style1, $style2 = '', $preserve_defaults = false)
- {
- if (is_bool($style2)) {
- $preserve_defaults = $style2;
- $style2 = '';
- }
- if (!$preserve_defaults) {
- $this->line_style1 = $style1;
- $this->line_style2 = $style2;
- } else {
- $this->line_style1 .= $style1;
- $this->line_style2 .= $style2;
- }
- }
-
-
-
- public function enable_line_numbers($flag, $nth_row = 5)
- {
- if (GESHI_NO_LINE_NUMBERS != $flag && GESHI_NORMAL_LINE_NUMBERS != $flag
- && GESHI_FANCY_LINE_NUMBERS != $flag) {
- $this->error = GESHI_ERROR_INVALID_LINE_NUMBER_TYPE;
- }
- $this->line_numbers = $flag;
- $this->line_nth_row = $nth_row;
- }
-
-
-
- public function set_keyword_group_style($key, $style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['KEYWORDS'][$key] = $style;
- } else {
- $this->language_data['STYLES']['KEYWORDS'][$key] .= $style;
- }
- }
-
-
-
- public function set_keyword_group_highlighting($key, $flag = true)
- {
- $this->lexic_permissions['KEYWORDS'][$key] = ($flag) ? true : false;
- }
-
-
-
- public function set_comments_style($key, $style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['COMMENTS'][$key] = $style;
- } else {
- $this->language_data['STYLES']['COMMENTS'][$key] .= $style;
- }
- }
-
-
-
- public function set_comments_highlighting($key, $flag = true)
- {
- $this->lexic_permissions['COMMENTS'][$key] = ($flag) ? true : false;
- }
-
-
-
- public function set_escape_characters_style($style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['ESCAPE_CHAR'][0] = $style;
- } else {
- $this->language_data['STYLES']['ESCAPE_CHAR'][0] .= $style;
- }
- }
-
-
-
- public function set_escape_characters_highlighting($flag = true)
- {
- $this->lexic_permissions['ESCAPE_CHAR'] = ($flag) ? true : false;
- }
-
-
-
- public function set_brackets_style($style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['BRACKETS'][0] = $style;
- } else {
- $this->language_data['STYLES']['BRACKETS'][0] .= $style;
- }
- }
-
-
-
- public function set_brackets_highlighting($flag)
- {
- $this->lexic_permissions['BRACKETS'] = ($flag) ? true : false;
- }
-
-
-
- public function set_symbols_style($style, $preserve_defaults = false, $group = 0)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['SYMBOLS'][$group] = $style;
- } else {
- $this->language_data['STYLES']['SYMBOLS'][$group] .= $style;
- }
-
- if (0 == $group) {
- $this->set_brackets_style($style, $preserve_defaults);
- }
- }
-
-
-
- public function set_symbols_highlighting($flag)
- {
- $this->lexic_permissions['SYMBOLS'] = ($flag) ? true : false;
-
- $this->set_brackets_highlighting($flag);
- }
-
-
-
- public function set_strings_style($style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['STRINGS'][0] = $style;
- } else {
- $this->language_data['STYLES']['STRINGS'][0] .= $style;
- }
- }
-
-
-
- public function set_strings_highlighting($flag)
- {
- $this->lexic_permissions['STRINGS'] = ($flag) ? true : false;
- }
-
-
-
- public function set_numbers_style($style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['NUMBERS'][0] = $style;
- } else {
- $this->language_data['STYLES']['NUMBERS'][0] .= $style;
- }
- }
-
-
-
- public function set_numbers_highlighting($flag)
- {
- $this->lexic_permissions['NUMBERS'] = ($flag) ? true : false;
- }
-
-
-
- public function set_methods_style($key, $style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['METHODS'][$key] = $style;
- } else {
- $this->language_data['STYLES']['METHODS'][$key] .= $style;
- }
- }
-
-
-
- public function set_methods_highlighting($flag)
- {
- $this->lexic_permissions['METHODS'] = ($flag) ? true : false;
- }
-
-
-
- public function set_regexps_style($key, $style, $preserve_defaults = false)
- {
- if (!$preserve_defaults) {
- $this->language_data['STYLES']['REGEXPS'][$key] = $style;
- } else {
- $this->language_data['STYLES']['REGEXPS'][$key] .= $style;
- }
- }
-
-
-
- public function set_regexps_highlighting($key, $flag)
- {
- $this->lexic_permissions['REGEXPS'][$key] = ($flag) ? true : false;
- }
-
-
-
- public function set_case_sensitivity($key, $case)
- {
- $this->language_data['CASE_SENSITIVE'][$key] = ($case) ? true : false;
- }
-
-
-
- public function set_case_keywords($case)
- {
- if (in_array($case, array(
- GESHI_CAPS_NO_CHANGE, GESHI_CAPS_UPPER, GESHI_CAPS_LOWER))) {
- $this->language_data['CASE_KEYWORDS'] = $case;
- }
- }
-
-
-
- public function set_tab_width($width)
- {
- $this->tab_width = intval($width);
-
- if ($this->tab_width < 1) {
-
- $this->tab_width = 8;
- }
- }
-
-
-
- public function set_use_language_tab_width($use)
- {
- $this->use_language_tab_width = (bool) $use;
- }
-
-
-
- public function get_real_tab_width()
- {
- if (!$this->use_language_tab_width || !isset($this->language_data['TAB_WIDTH'])) {
- return $this->tab_width;
- } else {
- return $this->language_data['TAB_WIDTH'];
- }
- }
-
-
-
- public function enable_strict_mode($mode = true)
- {
- if (GESHI_MAYBE == $this->language_data['STRICT_MODE_APPLIES']) {
- $this->strict_mode = ($mode) ? true : false;
- }
- }
-
-
-
- public function disable_highlighting()
- {
- $this->enable_highlighting(false);
- }
-
-
-
- public function enable_highlighting($flag = true)
- {
- $flag = $flag ? true : false;
- foreach ($this->lexic_permissions as $key => $value) {
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- $this->lexic_permissions[$key][$k] = $flag;
- }
- } else {
- $this->lexic_permissions[$key] = $flag;
- }
- }
-
- $this->enable_important_blocks = $flag;
- }
-
-
-
- public function get_language_name_from_extension($extension, $lookup = array())
- {
- if (!is_array($lookup) || !count($lookup)) {
- $lookup = array(
- 'actionscript' => array('as'),
- 'ada' => array('a', 'ada', 'adb', 'ads'),
- 'apache' => array('conf'),
- 'asm' => array('ash', 'asm'),
- 'asp' => array('asp'),
- 'bash' => array('sh'),
- 'c' => array('c', 'h'),
- 'c_mac' => array('c', 'h'),
- 'caddcl' => array(),
- 'cadlisp' => array(),
- 'cdfg' => array('cdfg'),
- 'cpp' => array('cpp', 'h', 'hpp'),
- 'csharp' => array(),
- 'css' => array('css'),
- 'delphi' => array('dpk', 'dpr', 'pp', 'pas'),
- 'dos' => array('bat', 'cmd'),
- 'html4strict' => array('html', 'htm'),
- 'java' => array('java'),
- 'javascript' => array('js'),
- 'lisp' => array('lisp'),
- 'lua' => array('lua'),
- 'mpasm' => array(),
- 'nsis' => array(),
- 'objc' => array(),
- 'oobas' => array(),
- 'oracle8' => array(),
- 'pascal' => array(),
- 'perl' => array('pl', 'pm'),
- 'php' => array('php', 'php5', 'phtml', 'phps'),
- 'python' => array('py'),
- 'qbasic' => array('bi'),
- 'sas' => array('sas'),
- 'smarty' => array(),
- 'vb' => array('bas'),
- 'vbnet' => array(),
- 'visualfoxpro' => array(),
- 'xml' => array('xml')
- );
- }
-
- foreach ($lookup as $lang => $extensions) {
- foreach ($extensions as $ext) {
- if ($ext == $extension) {
- return $lang;
- }
- }
- }
- return '';
- }
-
-
-
- public function load_from_file($file_name, $lookup = array())
- {
- if (is_readable($file_name)) {
- $this->set_source(implode('', file($file_name)));
- $this->set_language($this->get_language_name_from_extension(substr(strrchr($file_name, '.'), 1), $lookup));
- } else {
- $this->error = GESHI_ERROR_FILE_NOT_READABLE;
- }
- }
-
-
-
- public function add_keyword($key, $word)
- {
- $this->language_data['KEYWORDS'][$key][] = $word;
- }
-
-
-
- public function remove_keyword($key, $word)
- {
- $this->language_data['KEYWORDS'][$key] =
- array_diff($this->language_data['KEYWORDS'][$key], array($word));
- }
-
-
-
- public function add_keyword_group($key, $styles, $case_sensitive = true, $words = array())
- {
- $words = (array) $words;
- $this->language_data['KEYWORDS'][$key] = $words;
- $this->lexic_permissions['KEYWORDS'][$key] = true;
- $this->language_data['CASE_SENSITIVE'][$key] = $case_sensitive;
- $this->language_data['STYLES']['KEYWORDS'][$key] = $styles;
- }
-
-
-
- public function remove_keyword_group($key)
- {
- unset($this->language_data['KEYWORDS'][$key]);
- unset($this->lexic_permissions['KEYWORDS'][$key]);
- unset($this->language_data['CASE_SENSITIVE'][$key]);
- unset($this->language_data['STYLES']['KEYWORDS'][$key]);
- }
-
-
-
- public function set_header_content($content)
- {
- $this->header_content = $content;
- }
-
-
-
- public function set_footer_content($content)
- {
- $this->footer_content = $content;
- }
-
-
-
- public function set_header_content_style($style)
- {
- $this->header_content_style = $style;
- }
-
-
-
- public function set_footer_content_style($style)
- {
- $this->footer_content_style = $style;
- }
-
-
-
- public function enable_inner_code_block($flag)
- {
- $this->force_code_block = (bool)$flag;
- }
-
-
-
- public function set_url_for_keyword_group($group, $url)
- {
- $this->language_data['URLS'][$group] = $url;
- }
-
-
-
- public function set_link_styles($type, $styles)
- {
- $this->link_styles[$type] = $styles;
- }
-
-
-
- public function set_link_target($target)
- {
- if (!$target) {
- $this->link_target = '';
- } else {
- $this->link_target = ' target="' . $target . '" ';
- }
- }
-
-
-
- public function set_important_styles($styles)
- {
- $this->important_styles = $styles;
- }
-
-
-
- public function enable_important_blocks($flag)
- {
- $this->enable_important_blocks = ($flag) ? true : false;
- }
-
-
-
- public function enable_ids($flag = true)
- {
- $this->add_ids = ($flag) ? true : false;
- }
-
-
-
- public function highlight_lines_extra($lines, $style = null)
- {
- if (is_array($lines)) {
- foreach ($lines as $line) {
- $this->highlight_lines_extra(line, $style);
- }
- } else {
- $this->highlight_extra_lines[intval($lines)] = intval($lines);
- if ($style != null) {
- $this->highlight_extra_lines_styles[intval($lines)] = $style;
- } else {
- unset($this->highlight_extra_lines_styles[intval($lines)]);
- }
- }
- }
-
-
-
- public function set_highlight_lines_extra_style($styles)
- {
- $this->highlight_extra_lines_style = $styles;
- }
-
-
-
- public function set_line_ending($line_ending)
- {
- $this->line_ending = (string)$line_ending;
- }
-
-
-
- public function start_line_numbers_at($number)
- {
- $this->line_numbers_start = abs(intval($number));
- }
-
-
-
- public function set_encoding($encoding)
- {
- if ($encoding) {
- $this->encoding = $encoding;
- }
- }
-
-
-
- public function enable_keyword_links($enable = true)
- {
- $this->keyword_links = ($enable) ? true : false;
- }
-
-
-
- public function parse_code()
- {
-
- $start_time = microtime();
-
-
-
- if ($this->error) {
- $result = GeSHi::hsc($this->source);
-
- $this->set_time($start_time, $start_time);
- return $this->finalise($result);
- }
-
- $code = str_replace("\r\n", "\n", $this->source);
- $code = str_replace("\r", "\n", $code);
-
- $code = "\n" . $code . "\n";
-
-
- $length = strlen($code);
- $STRING_OPEN = '';
- $CLOSE_STRING = false;
- $ESCAPE_CHAR_OPEN = false;
- $COMMENT_MATCHED = false;
-
- $HIGHLIGHTING_ON = (!$this->strict_mode) ? true : '';
-
- $HIGHLIGHT_INSIDE_STRICT = false;
- $HARDQUOTE_OPEN = false;
- $STRICTATTRS = '';
- $stuff_to_parse = '';
- $result = '';
-
-
-
- if ($this->enable_important_blocks) {
- $this->language_data['COMMENT_MULTI'][GESHI_START_IMPORTANT] = GESHI_END_IMPORTANT;
- }
-
- if ($this->strict_mode) {
-
-
- $parts = array(0 => array(0 => ''));
- $k = 0;
- for ($i = 0; $i < $length; $i++) {
- $char = substr($code, $i, 1);
- if (!$HIGHLIGHTING_ON) {
- foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) {
- foreach ($delimiters as $open => $close) {
-
- $check = substr($code, $i, strlen($open));
-
- if ($check == $open) {
-
-
- $HIGHLIGHTING_ON = $open;
- $i += strlen($open) - 1;
- $char = $open;
- $parts[++$k][0] = $char;
-
-
- break(2);
- }
- }
- }
- } else {
- foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) {
- foreach ($delimiters as $open => $close) {
- if ($open == $HIGHLIGHTING_ON) {
-
- break(2);
- }
- }
- }
-
-
- $check = substr($code, $i - strlen($close) + 1, strlen($close));
- if ($check == $close) {
- $HIGHLIGHTING_ON = '';
-
- $parts[$k][1] = (isset($parts[$k][1])) ? $parts[$k][1] . $char : $char;
- $parts[++$k][0] = '';
- $char = '';
- }
- }
- $parts[$k][1] = (isset($parts[$k][1])) ? $parts[$k][1] . $char : $char;
- }
- $HIGHLIGHTING_ON = '';
- } else {
-
-
- $parts = array(
- 1 => array(
- 0 => '',
- 1 => $code
- )
- );
- }
-
-
-
-
- foreach ($parts as $key => $data) {
- $part = $data[1];
-
- if ($key % 2) {
- if ($this->strict_mode) {
-
- foreach ($this->language_data['SCRIPT_DELIMITERS'] as $script_key => $script_data) {
- foreach ($script_data as $open => $close) {
- if ($data[0] == $open) {
- break(2);
- }
- }
- }
-
- if ($this->language_data['STYLES']['SCRIPT'][$script_key] != '' &&
- $this->lexic_permissions['SCRIPT']) {
-
-
- if (!$this->use_classes &&
- $this->language_data['STYLES']['SCRIPT'][$script_key] != '') {
- $attributes = ' style="' . $this->language_data['STYLES']['SCRIPT'][$script_key] . '"';
- } else {
- $attributes = ' class="sc' . $script_key . '"';
- }
- $result .= "<span$attributes>";
- $STRICTATTRS = $attributes;
- }
- }
-
- if (!$this->strict_mode || $this->language_data['HIGHLIGHT_STRICT_BLOCK'][$script_key]) {
-
-
-
- $length = strlen($part);
- for ($i = 0; $i < $length; $i++) {
-
- $char = substr($part, $i, 1);
- $hq = isset($this->language_data['HARDQUOTE']) ? $this->language_data['HARDQUOTE'][0] : false;
-
- if (($this->line_numbers != GESHI_NO_LINE_NUMBERS
- || count($this->highlight_extra_lines) > 0)
- && $char == "\n") {
-
-
-
-
-
- if ($STRING_OPEN) {
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';
- } else {
- $attributes = ' class="st0"';
- }
- $char = '</span>' . $char . "<span$attributes>";
- }
- } elseif ($char == $STRING_OPEN) {
-
- if (($this->lexic_permissions['ESCAPE_CHAR'] && $ESCAPE_CHAR_OPEN) ||
- ($this->lexic_permissions['STRINGS'] && !$ESCAPE_CHAR_OPEN)) {
- $char = GeSHi::hsc($char) . '</span>';
- }
- $escape_me = false;
- if ($HARDQUOTE_OPEN) {
- if ($ESCAPE_CHAR_OPEN) {
- $escape_me = true;
- } else {
- foreach ($this->language_data['HARDESCAPE'] as $hardesc) {
- if (substr($part, $i, strlen($hardesc)) == $hardesc) {
- $escape_me = true;
- break;
- }
- }
- }
- }
-
- if (!$ESCAPE_CHAR_OPEN) {
- $STRING_OPEN = '';
- $CLOSE_STRING = true;
- }
- if (!$escape_me) {
- $HARDQUOTE_OPEN = false;
- }
- $ESCAPE_CHAR_OPEN = false;
- } elseif (in_array($char, $this->language_data['QUOTEMARKS']) &&
- ($STRING_OPEN == '') && $this->lexic_permissions['STRINGS']) {
-
- $STRING_OPEN = $char;
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';
- } else {
- $attributes = ' class="st0"';
- }
- $char = "<span$attributes>" . GeSHi::hsc($char);
-
- $result .= $this->parse_non_string_part($stuff_to_parse);
- $stuff_to_parse = '';
- } elseif ($hq && substr($part, $i, strlen($hq)) == $hq &&
- ($STRING_OPEN == '') && $this->lexic_permissions['STRINGS']) {
-
- $STRING_OPEN = $this->language_data['HARDQUOTE'][1];
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['STRINGS'][0] . '"';
- } else {
- $attributes = ' class="st0"';
- }
- $char = "<span$attributes>" . $hq;
- $i += strlen($hq) - 1;
- $HARDQUOTE_OPEN = true;
- $result .= $this->parse_non_string_part($stuff_to_parse);
- $stuff_to_parse = '';
- } elseif ($char == $this->language_data['ESCAPE_CHAR'] && $STRING_OPEN != '') {
-
- if (!$ESCAPE_CHAR_OPEN) {
- $ESCAPE_CHAR_OPEN = !$HARDQUOTE_OPEN;
- if ($HARDQUOTE_OPEN) {
- foreach ($this->language_data['HARDESCAPE'] as $hard) {
- if (substr($part, $i, strlen($hard)) == $hard) {
- $ESCAPE_CHAR_OPEN = true;
- break;
- }
- }
- }
- if ($ESCAPE_CHAR_OPEN && $this->lexic_permissions['ESCAPE_CHAR']) {
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['ESCAPE_CHAR'][0] . '"';
- } else {
- $attributes = ' class="es0"';
- }
- $char = "<span$attributes>" . $char;
- if (substr($code, $i + 1, 1) == "\n") {
-
-
- $char .= '</span>';
- $ESCAPE_CHAR_OPEN = false;
- }
- }
- } else {
- $ESCAPE_CHAR_OPEN = false;
- if ($this->lexic_permissions['ESCAPE_CHAR']) {
- $char .= '</span>';
- }
- }
- } elseif ($ESCAPE_CHAR_OPEN) {
- if ($this->lexic_permissions['ESCAPE_CHAR']) {
- $char .= '</span>';
- }
- $ESCAPE_CHAR_OPEN = false;
- $test_str = $char;
- } elseif ($STRING_OPEN == '') {
-
- foreach ($this->language_data['COMMENT_MULTI'] as $open => $close) {
- $com_len = strlen($open);
- $test_str = substr($part, $i, $com_len);
- $test_str_match = $test_str;
- if (strtolower($open) == strtolower($test_str)) {
- $COMMENT_MATCHED = true;
-
- if ($this->lexic_permissions['COMMENTS']['MULTI'] ||
- $test_str == GESHI_START_IMPORTANT) {
- if ($test_str != GESHI_START_IMPORTANT) {
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS']['MULTI'] . '"';
- } else {
- $attributes = ' class="coMULTI"';
- }
- $test_str = "<span$attributes>" . GeSHi::hsc($test_str);
- } else {
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->important_styles . '"';
- } else {
- $attributes = ' class="imp"';
- }
-
-
- $test_str = "<span$attributes>";
- }
- } else {
- $test_str = GeSHi::hsc($test_str);
- }
-
- $close_pos = strpos($part, $close, $i + strlen($close));
-
- $oops = false;
- if ($close_pos === false) {
- $close_pos = strlen($part);
- $oops = true;
- } else {
- $close_pos -= ($com_len - strlen($close));
- }
-
-
- $rest_of_comment = GeSHi::hsc(substr($part, $i + $com_len, $close_pos - $i));
- if (($this->lexic_permissions['COMMENTS']['MULTI'] ||
- $test_str_match == GESHI_START_IMPORTANT) &&
- ($this->line_numbers != GESHI_NO_LINE_NUMBERS ||
- count($this->highlight_extra_lines) > 0)) {
-
- $test_str .= str_replace(
- "\n", "</span>\n<span$attributes>",
- str_replace("\n ", "\n ", $rest_of_comment)
- );
- } else {
- $test_str .= $rest_of_comment;
- }
-
- if ($this->lexic_permissions['COMMENTS']['MULTI'] ||
- $test_str_match == GESHI_START_IMPORTANT) {
- $test_str .= '</span>';
- if ($oops) {
- $test_str .= "\n";
- }
- }
- $i = $close_pos + $com_len - 1;
-
- $result .= $this->parse_non_string_part($stuff_to_parse);
- $stuff_to_parse = '';
- break;
- }
- }
-
- if (!$COMMENT_MATCHED) {
- foreach ($this->language_data['COMMENT_SINGLE'] as $comment_key => $comment_mark) {
- $com_len = strlen($comment_mark);
- $test_str = substr($part, $i, $com_len);
- if ($this->language_data['CASE_SENSITIVE'][GESHI_COMMENTS]) {
- $match = ($comment_mark == $test_str);
- } else {
- $match = (strtolower($comment_mark) == strtolower($test_str));
- }
-
- if ($match) {
- $disallowed_before = "";
- $disallowed_after = "";
-
- if (isset($this->language_data['PARSER_CONTROL'])) {
- if (isset($this->language_data['PARSER_CONTROL']['COMMENTS'])) {
- if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE'])) {
- $disallowed_before = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_BEFORE'];
- }
- if (isset($this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER'])) {
- $disallowed_after = $this->language_data['PARSER_CONTROL']['COMMENTS']['DISALLOWED_AFTER'];
- }
- }
- }
-
- $match = $match && (!strlen($disallowed_before) || ((false === strpos($disallowed_before, substr($part, $i-1, 1))) && (0!=$i)));
- $match = $match && (!strlen($disallowed_after) || ((false === strpos($disallowed_after, substr($part, $i+1, 1))) && (strlen($part)-1>$i)));
- }
- if ($match) {
- $COMMENT_MATCHED = true;
- if ($this->lexic_permissions['COMMENTS'][$comment_key]) {
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['COMMENTS'][$comment_key] . '"';
- } else {
- $attributes = ' class="co' . $comment_key . '"';
- }
- $test_str = "<span$attributes>" . GeSHi::hsc($this->change_case($test_str));
- } else {
- $test_str = GeSHi::hsc($test_str);
- }
- $close_pos = strpos($part, "\n", $i);
- $oops = false;
- if ($close_pos === false) {
- $close_pos = strlen($part);
- $oops = true;
- }
- $test_str .= GeSHi::hsc(substr($part, $i + $com_len, $close_pos - $i - $com_len));
- if ($this->lexic_permissions['COMMENTS'][$comment_key]) {
- $test_str .= "</span>";
- }
-
- if (!$oops) {
- $test_str .= "\n";
- }
- $i = $close_pos;
-
- $result .= $this->parse_non_string_part($stuff_to_parse);
- $stuff_to_parse = '';
- break;
- }
- }
- }
- } elseif ($STRING_OPEN != '') {
-
- if (strtolower($this->encoding) == 'utf-8') {
-
- if (ord($char) < 128) {
- $char = GeSHi::hsc($char);
- }
- } else {
-
- $char = GeSHi::hsc($char);
- }
- }
-
- if (!$COMMENT_MATCHED) {
- if (($STRING_OPEN == '') && !$CLOSE_STRING) {
- $stuff_to_parse .= $char;
- } else {
- $result .= $char;
- $CLOSE_STRING = false;
- }
- } else {
- $result .= $test_str;
- $COMMENT_MATCHED = false;
- }
- }
-
- $result .= $this->parse_non_string_part($stuff_to_parse);
- $stuff_to_parse = '';
- } else {
- if ($STRICTATTRS != '') {
- $part = str_replace("\n", "</span>\n<span$STRICTATTRS>", GeSHi::hsc($part));
- $STRICTATTRS = '';
- }
- $result .= $part;
- }
-
- if ($this->strict_mode && $this->language_data['STYLES']['SCRIPT'][$script_key] != '' &&
- $this->lexic_permissions['SCRIPT']) {
- $result .= '</span>';
- }
- } else {
-
- $result .= GeSHi::hsc($part);
- }
- }
-
-
- $result .= $this->parse_non_string_part($stuff_to_parse);
-
-
- $result = substr($result, 1, -1);
-
-
- if ($STRING_OPEN) {
- $result .= '</span>';
- }
-
-
- $this->set_time($start_time, microtime());
-
- return $this->finalise($result);
- }
-
-
-
- public function indent($result)
- {
-
- if (false !== strpos($result, "\t")) {
- $lines = explode("\n", $result);
- $tab_width = $this->get_real_tab_width();
- foreach ($lines as $key => $line) {
- if (false === strpos($line, "\t")) {
- $lines[$key] = $line;
- continue;
- }
-
- $pos = 0;
- $length = strlen($line);
- $result_line = '';
-
- $IN_TAG = false;
- for ($i = 0; $i < $length; $i++) {
- $char = substr($line, $i, 1);
-
-
-
-
-
-
-
- if ($IN_TAG && '>' == $char) {
- $IN_TAG = false;
- $result_line .= '>';
- ++$pos;
- } elseif (!$IN_TAG && '<' == $char) {
- $IN_TAG = true;
- $result_line .= '<';
- ++$pos;
- } elseif (!$IN_TAG && '&' == $char) {
- $substr = substr($line, $i + 3, 4);
-
- $posi = strpos($substr, ';');
- if (false !== $posi) {
- $pos += $posi + 3;
- }
- $result_line .= '&';
- } elseif (!$IN_TAG && "\t" == $char) {
- $str = '';
-
-
-
-
-
-
- $strs = array(0 => ' ', 1 => ' ');
- for ($k = 0; $k < ($tab_width - (($i - $pos) % $tab_width)); $k++) {
- $str .= $strs[$k % 2];
- }
- $result_line .= $str;
- $pos += ($i - $pos) % $tab_width + 1;
-
- if (false === strpos($line, "\t", $i + 1)) {
- $result_line .= substr($line, $i + 1);
- break;
- }
- } elseif ($IN_TAG) {
- ++$pos;
- $result_line .= $char;
- } else {
- $result_line .= $char;
-
- }
- }
- $lines[$key] = $result_line;
- }
- $result = implode("\n", $lines);
- }
-
-
- $result = preg_replace('/^ /m', ' ', $result);
- $result = str_replace(' ', ' ', $result);
-
- if ($this->line_numbers == GESHI_NO_LINE_NUMBERS) {
- if ($this->line_ending === null) {
- $result = nl2br($result);
- } else {
- $result = str_replace("\n", $this->line_ending, $result);
- }
- }
- return $result;
- }
-
-
-
- public function change_case($instr)
- {
- if ($this->language_data['CASE_KEYWORDS'] == GESHI_CAPS_UPPER) {
- return strtoupper($instr);
- } elseif ($this->language_data['CASE_KEYWORDS'] == GESHI_CAPS_LOWER) {
- return strtolower($instr);
- }
- return $instr;
- }
-
-
-
- public function add_url_to_keyword($keyword, $group, $start_or_end)
- {
- if (!$this->keyword_links) {
-
- return;
- }
-
- if (isset($this->language_data['URLS'][$group]) &&
- $this->language_data['URLS'][$group] != '' &&
- substr($keyword, 0, 5) != '</') {
-
- if ($start_or_end == 'BEGIN') {
-
- if ($keyword != '') {
-
-
-
- foreach ($this->language_data['KEYWORDS'][$group] as $word) {
- if (strtolower($word) == strtolower($keyword)) {
- break;
- }
- }
- $word = (substr($word, 0, 4) == '<') ? substr($word, 4) : $word;
- $word = (substr($word, -4) == '>') ? substr($word, 0, strlen($word) - 4) : $word;
- if (!$word) {
- return '';
- }
-
- return '<|UR1|"' .
- str_replace(
- array('{FNAME}', '{FNAMEL}', '{FNAMEU}', '.'),
- array(GeSHi::hsc($word), GeSHi::hsc(strtolower($word)),
- GeSHi::hsc(strtoupper($word)), '<DOT>'),
- $this->language_data['URLS'][$group]
- ) . '">';
- }
- return '';
-
- } elseif (!($this->language == 'html4strict' && ('>' == $keyword || '<' == $keyword))) {
- return '</a>';
- }
- }
- }
-
-
-
- public function parse_non_string_part(&$stuff_to_parse)
- {
- $stuff_to_parse = ' ' . GeSHi::hsc($stuff_to_parse);
- $stuff_to_parse_pregquote = preg_quote($stuff_to_parse, '/');
- $func = '$this->change_case';
- $func2 = '$this->add_url_to_keyword';
-
-
-
-
- foreach ($this->language_data['REGEXPS'] as $key => $regexp) {
- if ($this->lexic_permissions['REGEXPS'][$key]) {
- if (is_array($regexp)) {
- $stuff_to_parse = preg_replace(
- "/" .
- str_replace('/', '\/', $regexp[GESHI_SEARCH]) .
- "/{$regexp[GESHI_MODIFIERS]}",
- "{$regexp[GESHI_BEFORE]}<|!REG3XP$key!>{$regexp[GESHI_REPLACE]}|>{$regexp[GESHI_AFTER]}",
- $stuff_to_parse
- );
- } else {
- $stuff_to_parse = preg_replace("/(" . str_replace('/', '\/', $regexp) . ")/", "<|!REG3XP$key!>\\1|>", $stuff_to_parse);
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
- if ($this->lexic_permissions['NUMBERS'] && preg_match('#[0-9]#', $stuff_to_parse)) {
- $stuff_to_parse = preg_replace('/([-+]?\\b(?:[0-9]*\\.)?[0-9]+\\b)/', '<|/NUM!/>\\1|>', $stuff_to_parse);
- }
-
-
-
- if (preg_match('#[a-zA-Z]{2,}#', $stuff_to_parse)) {
- foreach ($this->language_data['KEYWORDS'] as $k => $keywordset) {
- if ($this->lexic_permissions['KEYWORDS'][$k]) {
- foreach ($keywordset as $keyword) {
- $keyword = preg_quote($keyword, '/');
-
-
-
-
-
-
- if (false !== stristr($stuff_to_parse_pregquote, $keyword)) {
- $stuff_to_parse .= ' ';
-
-
-
- $styles = "/$k/";
- $modifiers = ($this->language_data['CASE_SENSITIVE'][$k]) ? "e" : "ie";
-
- $disallowed_before = "a-zA-Z0-9\$_\|\#;>|^";
- $disallowed_after = "a-zA-Z0-9_<\|%\\-&";
- if (isset($this->language_data['PARSER_CONTROL'])) {
- if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS'])) {
- if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'])) {
- $disallowed_before = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'];
- }
- if (isset($this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'])) {
- $disallowed_after = $this->language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'];
- }
- }
- }
- $stuff_to_parse = preg_replace(
- "/([^$disallowed_before])($keyword)(?=[^$disallowed_after])/$modifiers",
- "'\\1' . $func2('\\2', '$k', 'BEGIN') . '<|$styles>' . $func('\\2') . '|>' . $func2('\\2', '$k', 'END')",
- $stuff_to_parse
- );
-
- $stuff_to_parse = substr($stuff_to_parse, 0, strlen($stuff_to_parse) - 1);
- }
- }
- }
- }
- }
-
-
-
-
- foreach ($this->language_data['KEYWORDS'] as $k => $kws) {
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['KEYWORDS'][$k] . '"';
- } else {
- $attributes = ' class="kw' . $k . '"';
- }
- $stuff_to_parse = str_replace("/$k/", $attributes, $stuff_to_parse);
- }
-
-
- if (!$this->use_classes && $this->lexic_permissions['NUMBERS']) {
- $attributes = ' style="' . $this->language_data['STYLES']['NUMBERS'][0] . '"';
- } else {
- $attributes = ' class="nu0"';
- }
- $stuff_to_parse = str_replace('/NUM!/', $attributes, $stuff_to_parse);
-
-
-
-
- if ($this->lexic_permissions['METHODS'] && $this->language_data['OOLANG']) {
- foreach ($this->language_data['OBJECT_SPLITTERS'] as $key => $splitter) {
- if (false !== stristr($stuff_to_parse, $splitter)) {
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['METHODS'][$key] . '"';
- } else {
- $attributes = ' class="me' . $key . '"';
- }
- $stuff_to_parse = preg_replace("/(" . preg_quote($this->language_data['OBJECT_SPLITTERS'][$key], 1) . "[\s]*)([a-zA-Z\*\(][a-zA-Z0-9_\*]*)/", "\\1<|$attributes>\\2|>", $stuff_to_parse);
- }
- }
- }
-
-
-
-
-
-
-
- if ($this->lexic_permissions['BRACKETS']) {
- $code_entities_match = array('[', ']', '(', ')', '{', '}');
- if (!$this->use_classes) {
- $code_entities_replace = array(
- '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">[|>',
- '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">]|>',
- '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">(|>',
- '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">)|>',
- '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">{|>',
- '<| style="' . $this->language_data['STYLES']['BRACKETS'][0] . '">}|>',
- );
- } else {
- $code_entities_replace = array(
- '<| class="br0">[|>',
- '<| class="br0">]|>',
- '<| class="br0">(|>',
- '<| class="br0">)|>',
- '<| class="br0">{|>',
- '<| class="br0">}|>',
- );
- }
- $stuff_to_parse = str_replace($code_entities_match, $code_entities_replace, $stuff_to_parse);
- }
-
-
- if ($this->lexic_permissions['SYMBOLS']) {
-
-
-
-
- $symbol_data = $symbol_preg = array();
- foreach ($this->language_data['SYMBOLS'] as $key => $symbols) {
- if (is_array($symbols)) {
- foreach ($symbols as $sym) {
- if (!isset($symbol_data[$sym])) {
- $symbol_data[GeSHi::hsc($sym)] = $key;
- $symbol_preg[] = preg_quote(GeSHi::hsc($sym), '/');
- }
- }
- } else {
- if (!isset($symbol_data[$symbols])) {
- $symbol_data[GeSHi::hsc($symbols)] = 0;
- $symbol_preg[] = preg_quote(GESHI::hsc($symbols), '/');
- }
- }
- }
-
-
-
-
- $sym_search = implode("|", $symbol_preg);
-
- preg_match_all("/(?:" . $sym_search . ")+/", $stuff_to_parse, $matches_in_stuff, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
-
- preg_match_all("/<\|(?:<DOT>|[^>])+>(?:(?!\|>).*?)\|>|<\/a>/", $stuff_to_parse, $highlighted_in_stuff, PREG_OFFSET_CAPTURE);
- foreach ($matches_in_stuff as $stuff_match_id => $stuff_match_data) {
- foreach ($highlighted_in_stuff[0] as $highlight_id => $highlight_data) {
-
- if (($highlight_data[1] <= $stuff_match_data[0][1]) &&
- ($highlight_data[1] + strlen($highlight_data[0]) >= $stuff_match_data[0][1] + strlen($stuff_match_data[0][0]))) {
-
- unset($matches_in_stuff[$stuff_match_id]);
- break;
- }
- }
- }
-
- $symbol_offsets = array();
- foreach ($matches_in_stuff as $stuff_match_data) {
- $symbol_offsets[$stuff_match_data[0][1]] = $stuff_match_data[0][0];
- }
- krsort($symbol_offsets);
-
- foreach ($symbol_offsets as $symbol_offset => $symbol_match) {
- $symbol_hl = "";
- $old_sym = -1;
-
- preg_match_all("/$sym_search/", $symbol_match, $sym_match_syms, PREG_PATTERN_ORDER);
- foreach ($sym_match_syms[0] as $sym_ms) {
-
- if (isset($symbol_data[$sym_ms]) && ($symbol_data[$sym_ms] != $old_sym)) {
- if (-1 != $old_sym) {
- $symbol_hl .= "|>";
- }
- $old_sym = $symbol_data[$sym_ms];
- if (!$this->use_classes) {
- $symbol_hl .= '<| style="' . $this->language_data['STYLES']['SYMBOLS'][$old_sym] . '">';
- } else {
- $symbol_hl .= '<| class="sy' . $old_sym . '">';
- }
- }
- $symbol_hl .= $sym_ms;
- }
-
-
- if (-1 != $old_sym) {
- $symbol_hl .= "|>";
- }
- $stuff_to_parse = substr($stuff_to_parse, 0, $symbol_offset) . $symbol_hl . substr($stuff_to_parse, $symbol_offset + strlen($symbol_match));
- }
- }
-
-
-
-
-
- foreach ($this->language_data['REGEXPS'] as $key => $regexp) {
- if ($this->lexic_permissions['REGEXPS'][$key]) {
- if (is_callable($this->language_data['STYLES']['REGEXPS'][$key])) {
- $func = $this->language_data['STYLES']['REGEXPS'][$key];
- $stuff_to_parse = preg_replace("/!REG3XP$key!(.*)\|>/eU",
- "' style=\"' . call_user_func(\"$func\", '\\1') . '\"\\1|>'", $stuff_to_parse);
- } else {
- if (!$this->use_classes) {
- $attributes = ' style="' . $this->language_data['STYLES']['REGEXPS'][$key] . '"';
- } else {
- if (is_array($this->language_data['REGEXPS'][$key]) &&
- array_key_exists(GESHI_CLASS, $this->language_data['REGEXPS'][$key])) {
- $attributes = ' class="' .
- $this->language_data['REGEXPS'][$key][GESHI_CLASS] . '"';
- } else {
- $attributes = ' class="re' . $key . '"';
- }
- }
- $stuff_to_parse = str_replace("!REG3XP$key!", "$attributes", $stuff_to_parse);
- }
- }
- }
-
-
- $stuff_to_parse = str_replace('<DOT>', '.', $stuff_to_parse);
-
- if (isset($this->link_styles[GESHI_LINK])) {
- if ($this->use_classes) {
- $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' href=', $stuff_to_parse);
- } else {
- $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' style="' . $this->link_styles[GESHI_LINK] . '" href=', $stuff_to_parse);
- }
- } else {
- $stuff_to_parse = str_replace('<|UR1|', '<a' . $this->link_target . ' href=', $stuff_to_parse);
- }
-
-
-
-
-
- $stuff_to_parse = str_replace('<|', '<span', $stuff_to_parse);
- $stuff_to_parse = str_replace('|>', '</span>', $stuff_to_parse);
-
- return substr($stuff_to_parse, 1);
- }
-
-
-
- public function set_time($start_time, $end_time)
- {
- $start = explode(' ', $start_time);
- $end = explode(' ', $end_time);
- $this->time = $end[0] + $end[1] - $start[0] - $start[1];
- }
-
-
-
- public function get_time()
- {
- return $this->time;
- }
-
-
-
- public function load_language($file_name)
- {
- $this->enable_highlighting();
- $language_data = array();
- require $file_name;
-
-
- $this->language_data = $language_data;
-
- if ($this->language_data['STRICT_MODE_APPLIES'] == GESHI_ALWAYS) {
- $this->strict_mode = true;
- }
-
-
- foreach ($this->language_data['KEYWORDS'] as $key => $words) {
- $this->lexic_permissions['KEYWORDS'][$key] = true;
- }
- foreach ($this->language_data['COMMENT_SINGLE'] as $key => $comment) {
- $this->lexic_permissions['COMMENTS'][$key] = true;
- }
- foreach ($this->language_data['REGEXPS'] as $key => $regexp) {
- $this->lexic_permissions['REGEXPS'][$key] = true;
- }
-
- $this->overall_class = $this->language;
- }
-
-
-
- public function finalise($parsed_code)
- {
-
-
-
- if ($this->enable_important_blocks &&
- (strstr($parsed_code, GeSHi::hsc(GESHI_START_IMPORTANT)) === false)) {
- $parsed_code = str_replace(GeSHi::hsc(GESHI_END_IMPORTANT), '', $parsed_code);
- }
-
-
- if ($this->header_type != GESHI_HEADER_PRE) {
- $parsed_code = $this->indent($parsed_code);
- }
-
-
- $parsed_code = preg_replace('#<span[^>]+>(\s*)</span>#', '\\1', $parsed_code);
- $parsed_code = preg_replace('#<div[^>]+>(\s*)</div>#', '\\1', $parsed_code);
-
-
-
- if ($this->add_ids && !$this->overall_id) {
- $this->overall_id = 'geshi-' . substr(md5(microtime()), 0, 4);
- }
-
-
-
- if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
-
-
- $ls = ($this->header_type != GESHI_HEADER_PRE) ? "\n" : '';
-
- $code = explode("\n", $parsed_code);
-
- $parsed_code = '';
- $i = 0;
-
-
- foreach ($code as $line) {
-
- $attrs = array();
-
-
-
- if ('' == trim($line)) {
- $line = ' ';
- }
-
- if ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS &&
- $i % $this->line_nth_row == ($this->line_nth_row - 1)) {
-
- if ($this->use_classes) {
-
- $attrs['class'][] = 'li2';
- $def_attr = ' class="de2"';
- } else {
-
- $attrs['style'][] = $this->line_style2;
-
-
-
- $def_attr = ' style="' . $this->code_style . '"';
- }
-
- $start = "<div$def_attr>";
- $end = '</div>';
- } else {
- if ($this->use_classes) {
-
- $attrs['class'][] = 'li1';
- $def_attr = ' class="de1"';
- } else {
-
- $attrs['style'][] = $this->line_style1;
- $def_attr = ' style="' . $this->code_style . '"';
- }
- $start = "<div$def_attr>";
- $end = '</div>';
- }
-
- ++$i;
-
- if ($this->add_ids) {
- $attrs['id'][] = "$this->overall_id-$i";
- }
- if (in_array($i, $this->highlight_extra_lines)) {
- if ($this->use_classes) {
- if (array_key_exists($i, $this->highlight_extra_lines_styles)) {
- $attrs['class'][] = "lx$i";
- } else {
- $attrs['class'][] = "ln-xtra";
- }
- } else {
- array_push($attrs['style'], $this->get_line_style($i));
- }
- }
-
-
- $attr_string = '';
- foreach ($attrs as $key => $attr) {
- $attr_string .= ' ' . $key . '="' . implode(' ', $attr) . '"';
- }
- $parsed_code .= "<li$attr_string>$start$line$end</li>$ls";
- }
- } else {
-
-
- $code = explode("\n", $parsed_code);
- $parsed_code = '';
- $i = 0;
- foreach ($code as $line) {
-
-
- if ('' == trim($line)) {
- $line = ' ';
- }
- if (in_array(++$i, $this->highlight_extra_lines)) {
- if ($this->use_classes) {
- if (array_key_exists($i, $this->highlight_extra_lines_styles)) {
- $parsed_code .= "<div class=\"lx$i\">";
- } else {
- $parsed_code .= "<div class=\"ln-xtra\">";
- }
- } else {
- $parsed_code .= "<div style=\"" . $this->get_line_style($i) . "\">";
- }
-
- $parsed_code .= $line . "</div>";
- } else {
- $parsed_code .= $line . "\n";
- }
- }
- }
-
- if ($this->header_type == GESHI_HEADER_PRE) {
-
- $parsed_code = str_replace('<li></li>', '<li> </li>', $parsed_code);
- }
-
- return $this->header() . chop($parsed_code) . $this->footer();
- }
-
-
-
- public function header()
- {
-
- $attributes = $this->get_attributes();
-
- $ol_attributes = '';
-
- if ($this->line_numbers_start != 1) {
- $ol_attributes .= ' start="' . $this->line_numbers_start . '"';
- }
-
-
- $header = $this->format_header_content();
-
- if (GESHI_HEADER_NONE == $this->header_type) {
- if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
- return "$header<ol$ol_attributes>";
- }
- return $header .
- ($this->force_code_block ? '<div>' : '');
- }
-
-
- if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
- if ($this->header_type == GESHI_HEADER_PRE) {
- return "<pre$attributes>$header<ol$ol_attributes>";
- } elseif ($this->header_type == GESHI_HEADER_DIV) {
- return "<div$attributes>$header<ol$ol_attributes>";
- }
- } else {
- if ($this->header_type == GESHI_HEADER_PRE) {
- return "<pre$attributes>$header" .
- ($this->force_code_block ? '<div>' : '');
- } elseif ($this->header_type == GESHI_HEADER_DIV) {
- return "<div$attributes>$header" .
- ($this->force_code_block ? '<div>' : '');
- }
- }
- }
-
-
-
- public function format_header_content()
- {
- $header = $this->header_content;
- if ($header) {
- if ($this->header_type == GESHI_HEADER_PRE) {
- $header = str_replace("\n", '', $header);
- }
- $header = $this->replace_keywords($header);
-
- if ($this->use_classes) {
- $attr = ' class="head"';
- } else {
- $attr = " style=\"{$this->header_content_style}\"";
- }
- return "<div$attr>$header</div>";
- }
- }
-
-
-
- public function footer()
- {
- $footer_content = $this->format_footer_content();
-
- if (GESHI_HEADER_NONE == $this->header_type) {
- return ($this->line_numbers != GESHI_NO_LINE_NUMBERS) ? '</ol>' . $footer_content
- : $footer_content;
- }
-
- if ($this->header_type == GESHI_HEADER_DIV) {
- if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
- return "</ol>$footer_content</div>";
- }
- return ($this->force_code_block ? '</div>' : '') .
- "$footer_content</div>";
- } else {
- if ($this->line_numbers != GESHI_NO_LINE_NUMBERS) {
- return "</ol>$footer_content</pre>";
- }
- return ($this->force_code_block ? '</div>' : '') .
- "$footer_content</pre>";
- }
- }
-
-
-
- public function format_footer_content()
- {
- $footer = $this->footer_content;
- if ($footer) {
- if ($this->header_type == GESHI_HEADER_PRE) {
- $footer = str_replace("\n", '', $footer);
- ;
- }
- $footer = $this->replace_keywords($footer);
-
- if ($this->use_classes) {
- $attr = ' class="foot"';
- } else {
- $attr = " style=\"{$this->footer_content_style}\"";
- }
- return "<div$attr>$footer</div>";
- }
- }
-
-
-
- public function replace_keywords($instr)
- {
- $keywords = $replacements = array();
-
- $keywords[] = '<TIME>';
- $keywords[] = '{TIME}';
- $replacements[] = $replacements[] = number_format($this->get_time(), 3);
-
- $keywords[] = '<LANGUAGE>';
- $keywords[] = '{LANGUAGE}';
- $replacements[] = $replacements[] = $this->language;
-
- $keywords[] = '<VERSION>';
- $keywords[] = '{VERSION}';
- $replacements[] = $replacements[] = GESHI_VERSION;
-
- return str_replace($keywords, $replacements, $instr);
- }
-
-
-
- public function get_attributes()
- {
- $attributes = '';
-
- if ($this->overall_class != '') {
- $attributes .= " class=\"{$this->overall_class}\"";
- }
- if ($this->overall_id != '') {
- $attributes .= " id=\"{$this->overall_id}\"";
- }
- if ($this->overall_style != '') {
- $attributes .= ' style="' . $this->overall_style . '"';
- }
- return $attributes;
- }
-
-
-
- public function hsc($string, $quote_style=ENT_COMPAT)
- {
-
- $aTransSpecchar = array(
- '&' => '&',
- '"' => '"',
- '<' => '<',
- '>' => '>'
- );
-
- if (ENT_NOQUOTES == $quote_style) {
- unset($aTransSpecchar['"']);
- } elseif (ENT_QUOTES == $quote_style) {
- $aTransSpecchar["'"] = ''';
- }
-
-
- return strtr($string, $aTransSpecchar);
- }
-
-
-
- public function get_stylesheet($economy_mode = true)
- {
-
-
-
- if ($this->error) {
- return '';
- }
-
-
-
- $selector = ($this->overall_id != '') ? "#{$this->overall_id} " : '';
- $selector = ($selector == '' && $this->overall_class != '') ? ".{$this->overall_class} " : $selector;
-
-
- if (!$economy_mode) {
- $stylesheet = "/**\n".
- " * GeSHi Dynamically Generated Stylesheet\n".
- " * --------------------------------------\n".
- " * Dynamically generated stylesheet for {$this->language}\n".
- " * CSS class: {$this->overall_class}, CSS id: {$this->overall_id}\n".
- " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" .
- " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n".
- " * --------------------------------------\n".
- " */\n";
- } else {
- $stylesheet = "/**\n".
- " * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann\n" .
- " * (http://qbnz.com/highlighter/ and http://geshi.org/)\n".
- " */\n";
- }
-
-
-
-
-
- if (!$economy_mode || $this->line_numbers != GESHI_NO_LINE_NUMBERS) {
-
- $stylesheet .= "$selector.de1, $selector.de2 {{$this->code_style}}\n";
- }
-
-
- if (!$economy_mode || $this->overall_style != '') {
- $stylesheet .= "$selector {{$this->overall_style}}\n";
- }
-
-
- foreach ($this->link_styles as $key => $style) {
- if (!$economy_mode || $key == GESHI_LINK && $style != '') {
- $stylesheet .= "{$selector}a:link {{$style}}\n";
- }
- if (!$economy_mode || $key == GESHI_HOVER && $style != '') {
- $stylesheet .= "{$selector}a:hover {{$style}}\n";
- }
- if (!$economy_mode || $key == GESHI_ACTIVE && $style != '') {
- $stylesheet .= "{$selector}a:active {{$style}}\n";
- }
- if (!$economy_mode || $key == GESHI_VISITED && $style != '') {
- $stylesheet .= "{$selector}a:visited {{$style}}\n";
- }
- }
-
-
- if (!$economy_mode || $this->header_content_style != '') {
- $stylesheet .= "$selector.head {{$this->header_content_style}}\n";
- }
- if (!$economy_mode || $this->footer_content_style != '') {
- $stylesheet .= "$selector.foot {{$this->footer_content_style}}\n";
- }
-
-
- if (!$economy_mode || $this->important_styles != '') {
- $stylesheet .= "$selector.imp {{$this->important_styles}}\n";
- }
-
-
- if (!$economy_mode || ($this->line_numbers != GESHI_NO_LINE_NUMBERS && $this->line_style1 != '')) {
- $stylesheet .= "{$selector}li, {$selector}li.li1 {{$this->line_style1}}\n";
- }
-
- if (!$economy_mode || ($this->line_numbers == GESHI_FANCY_LINE_NUMBERS && $this->line_style2 != '')) {
- $stylesheet .= "{$selector}li.li2 {{$this->line_style2}}\n";
- }
-
- foreach ($this->language_data['STYLES']['KEYWORDS'] as $group => $styles) {
- if (!$economy_mode || ($economy_mode && $styles != '') &&
- (isset($this->lexic_permissions['KEYWORDS'][$group]) &&
- $this->lexic_permissions['KEYWORDS'][$group])) {
- $stylesheet .= "$selector.kw$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['COMMENTS'] as $group => $styles) {
- if (!$economy_mode || ($economy_mode && $styles != '') &&
- (isset($this->lexic_permissions['COMMENTS'][$group]) &&
- $this->lexic_permissions['COMMENTS'][$group])) {
- $stylesheet .= "$selector.co$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['ESCAPE_CHAR'] as $group => $styles) {
- if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
- !$this->lexic_permissions['ESCAPE_CHAR'])) {
- $stylesheet .= "$selector.es$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['BRACKETS'] as $group => $styles) {
- if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
- !$this->lexic_permissions['BRACKETS'])) {
- $stylesheet .= "$selector.br$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['SYMBOLS'] as $group => $styles) {
- if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
- !$this->lexic_permissions['SYMBOLS'])) {
- $stylesheet .= "$selector.sy$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['STRINGS'] as $group => $styles) {
- if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
- !$this->lexic_permissions['STRINGS'])) {
- $stylesheet .= "$selector.st$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['NUMBERS'] as $group => $styles) {
- if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
- !$this->lexic_permissions['NUMBERS'])) {
- $stylesheet .= "$selector.nu$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['METHODS'] as $group => $styles) {
- if (!$economy_mode || !($economy_mode && $styles == '') && !($economy_mode &&
- !$this->lexic_permissions['METHODS'])) {
- $stylesheet .= "$selector.me$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['SCRIPT'] as $group => $styles) {
- if (!$economy_mode || !($economy_mode && $styles == '')) {
- $stylesheet .= "$selector.sc$group {{$styles}}\n";
- }
- }
- foreach ($this->language_data['STYLES']['REGEXPS'] as $group => $styles) {
- if (!$economy_mode || ($economy_mode && $styles != '') &&
- (isset($this->lexic_permissions['REGEXPS'][$group]) &&
- $this->lexic_permissions['REGEXPS'][$group])) {
- if (is_array($this->language_data['REGEXPS'][$group]) &&
- array_key_exists(GESHI_CLASS,
- $this->language_data['REGEXPS'][$group])) {
- $stylesheet .= "$selector.";
- $stylesheet .= $this->language_data['REGEXPS'][$group][GESHI_CLASS];
- $stylesheet .= " {{$styles}}\n";
- } else {
- $stylesheet .= "$selector.re$group {{$styles}}\n";
- }
- }
- }
-
- if (!$economy_mode || (count($this->highlight_extra_lines)!=count($this->highlight_extra_lines_styles))) {
- $stylesheet .= "{$selector}.ln-xtra, {$selector}li.ln-xtra, {$selector}div.ln-xtra {{$this->highlight_extra_lines_style}}\n";
- }
- foreach ($this->highlight_extra_lines_styles as $lineid => $linestyle) {
- $stylesheet .= "{$selector}.lx$lineid, {$selector}li.lx$lineid, {$selector}div.lx$lineid {{$linestyle}}\n";
- }
-
- return $stylesheet;
- }
-
-
-
- public function get_line_style($line)
- {
-
- $style = null;
- if (array_key_exists($line, $this->highlight_extra_lines_styles)) {
- $style = $this->highlight_extra_lines_styles[$line];
- } else {
- $style = $this->highlight_extra_lines_style;
- }
-
- return $style;
- }
- }
-
-
- if (!function_exists('geshi_highlight')) {
-
-
- function geshi_highlight($string, $language, $path = null, $return = false)
- {
- $geshi = new GeSHi($string, $language, $path);
- $geshi->set_header_type(GESHI_HEADER_NONE);
- if ($return) {
- return '<code>' . $geshi->parse_code() . '</code>';
- }
- echo '<code>' . $geshi->parse_code() . '</code>';
- if ($geshi->error()) {
- return false;
- }
- return true;
- }
- }
|