# SM::ToHtml does not convert urls to hyperlinks

**URL:** <https://www.ruby-forum.com/t/sm-tohtml-does-not-convert-urls-to-hyperlinks/168288>\
**Category:** Ruby\
**Created:** [May 19, 2009, 8:31am UTC](https://www.ruby-forum.com/t/sm-tohtml-does-not-convert-urls-to-hyperlinks/168288 "2009-05-19T08:31:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [May 19, 2009, 8:31am UTC](https://www.ruby-forum.com/t/sm-tohtml-does-not-convert-urls-to-hyperlinks/168288/1 "2009-05-19T08:31:09Z")

</div>

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](http://www.foo.com) ,  
[http://www.foo.com](http://www.foo.com) , foo[[http://www.foo.com](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 **tag, but the urls were not surrounded with tags.**

 

**This is bold. These are urls - www.foo.com , http://www.foo.com , foo[http://www.foo.com]**

 

**Is there a way to make this happen?**

 

**Regards,  
Shri**

---

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [May 19, 2009, 7:58pm UTC](https://www.ruby-forum.com/t/sm-tohtml-does-not-convert-urls-to-hyperlinks/168288/2 "2009-05-19T19:58:40Z")

</div>

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](http://www.foo.com),  
foo[[http://www.foo.com](http://www.foo.com)  
]’ | rdoc --pipe

This is **bold**. These are urls - [www.foo.com](http://www.foo.com), [foo](http://www.foo.com)
