Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Extension: AutoP

StashStash
edited January 2007 in Vanilla 1.0 Help
I have just released AutoP.

If you've ever been annoyed by the way you carefully crafted HTML gets <br />d to death in Vanilla, this extension is for you! It is an implementation of AutoP by Matthew Mullenweg of WordPress fame. It "fixes" new lines in comments, displaying them as you would expect and using semantic, valid XHTML instead of multiple <br />s all over the place.

As of 2007-01-02, it has been tested and works with the default Vanilla text formatter, BBCodeParser, BetterBBCode, ExtendedTextFormatter, ForcedBBCode, HtmlFormatter, ksesXHTML, Markdown and Textile.

Known bugs:
! None. Please shout if you think you've found something that's broken!

To do:
+ Add a blacklist to disable this extension only on comments with incompatible text formatters used.

Also, a big THANK YOU goes out to Chuyskywalker for letting me know AutoP existed in the first place!
«1

Comments

  • Options
    pbearpbear New
    edited January 2007
    I've always thought the multiple <br>s were odd, even as the entire comment is within a list element.
  • Options
    So did I pbear, that's why I made this extension. Have you tried it? I'm gagging for feedback even if it's bad, just so long as it's constructive.
  • Options
    StashStash
    edited January 2007
    Wanderer
    Hey [-Stash-], I'm not sure I understand what problem your AutoP extension fixes.
    That's a valid question Wanderer, and I guess I've not explained with examples, so I'm going to try that now. I hope the following will make everything clear.

    OK, try this code in an HTML comment at this forum here:

    A line of text. <ul> <li>one</li> <li>two</li> <li>three</li> </ul> Another line of text.

    This gives me

    A line of text.
    • one
    • two
    • three
    Another line of text.

    And the actual HTML output looks like this:

    A line of text.<br /><br /><ul><br /><li>one</li><br /><li>two</li><br /><li>three</li><br /></ul><br /><br />Another line of text.

    When really, I was expecting

    A line of text.
    • one
    • two
    • three
    Another line of text.

    But in order to get this I have to type the following code:

    A line of text. <ul><li>one</li><li>two</li><li>three</li></ul> Another line of text.
    Essentially, the HTML being output is incorrect. HTML doesn't usually care about white space or carriage returns, yet these are being converted to <br />s. The AutoP Extension does a better job of deciding when a paragraph <p> tag should be used instead of two <br />s and when newlines should be left as is (after an </li> in the examples above) and not converted into HTML.

    Hope this clears things up a bit?
  • Options
    OK, crystal clear [-Stash-], I've encountered that problem before and my solution was, as you suggested, putting the code all on one line.

    Not sure that it happens enough that I want to add another extension though, and I've never had a user complain or use lists for that matter, but thanks anyway. All clear now. pic

    Posted: Wednesday, 3 January 2007 at 1:03PM (AEDT)

  • Options
    I know I'm going to sound like Polo here, but anyway...... this is actually something that I think really *should* be in the core as it exhibits what I believe to be the correct behaviour. But hey, as it's now an extension, it doesn't really matter does it? image
  • Options
    No doubt about it, your fix is the correct behaviour.
    And yes, I too vote for a core fix.

    Posted: Wednesday, 3 January 2007 at 1:14PM (AEDT)

  • Options
    dan39dan39 New
    edited January 2007
    This extension really helps a lot for a number of reasons. First, this means that the paragraphs in the comments are tagged, sematically, for what they actually are: paragraphs. But, perhaps even more importantly, it allows you to use CSS to style your paragraphs as you choose to (leading, indents, text-sizes, margins+paddings between paragraphs and other elements). With the <br />s you can't really do that effectively. This is a great extension.
  • Options
    Perfect example: breaks in a list where the list elements break on their own. Downloading now...
  • Options
    edited January 2007
    OK, I installed AutoP, it does not seem to work...

    <ul> <li>Test Line 1</li> <li>Test Line 2</li> <li>Test Line 3</li> </ul>

    By the way, should it work with preview as well?

    Posted: Thursday, 4 January 2007 at 8:03AM (AEDT)

  • Options
    StashStash
    edited January 2007
    Looking at the HTML of your comments, it would seem that they are not creating an <li>, so you end up with incorrect HTML like this:<div class="CommentBody" id="CommentBody_134"><ul>Multiple lines, expecting AutoP to fix things... <ul> <li>Test Line 1</li> <!-- SNIP --> </ul> </ul>
    Notice specifically, that after id="CommentBody_134"><ul> there is no <li>. I can only imagine that this invalid HTML is breaking AutoP somehow. I would say that this isn't AutoP's fault, but I will show it to the author and see if there's anything he can do to make AutoP more robust with invalid HTML.

    Of course I may be completely wrong here and it is AutoP's fault, so if anyone wants to show me the error of my ways you're more than welcome.

    But there's still definitely something strange happening here...

    [-Stash-]
  • Options
    StashStash
    edited January 2007
    I've done a little more digging. SirNot's HtmlFormatter 1.7.2 has a function for newline replacement which conflicts with AutoP. You will want to change line 17 of default.php from:define('HTML_CONVERT_NEWLINES', 1);to:define('HTML_CONVERT_NEWLINES',0);
    I don't suppose there's any way of the AutoP extension overriding HtmlFormatter's setting here is there?

    Oh yes, and preview should work, it does for me using SirNot's Preview Post 2.1, however, given the HTML issues mentioned above, I would imagine that isn't helping matters. Your forum's HTML seems to be broken compared to every other Vanilla forum's HTML code.

    Edit: I have added this to the readme file and updated the package on the add-ons site.
  • Options
    edited January 2007
     Quote: [-Stash-]  Looking at the HTML of your comments, it would seem that they are not creating an <li>, so you end up with incorrect HTML...
    I don't see how you can say this mate, the <li> and </li> tags are definitely there.
    In any case, your suggested modification to HTML Formatter worked, for lists but now HTML Formatter takes out ALL of the <p> tags.

    Posted: Friday, 5 January 2007 at 6:03AM (AEDT)

  • Options
    edited January 2007
    In my case, AutoP will add a <p> after </param> with HtmlFormatter 1.7.2 (on the youtube html), really strange.

    Does anyone have the same problem?
  • Options
    StashStash
    edited January 2007
    Nice forums! :)

    I notice you are using the BBInsertBar and I guess you're using it to embed the YouTube videos? I'm also going to guess that you are using BetterBBCode with the YouTube modifications mentioned elsewhere in this community. Taking these assumptions, I can say that I found the same problem on a site of mine as well. I would say that it's possibly a shortcoming in the AutoP regex, but I haven't really looked into it all that deeply. I will bring this to the attention of AutoP and see if he has the time to create a fix for it.

    What I did to solve it was change the YouTube embedding code from: return preg_replace('/<youtube>([\d\w-_]+)<\/youtube>/i', '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$1"></param> <embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" wmode="transparent"></embed> </object>', $String);
    to:return preg_replace('/<youtube>([\d\w-_]+)<\/youtube>/i', '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$1" /><param name="wmode" value="transparent" /><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>', $String);
    This solved the problem for me...

    Edit: The BBCodeParser extension already contains this fix among others...
  • Options
    edited January 2007
    Ok, find it. If you have some <embed blah blah...></embed> in your forum, you'll want to add "embed" in the line 27 of AutoP's default page.
    eg: $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|style|script|object|input|embed|param|p|h[1-6])';
    or you may get some dirty "p" on it.
  • Options
    Thanks :) For that SkyBoy, I'll do some more testing and sort out getting that fix included and update the main package!
  • Options
    You guess wrong. :P
    I am using BBCodeParser (nice Extension, thanks.) and I add youtube video with HtmlFormatter. :)

    Whatever, it works great now.
  • Options
    Ahhh well, that's why they call it a guess! You could make the changes I mentioned to the HtmlFormatter as well since they make for slightly smaller code ;)
  • Options
    edited January 2007
    HtmlFormatter use other format to write the code, case 'youtube' : return ('<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'.$ID.'"></param>'. '<embed src="http://www.youtube.com/v/'.$ID.'" type="application/x-shockwave-flash" width="425" height="350"></embed>'. '</object>'); Source will be: <object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/XXXXX"></param><embed src="http://www.youtube.com/v/XXXXXX" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
    It'll not have new line in the code.

    But since the line 28 & 29 of AutoP: $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);AutoP will add some new line on it.
    Source after AutoP:<object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/XXX"></param> <embed src="http://www.youtube.com/v/XXXX" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed> </object>

    PS: AutoP also changes the html source code of BBCodePaser.
  • Options
    PS: AutoP also changes the html source code of BBCodePaser.
    This is by design.

    I saw there was a need for this functionality in BBCodeParser as I was building it, but I also realised that just about every string formatter in Vanilla, includingn the defaul, needed it as well, so I separated it out so people who don't want to use the BBCodeParser can benefit from it as well.
This discussion has been closed.