![]() |
[General] MyCode parse error ( [font="droid sans", sans-serif] ) - Printable Version +- MyBB Community Forums (https://community.mybb.com) +-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html) +--- Forum: General Support (https://community.mybb.com/forum-176.html) +--- Thread: [General] MyCode parse error ( [font="droid sans", sans-serif] ) (/thread-229517.html) |
MyCode parse error ( [font="droid sans", sans-serif] ) - Hovatek - 2020-09-25 This is what gets displayed when you select and copy text from mybb and paste it in new thread / reply like I've just done i.e
This gets parsed just fine in Sceditor but appears broken in showthread To replicate, Select and copy text from any comment, paste it in the reply (not quick reply) then post RE: MyCode parse error ( [font="droid sans", sans-serif] ) - noyle - 2020-09-26 Which version of MyBB and theme/template are you using? And what was the web browser / OS when you achieved that? RE: MyCode parse error ( [font="droid sans", sans-serif] ) - nixer55 - 2020-09-27 Might be mistaken, but this looks like the issue I posted about back in April. And can be duplicated on this board: And can be duplicated on this board Link to original post: https://community.mybb.com/thread-223638-post-1346298.html#pid1346298 cheers... RE: MyCode parse error ( [font="droid sans", sans-serif] ) - Laird - 2020-10-05 (2020-09-27, 11:16 AM)nixer55 Wrote: Might be mistaken, but this looks like the issue I posted about back in April. It definitely seems related, although the issue you posted about seems broader: SCEditor adding extraneous tags, particularly "font" but also "color" and "size". The more particular issue of this thread is that sometimes those added "font" tags include a comma-separated list of fonts, including at least one font enclosed in double-quote marks. The MyBB parser doesn't handle that situation (the double-quotes within - rather than simply enclosing - the comma-separated list are the problem), and thus it doesn't render the tag but instead displays it literally, making the post less readable. I've put together a fix in the form of a very simple plugin which replaces those double-quotes with single-quotes prior to MyBB parsing font tags. If anybody wants to test it, feel free to download the attached file to your inc/plugins directory and then activate the Fix Unrendered Font Tags plugin via the ACP. RE: MyCode parse error ( [font="droid sans", sans-serif] ) - Hovatek - 2020-10-05 Thanks @ Laird for the plugin I'd already created a temporary fix using Mycode (Admin > Configuration > Mycode) Title: Font Fix Description: Fix Sceditor - Mycode issue Regular Expression: \[font="droid sans", sans-serif\](.*?)\[/font\] Replacement: <span style="font-family: droid sans, sans-serif;" class="mycode_font">$1</span> This might be custom to my forum (font style) RE: MyCode parse error ( [font="droid sans", sans-serif] ) - Laird - 2020-10-06 You're welcome. And I've just updated the file in my above post to version 1.0.1 to handle nested font tags. Yes, your regex looks like it will work for your custom forum and font style, however, it might not catch the scenario where somebody copy-n-pastes text from an external site into SCEditor, in which case different fonts - some enclosed in double-quotes - might be listed in the font tag generated by SCEditor. It also, as best I can tell, would not - as initially the case with my plugin - handle nested font tags which list those fonts specific to your forum. RE: MyCode parse error ( [font="droid sans", sans-serif] ) - noyle - 2020-10-06 It looks like different copy/paste behaviors between desktop browsers and mobile browsers, Google Chrome especially. RE: MyCode parse error ( [font="droid sans", sans-serif] ) - Omar G. - 2020-10-06 The addition of tags should be just disabled imo. RE: MyCode parse error ( [font="droid sans", sans-serif] ) - Laird - 2020-10-07 I agree to an extent, Omar, but that only prevents the problem of extraneous tags occurring in posts from that point onwards - it doesn't have any effect on those posts which have already been posted, so there's still a use case for my plugin, and perhaps even for incorporating its code into the core. I say "to an extent" because sometimes when rich-format text is pasted into the editor, it is necessary that font, size, and/or color tags be added so that the formatting is preserved. In this case, we should simply ensure that if the added font tag contains a list of fonts, any individual fonts in that list are not enclosed in double quotes but rather in single quotes. I'm not sure that I'll have any success but I'll see if I can work out why SCEditor is adding extraneous tags and how to stop it - noyle seems to have given us a good clue - as well as how to ensure that it uses single quotes instead of double quotes in the list of fonts in those font tags that can't be eliminated. OK, I've done a bunch of debugging and testing, and here are the results. Noyle, you're probably way ahead of me on this, so please let me know how this compares to your own findings. I think that there are three distinct - though related - problems raised in this thread and the one to which nixer55 linked above:
A working solution and a potential but flawed solution: Let's start with bug #3, the 'double quotes in font lists' bug, because its solution is simplest with fewest potential side effects. Borrowing from and porting into Javascript the PHP code of my plugin above, we can simply replace in the file jscript/bbcodes_sceditor.js the following code from within the "format" method relating to the "font" bbcode:
with this:
Now, when text is pasted into the editor in WYSIWYG mode, or when switching into Source mode, double quotes within lists of fonts are replaced with single quotes. Problem solved. Bugs #1 and #2 are closely related in that they stem from browsers redundantly setting values for style attributes in pasted text that are already at their default values. The "obvious" fix is to again edit appropriate sections of jscript/bbcodes_sceditor.js such that default values of those size/font/color attributes are detected and ignored, and so that no tag is thus added in those scenarios. I have tested this approach - for size, font, and color tags - and it does work on a default MyBB installation, resolving both bugs. The problem, however, is that it involves hard-coding those default style values into this Javascript file based on those in the default stylesheet, jscripts/sceditor/styles/jquery.sceditor.mybb.css, whereas, as Hovatek's scenario above demonstrates, those default stylesheet values might be changed (customised) by themes. That is to say that, for example, the default font-family specified in jscripts/sceditor/styles/jquery.sceditor.mybb.css is 'Tahoma, Verdana, Arial, Sans-Serif', whereas for Hovatek's forum it appears instead to have been customised to '"droid sans", sans-serif'. Detecting and ignoring in Javascript the default font-family for the editor as specified in jscripts/sceditor/styles/jquery.sceditor.mybb.css would thus fail on Hovatek's forum, because his theme has overridden that default font-family. So, I wonder whether anybody has any good suggestions for how to more generally resolve bugs #1 and #2? RE: MyCode parse error ( [font="droid sans", sans-serif] ) - Dr_The_One - 2020-10-17 I have same issue with mybb 1.8.24. Need to be fix. |