Please upgrade here. These earlier versions are no longer being updated and have security issues.

Would like to use Markdown formatting, but with one feature borrowed from BBCode input formatter

DoyceTDoyceT Model Questioner ✭✭✭
edited August 2014 in Vanilla 2.0 - 2.3

Hi all,

To get you caught up, I'm on 2.1.1 stable, default template, and I'm using no text editing addon of any kind at this point, because my users are... bad at following directions - the cledit wysiwyg editor I was using was simply too much power in the hands of the irresponsible, and stuff like buttonbar (which puts the formatting out where the author can see it) simply terrifies everyone.

SO: no text editing addon, and my input formatter in config is set to Markdown (just because I had to disable editing tools, there's no reason people who know markdown need to suffer).

This works great, except for one problem: poets.

(As a matter of fact, 98% of the problems I have with my newly-live forum stem from the poetry department. Goddamn.)

Anyway, the poets need soft line breaks, because they're all posting poetry for critique and, using the Markdown input format, all the soft line breaks are being ignored. I've told them to just end those lines with two spaces, but christ-on-sale you'd think I'd asked them to climb a mountain. (And the eighty-six-year-old faculty guy has muttered about resigning. Again.)

Solution! I can switch the input to BBCode, which pays attention to soft line breaks.
Problem! Losing Markdown to enable BBCode makes me very sad.

So, what I really want - what I think would solve most of my problems - is Markdown input formatting, but with the BBCode inputformatter's ability not-ignore soft line breaks.

Is this possible? (Yes, I know it will anger Gruber and the rest of the Markdown gods, but at this point I will bear their wrath if I can do this.)

«13

Comments

  • peregrineperegrine MVP
    edited August 2014

    what about telling them to put their poetry within code tags
    highlight click code.

    there was once was a sailor from ....
    who ....
    and ...
    

    or poets category could have a different input formatter.

    of individuals could choose formatter the same way you changed custom theme css.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • whu606whu606 I'm not a SuperHero; I just like wearing tights... Moderator
    edited August 2014

    You could even duplicate the code tag button, and name it verse, or something, to make them feel really special.

    I heard this on the radio recently (paraphrase, cant quite remember it exactly.)

    You don't like long poems
    You say they bore you.
    This one's finished.
    Was that short enough for you?
    
    peregrineDoyceThgtonightvrijvlinder
  • DoyceTDoyceT Model Questioner ✭✭✭

    @peregrine said:

    or poets category could have a different input formatter.

    Eh?

    Tell me more about this wizardry.

  • BleistivtBleistivt MVP
    edited August 2014

    There was a change in master some time ago to respect soft linebreaks in Markdown, but it was reverted:
    https://github.com/vanilla/vanilla/commit/8c7261278c05f31af23326b4fdb1effa11289302

    But if you don't want to modify the core...
    Try this and tell me if it works:

    public function DiscussionController_BeforeCommentBody_Handler($Sender) {
        $Comment = $Sender->EventArguments['Object']->Body;
        $Comment = preg_replace('/(\r?\n)/', '  $1', $Comment);
        $Sender->EventArguments['Object']->Body = $Comment;
    }
    

    edit: Be sure you have 2 spaces before the $1 (when i coped this code they got trimmed for some reason)

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

    peregrineR_JDoyceThgtonight
  • peregrineperegrine MVP
    edited August 2014

    @whu606 said:
    You could even duplicate the code tag button, and name it verse, or something, to make them feel really special.

    I heard this on the radio recently (paraphrase, cant quite remember it exactly.)

    You don't like long poems
    You say they bore you.
    This one's finished.
    Was that short enough for you?
    

    thats what I was thinking too! (didn't mention it, but my thought were aligned with you).

    but will see if Bleistivt's change is what Doyce wants.

    @DoyceT said:
    Tell me more about this wizardry.

    probably via custom plugin.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • DoyceTDoyceT Model Questioner ✭✭✭
    edited August 2014

    Okay, I put together an addon with the code from @bliestivt. Looks like so:

    <?php if (!defined('APPLICATION')) exit();
      $PluginInfo['MarkdownMarkup'] = array(
       'Name' => 'MarkdownMarkup',
       'Description' => 'This addon modifies the Markdown input formatter so that it honors soft line breaks and converts them to -br- code.',
       'Version' => '0.1',
       'Author' => "doycet",
       'AuthorEmail' => '[email protected]',
       'AuthorUrl' => 'http://vanillaforums.org/discussion/comment/214129'
    );
    
    class MarkdownMarkupPlugin extends Gdn_Plugin {
    public function DiscussionController_BeforeCommentBody_Handler($Sender) {
            $Comment = $Sender->EventArguments['Object']->Body;
            $Comment = preg_replace('/(\r?\n)/', '  $1', $Comment);
            $Sender->EventArguments['Object']->Body = $Comment;
        }
    }
    

    I can enable the plugin okay, and regular markdown is working, but when I post in something with a bunch of soft line breaks, it continues to ignore them.

    Did I miss something? What should be happening?

  • BleistivtBleistivt MVP
    edited August 2014

    @DoyceT on my setup it works

    Have you double checked for the double whitespace?
    It always gets lost, when I copy it from here.

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

    DoyceT
  • DoyceTDoyceT Model Questioner ✭✭✭

    Yeah. I thought (hoped) that might be it, but what you see up above is a straight copy-paste from my site - the two spaces before the $1 are there.

  • DoyceTDoyceT Model Questioner ✭✭✭

    This is a zip of the addon exactly as it is on my site.

    Bleistivtvrijvlinderr0obert
  • Weird, for me it works on a fresh copy of 2.1.1

    What in your config for Garden.InputFormatter ?
    If it's empty, try changing it to Markdown.

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

  • DoyceTDoyceT Model Questioner ✭✭✭

    Well...

    I had the input formatter set to Markdown.

    I deleted the line entirely to go back to default.

    Then I set the Input Formatter back to Markdown.

    And now...

    The addon works (it's reflecting line breaks), but none of the other Markdown formatting is being processed.

    vrijvlinder
  • DoyceTDoyceT Model Questioner ✭✭✭

    ... and then I refreshed the forum discussion where I'm testing all this.

    Now the markdown formatting works, and it's back to not processing the line breaks. WTAF.

    vrijvlinder
  • DoyceTDoyceT Model Questioner ✭✭✭
    edited August 2014

    OhmygodI'msodumb.

    Seriously. I'm so dumb.

    I disabled the plugin and forgot to turn it back on. Holy cats I'm stupid.

    I need a "shame" badge.

    It's all working now. You guys are great.

    peregrine
  • peregrineperegrine MVP
    edited August 2014

    I need a "shame" badge.

    @vrijvlinder could fashion one up. lol

    you'll have to settle for this now

    xx

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • BleistivtBleistivt MVP
    edited August 2014

    Great! You could add it to the addon repo, and maybe add

    if (C('Garden.InputFormatter') != 'Markdown')
        return;
    

    to the function, so it doesn't clash with other InputFormatters.

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

    DoyceTperegrinevrijvlinder
  • DoyceTDoyceT Model Questioner ✭✭✭

    @Bleistivt said:
    Great! You could add it to the addon repo, and maybe add

    if (C('Garden.InputFormatter') != 'Markdown')
    return;

    to the function, so it doesn't clash with other InputFormatters.

    I'd be happy to do both those things.

    I don't want to screw up those extra lines, so if you look at that paste-in of the addon I shared above, where would those two lines go? Insert above line 13?

  • peregrineperegrine MVP
    edited August 2014

    yes.

     public function DiscussionController_BeforeCommentBody_Handler($Sender) 
        if (C('Garden.InputFormatter') != 'Markdown') return;
    

    or with Lord Bracko taking precedence

     public function DiscussionController_BeforeCommentBody_Handler($Sender) 
            if (C('Garden.InputFormatter') != 'Markdown')  {
            return;
           }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    BleistivtDoyceTR_J
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited August 2014

    t's kind of crappy on short notice... but shame is crappy by default ...

    DoyceTperegrineBleistivtR_J
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited August 2014

    This is a refined version, you can use this cool tool to make any badges you want for free

    http://www.onlinebadgemaker.com/3d-badge-maker

    peregrine
  • peregrineperegrine MVP
    edited August 2014

    self-shame badge the lightning bolts signify the static electricity when you face-plant your head into the palm of your hand, and the flames signify release of bad energy at the moment of impact.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
«13
Sign In or Register to comment.