#35 ✓resolved
Michael Lovitt

Overzealous superscript and subscript

Reported by Michael Lovitt | August 11th, 2008 @ 01:14 PM | in 4.0.2

The following text:


Is converted by RedCloth into:


I would have expected the tildes to be preserved, not turned into subscript tags. Like so:


(In my app, we use a combination of RedCloth and a modified version of Rails' auto_link_urls, so it's important that URLs not be mangled by RedCloth, even if they don't appear in a link tag.)

Comments and changes to this ticket

  • Jason Garber

    Jason Garber August 11th, 2008 @ 02:00 PM

    • State changed from “new” to “invalid”

    I don't see how RedCloth could differentiate. What's wrong with using auto_link before RedCloth? RedCloth will preserve the HTML output by auto_link.

    >> text = "This is a bit of text that includes a http://google.com auto link."
    >> RedCloth.new(helper.auto_link(text)).to_html
    => "<p>This is a bit of text that includes a <a href=\"http://google.com\">http://google.com</a> auto link.</p>"

    Please reopen if that suggestion doesn't solve your problem.

  • Michael Lovitt

    Michael Lovitt August 11th, 2008 @ 02:08 PM

    I actually do use auto_link before RedCloth. When I do that, this text:


    Gets converted into this:

    <p><a href="http://foo.com/bar?something=1~2~3">http://foo.com/bar?something=1<sub>2</sub>3</a></p>

    So the link inside the href attribute is preserved, but the link that's displayed on the page is not. So if the user copies and pastes the link (by selecting the text that appears on the page), or prints out the page, etc., what they'll end up with is incorrect. The discrepancy is also somewhat confusing for the user who posted the link.

    So, I just wanted to provide this additional context. I understand if this is an edge case that is more trouble that it's worth to fix.

  • Michael Lovitt

    Michael Lovitt August 11th, 2008 @ 02:26 PM

    Note that, as I stated in the original bug report, we use a modified version of Rails' auto_link_urls method, since the original has its own issues (with Textile markup and with tildes in URLs).

    This is the HTML (returned from custom_auto_link_urls) that I pass to RedCloth:

    <a href="http://foo.com/bar?something=1~2~3">http://foo.com/bar?something=1~2~3</a>

    And this is what RedCloth returns:

    <p><a href=\"http://foo.com/bar?something=1~2~3\">http://foo.com/bar?something=1<sub>2</sub>3</a></p>
  • Jason Garber

    Jason Garber August 11th, 2008 @ 02:55 PM

    • State changed from “invalid” to “open”

    I see. I'll give it a look and see what I can figure out.

  • Jason Garber

    Jason Garber August 12th, 2008 @ 05:11 PM

    • Title changed from “Tildes in URLs cause problems” to “Overzealous superscript and subscript”
    • Tag changed from links to parser
    • Milestone set to 4.0.2

    With Textile 2, the sup and sub aren't recognized unless they have spaces or other punctuation, so this doesn't work

    f(x, n) = log~4~x^n^


    <p>f(x, n) = log~4~x^n^</p>

    In RedCloth 4.0.1, the subscript and superscript are recognized when they shouldn't be:

    <p>f(x, n) = log<sub>4</sub>x<sup>n</sup></p>

    Need to make them like del_phrase.

  • Jason Garber

    Jason Garber August 13th, 2008 @ 04:44 PM

    • State changed from “open” to “resolved”

    (from [5a684d50e219d4f4e36f77f22d1c7bb73273ec0e]) Limit overzealous superscript and subscript.

    Sup/sub phrases must be surrounded by spaces or square brackets. [#35 state:resolved] http://github.com/jgarber/redclo...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

RedCloth is a Ruby library for converting Textile into HTML

Shared Ticket Bins

People watching this ticket


Referenced by