Soooooooo, as most of you know, when it comes to coding I can be stubborn. Building out my new blogging system has led me down some interesting roads, and one of them was implementing code within your Blogs. As you can see from below I figured out how to do it by putting [CODER][/CODER] tags in my blogs. Then I pass each blog through a set of functions and the one below is one of them.
function CodeCheck($blogContent) {$ch = explode('[CODER]', $blogContent);if (count($ch) > 1) {$blogContentNew = str_replace("<br />", '<BREAK>', $blogContent);preg_match_all('|\[CODER\](.*)\[\/CODER\]|U', $blogContentNew, $newContent, PREG_PATTERN_ORDER);//print_r($newContent);$finalContent = $blogContent;foreach ($newContent[1] as $value) {//echo $value .'';$newSave = '[CODER]' .str_replace('<BREAK>', "<br />", $value) .'[/CODER]';$contentArray = explode('<BREAK>', $value);$newContent = '';foreach ($contentArray as $valueC) {$num = count(explode(" ", $valueC));if ($num > 1) {$cla = ' class="tab' .$num .'"';} else {$cla = '';}$newContent .= "\t<li" .$cla ."><code>" .trim(str_replace(' ', '', $valueC)) ."</code></li>\r\n";}$newContent = "<ol class=\"code\">\r\n\t" .$newContent ."\r\n</ol>";$finalContent = str_replace($newSave, $newContent, $finalContent);}return $finalContent;} else {return $blogContent;}}
Then I just need needed to style it and came up with the following.
/* Code Lists */ol {margin:1em 0; padding:0 0 0 2.5em; background-color: #DFDFDF;}.code {padding:3px 5px 3px 35px;border:1px solid #9e3637;list-style-type:decimal-leading-zero;font-family:Courier;font-size: 10px;}.code code {font-family:Monaco,"Courier New",Tahoma}.code li {margin:2px 0;padding:0 5px;background:#f7f7f5;}.code li.tab1 {padding-left:4ex}.code li.tab2 {padding-left:8ex}.code li.tab3 {padding-left:12ex}.code li.tab4 {padding-left:16ex}.code li.tab5 {padding-left:20ex}.code .changed {color:#900;font-weight:bold;}.code em {color:#900;font-weight:bold;font-style:normal;}
Seems to work great as long as I keep from putting the [CODER][/CODER] tags in any of my posts.
Now I remember seeing something out there that styled everything for me, but I just wanted something simple and couldn't find anything I liked. If you know of anything please feel free to comment on it below.













