[RFC] Integrate s9e\TextFormatter

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.2/Rhea branch. Everything listed in this forum will be available in phpBB 3.2.
Post Reply
User avatar
JoshyPHP
Registered User
Posts: 360
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Tue Aug 20, 2013 4:29 pm

I went with the original plan B: query the database, glob all the styles/*/template/bbcode.html files and recompose BBCode templates based on the fragments. The commit is here. The path to styles/ is configurable. This is what the renderer looks like for prosilver+subsilver.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Integrate s9e\TextFormatter

Post by EXreaction » Tue Aug 20, 2013 6:59 pm

Styles have inheritance, so you'll need to check the inheritance tree as well to find the appropriate file.

User avatar
JoshyPHP
Registered User
Posts: 360
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Tue Aug 20, 2013 8:01 pm

I assume that styles inherit the whole bbcode.html, not just parts of it right? Do they also inherit the same bbcode_bitfield or can it be different from its parent?

Update: pushed to GitHub. I recurse into each style's parents until I find one that has a bbcode.html file. I don't touch the style's bbcode_bitfield, so if it's different from its parent they are renderered differently.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Integrate s9e\TextFormatter

Post by EXreaction » Wed Aug 21, 2013 3:20 am

Yes, although I do not know what the bitfield is used for in the styles.

User avatar
JoshyPHP
Registered User
Posts: 360
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Wed Aug 21, 2013 3:36 am

It determines which default templates are replaced. For instance, the default template for [b] uses <span style="font-weight: bold">. prosilver's template uses <strong>, but since the bit for [b] is not set, it uses the default template instead.

User avatar
Pony99CA
Registered User
Posts: 986
Joined: Sun Feb 08, 2009 2:35 am
Location: Hollister, CA
Contact:

Re: [RFC] Integrate s9e\TextFormatter

Post by Pony99CA » Wed Aug 21, 2013 8:50 pm

When all BBCodes become "custom" BBCodes, maybe there should be a new Allow style override setting on the Custom BBCodes page instead of this bitfield.

Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.

User avatar
JoshyPHP
Registered User
Posts: 360
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Wed Aug 21, 2013 9:59 pm

Today's update: I've added support for the attachment BBCode. Once I made sense of how the current code works, I managed to adapt to it with minimum work.

For reference, here's how the legacy routines work:
  1. The user posts [аttachment=0]icon_e_biggrin.gif[/attachment]
  2. It is stored as [аttachment=0:16rvhx28]<!-- ia0 -->icon_e_biggrin.gif<!-- ia0 -->[/attachment:16rvhx28]
  3. bbcode::bbcode_second_pass() renders it as <div class="inline-attachment">…<!-- ia0 -->icon_e_biggrin.gif<!-- ia0 -->…</div>
  4. The result is post-processed by parse_attachments() to display the attached file as per the attachment.html template
And with the new routines, it's basically the same thing except step 3 is handled by the text_formatter.renderer service and in step 2 it is stored as:

Code: Select all

<rt><ATTACHMENT filename="icon_e_biggrin.gif" index="0"><st>[attachment=0]</st>icon_e_biggrin.gif<et>[/attachment]</et></ATTACHMENT></rt>

User avatar
JoshyPHP
Registered User
Posts: 360
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Thu Aug 22, 2013 7:10 pm

I've added some basic tests today. One of them (misnested tags) made me realize something (that phpBB uses span elements.) But first, a word about tag rules in s9e\TextFormatter.

s9e\TextFormatter supports a relatively wide array of rules governing tags, such as BBCode tags. Those rules allow you to control where tags can be used (e.g. you can't have a link inside of a link), what to do with their whitespace and/or newlines outside of inside of them or how to handle misnesting and optional end tags (e.g. [/*]). Fortunately, most of the time you don't have to configure any of that because a set of rules is automatically generated by studying the templates' content. This is done using the HTML5 specs as a guideline, and more specifically HTML5's content models, optional tags, adoption agency algorithm, and suggested default rendering. That's how it magically knows that links shouldn't be nested, that [/*] tags are optionals and that it shouldn't convert new lines to <br> inside of a <pre> tag. All spiffy stuff that I will be eternally proud of.

There are, however, some situations where the automatic rules may not cover all of the user expectations. For instance, if your templates use the b and i (or strong and em) elements for your [b] and [i] BBCodes, the following text:

Code: Select all

[b]..[i]..[/b]..[/i]
...will be interpreted as:

Code: Select all

[b]..[i]..[/i][/b][i]..[/i]
...which is exactly what the user wanted: everything between [b] tags is bold, everything between [i] tags is italic. That's because BBCodes that use the "b", "i", "em" or "strong" (and a few other) HTML elements, are automatically set to be reopened if they're closed unexpectedly. For instance, when their parent gets closed as in the example above. phpBB's prosilver uses a span element, which is not on the list of elements that get reopened automatically. That's why I explicitly added a rule to [b], [i] and [u] so that they get reopened automatically, because I think that's what people would expect.

There are other situations where I'm not sure what people expect. Take this bug for instance: PHPBB3-9386 - and BBCodes also affect quotes. A "quote" is not valid inside of a "b", so currently it results in bold, non-quoted text. I could set it so that quotes break the bold text, but I'd need feedback on that. Should "quote" close a "b"? If so, what other tags should it close? "i", "u", "color", I guess. "url" I'm not so sure.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Integrate s9e\TextFormatter

Post by EXreaction » Thu Aug 22, 2013 8:48 pm

I think we'd prefer less autocorrection/magic rather than try to make things overly complex.

User avatar
JoshyPHP
Registered User
Posts: 360
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Thu Aug 22, 2013 10:02 pm

I'm not sure what you mean there, or what your concern is. What do you think would become complex?

Taking PHPBB3-9386 as an example, the difference between the quote breaking bold/italic or the quote being disabled is one option. Either I pass 'closeParent' => array('b', 'i', 'u') as an option when creating the quote tag, or I do nothing and the default is for "quote" to be disallowed inside of "b". Or I can disable all rules altogether, in which case you get the same bold quote as in the bug report.

Having some sensible defaults in term of autocorrection saves the end user a lot of hassle. (e.g. nobody wants to close every list item with [/*]) What defaults would you want to have?

Post Reply