syntax highlighting - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html) +--- Forum: Board (https://python-forum.io/forum-26.html) +--- Thread: syntax highlighting (/thread-15.html) |
RE: syntax highlighting - snippsat - Sep-18-2016 Made a regex for pre tag in MyCode and deactivated HTML in post. Still the same problem. HTML is off witch is better for security. <h2>test</h2> [pre class="brush: python"] print('hello world') print("test") [/pre] [pre class="brush: python"] print('hello world') print("test") [/pre]Found this info. Quote:Note that in MyBB, you have to be careful with style tags because linebreaks are automatically converted into <br />Not to happy about this automatic stuff :@ So maybe a post to MyBB staff and ask if there is a way to turn it off. See that in php of v3 they have some cleaning $text = str_replace ( "\n", "", $text). So maybe have to clean it in some way. RE: syntax highlighting - metulburr - Sep-18-2016 Nice job. Will do. RE: syntax highlighting - snippsat - Sep-18-2016 So i have looked more into this. <?php echo nl2br("foo isn't\n bar"); ?> Out: foo isn't<br /> barLink MyCode. $options['nl2br'] Each line break will be transformed into a html line break (<br />), if this option is set to 1 So it's set to 1. It's defined in class_parser.php What i am unsure about is that options = array( is comment out. Tried only to un-uncomment nl2br,but that lock forum down :-/ In line 212 i tried to set 1,but did't help. Think maybe i have to un-uncomment whole array and set values for each :s RE: syntax highlighting - metulburr - Sep-18-2016 [pre class="brush: python"] print('hello world') print("test") [/pre] To keep changelog. I commented that entire if condition out. It appears to have worked. Im not sure of any unwanted side effects that might of caused (if any) //if(!isset($this->options['nl2br']) || $this->options['nl2br'] != 0) //{ // $message = nl2br($message); // Fix up new lines and block level elements // $message = preg_replace("#(</?(?: html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)\s* <br />#i", "$1", $message); // $message = preg_replace("#( )+(</?(?: html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)#i", "$2", $message); //}EDIT: I get it, then you lose ALL newlines. Ill revert back for the time being RE: syntax highlighting - metulburr - Sep-18-2016 Im crappy at regex, but what if we added a condition that replace newlines with breaks if not within pre tag? RE: syntax highlighting - metulburr - Oct-04-2016 I tried cleaning inside of pre tags only. It keeps the rest of the post fixed, and removes the newlines from within the pre tags. However the break tags still remain [attachment=18] function my_nl2br($string){ $string = str_replace("\n", "<br />", $string); if(preg_match_all('/\<pre\>(.*?)\<\/pre\>/', $string, $match)){ foreach($match as $a){ foreach($a as $b){ $string = str_replace('<pre>'.$b.'</pre>', "<pre>".str_replace("<br />", "", $b)."</pre>", $string); } } } return $string; }apparently other people have the same problem http://stackoverflow.com/questions/8217440/ignore-pre-tags-when-using-nl2br RE: syntax highlighting - metulburr - Oct-04-2016 Oh wait i think i might of got it. How does that look? Anything wrong? All newlines correct and as expected? First line second line fourth line sixth line import pygame as pg import sys class States(object): def __init__(self): self.done = False self.next = None self.quit = False self.previous = None class Menu(States): ''' test ''' def __init__(self): States.__init__(self) self.next = 'game' def cleanup(self): print("cleaning up Menu state stuff")Although it still does not copy from the codebox correctly. But only in the advanced editor. You can copy and paste it into the quick reply no problem. So whats different? RE: syntax highlighting - snippsat - Oct-04-2016 Very good what did you do :cool: Quote:Although it still does not copy from the codebox correctly.That should be an easier fix,maybe just use the button from V3 and make it insert. [pre class="brush: python"] [/pre]Shall look more into it later today,it's midnight theme i have build with here. [pre class="brush: python"] print('hello world') print("test") [/pre] [pre class="brush: python"] import dataset player_lst = [ {'name': 'Superman', 'score': 9999999}, {'name': 'Hulk', 'score': 2000001}, {'name': 'Batman', 'score': 500055} ] db = dataset.connect('sqlite:///heroes.db') table = db['Score_table'] for item in player_lst: table.insert(item) [/pre] [pre class="brush: python"] from collections import deque from itertools import islice def window(iterable, size=2): iterable = iter(iterable) d = deque(islice(iterable, size), size) yield d for x in iterable: d.append(x) yield d [/pre] RE: syntax highlighting - metulburr - Oct-04-2016 I made a BBCode for that so we dont have to keep typing in the class brush python etc. it should be [python]CODE HERE[/python]The actual button for it is currently in the new drop down BBcode Button RE: syntax highlighting - snippsat - Oct-04-2016 Okay good. But now it's 4 click to insert code,should be 2 as other. Maybe look at own button for this. Really nice to see it work :) Have not time now shall look more into it later. print('hello world') print("test") |