Forum: Ruby SM::ToHtml does not convert urls to hyperlinks

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Shri B. (Guest)
on 2009-05-19 10:31
(Received via mailing list)
I am trying to use my own output formatter with SimpleMarkup. Things
seems to work, except for hyperlinks not working as expected. I tried to
use SM::ToHtml to simplify things, and even if does not deal with
hyperlinks. Here is the code snippet I am using.

require 'rdoc/markup/simple_markup'
require 'rdoc/markup/simple_markup/to_html'
s = "This is *bold*. These are urls - www.foo.com<http://www.foo.com> ,
http://www.foo.com , foo[http://www.foo.com]"
p = SM::SimpleMarkup.new
puts p.convert(s, SM::ToHtml.new)

The output of this is as shown below. The word "bold" was surrounded by
the <b> tag, but the urls were not surrounded with <a href> tags.

<p>
This is <b>bold</b>. These are urls - www.foo.com<http://www.foo.com> ,
http://www.foo.com , foo[http://www.foo.com]
</p>

Is there a way to make this happen?

Regards,
Shri
Eric H. (Guest)
on 2009-05-19 21:58
(Received via mailing list)
On May 18, 2009, at 23:30, Shri B. wrote:

> I am trying to use my own output formatter with SimpleMarkup. Things
> seems to work, except for hyperlinks not working as expected. I
> tried to use SM::ToHtml to simplify things, and even if does not
> deal with hyperlinks. Here is the code snippet I am using.
>
> [...]

You should use RDoc::Markup from RDoc 2.  RDoc 1's SM is no longer
maintained.

As described in ri RDoc (for RDoc 2), valid URL formats are:

>      word label}[url].
>
>      Example hyperlinks:
>
>        link:RDoc.html
>        http://rdoc.rubyforge.org
>        mailto:removed_email_address@domain.invalid
>        {RDoc Documentation}[http://rdoc.rubyforge.org]
>        {RDoc Markup}[link:RDoc/Markup.html]

So, adjusting your input to fit:

$ echo 'This is *bold*. These are urls - http://www.foo.com,
foo[http://www.foo.com
]' | rdoc --pipe
<p>
This is <b>bold</b>. These are urls - <a
href="http://www.foo.com">www.foo.com</a>, <a
href="http://www.foo.com">foo</a>
</p>
This topic is locked and can not be replied to.