Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Adding a superscript and subscript button?

Does anyone know how to do this? Any help would be appreciated since it's pretty important for my forum :) thanks!

Comments

  • Options

    also me too..

  • Options
    hgtonighthgtonight ∞ · New Moderator

    You should be able to do it pretty easily. You didn't mention what input formatter you want though.

    Which formatter are you looking to add sup/sub tags in for?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    @hgtonight said:
    You should be able to do it pretty easily. You didn't mention what input formatter you want though.

    Which formatter are you looking to add sup/sub tags in for?

    Ahhh not sure, BBCode I think will be the best :)

  • Options
    hgtonighthgtonight ∞ · New Moderator
    edited February 2014

    There are two parts to this system. You want to a) add a button to button bar that provides [sub] and [sup] tags. Then you want to b) translate those tags into some type of html markup for actual display.

    Part A is strictly done by modifying the ButtonBar plugin. Your best bet is to copy the button bar plugin folder and rename it to something like ButtonBarPlus or something like that. You will also have to modify the class name and plugin info array to reflect the change in name.

    Then you need to add the button markup in /plugins/YourNewPlugin/views/buttonbar.php. Adding it should be straight-forward, but this is the code I used for my tests:

    <div class="ButtonBar">
      <div><span>bold</span></div>
      <div><span>italic</span></div>
      <div><span>underline</span></div>
      <div><span>strike</span></div>
      <div><span>code</span></div>
      <div><span>image</span></div>
      <div><span>url</span></div>
      <div><span>quote</span></div>
      <div><span>spoiler</span></div>
      <div><span>super</span></div>
      <div><span>sub</span></div>
    </div>
    

    Once the markup is added, you can add some extra CSS styles to make the button look nicer, but I leave that up to you.

    Now you need to add the tag for button bar by modifying the /plugins/YourNewPlugin/js/buttonbar.js. Since you are only adding support for BBCode, you need to add a case for 'super' and 'sub' in the PerformBBCode function. Something like the below inserted after line 336 should do the trick:

    case 'super':
      $(TextArea).insertRoundTag('sup',bbcodeOpts);
      break;
    
    case 'sub':
      $(TextArea).insertRoundTag('sub',bbcodeOpts);
      break;
    

    At this point, assuming you have your new plugin enabled (and the original buttonbar disabled), you should have two extra buttons that insert the appropriate tags.

    Part B can be quite easily done by using the NBBC plugin found here: http://vanillaforums.org/addon/nbbc-plugin

    I can't say I agree with using BBCode in the year of our lord 2014, but do what you gotta do.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    DobbyDobby New
    edited February 2014

    @hgtonight said:

    I can't say I agree with using BBCode in the year of our lord 2014, but do what you gotta do.

    Thanks a lot for the help! If you don't suggest BBcode what would you suggest and how would you alternatively do that? Sorry for the extra task haha.

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Markdown

    It really is a personal choice, I just think the advantages of Markdown outweigh BBCode and HTML. The only use case for using BBCode, imo, is having a large userbase that already uses BBCode.

    Don't let my preaching get to you though ;)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @hgtonight said:
    Markdown

    It really is a personal choice

    Not only. It is also a question of what features you need.

    HTML & BBCode can do what Markdown can do, but Markdown is limited.
    If you need or want for example colored text or font in different sizes, then Markdown is no choice for you.

    [color=lightgrey][size=small]P.S.: I personally [b][i]hate[/i][/b] markdown for those I-refuse-to-do-a-line-break-if-you-dont-hammer-on-your-space-bar ignorance[/size][/color]

  • Options
    hgtonighthgtonight ∞ · New Moderator
    edited February 2014

    @R_J said:

    hgtonight said:
    It really is a personal choice

    Not only. It is also a question of what features you need.

    Markdown was designed as a purely semantic markup language that is also human readable in plain text without the styling. As a side effect, it is much easier/lighter to write by hand.

    Philosophical issues aside, Markdown also supports inline HTML that will be rendered as-is*. This means you can add all the garish styling you want. ;)

    *not necessarily the case in Vanilla due to HTMLawed

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    DOH!
    I didn't knew that Markdown allows html. Well, if Markdown is not a restriction for the sake of simplicity, but an extension for the sake of convenience, I tend to think more friendly about Markdown.

    What I will never like is the line break, though...

    By the way: I didn't knew about that spoiler feature either :)

Sign In or Register to comment.