# Displaying source code of an rhtml file

**URL:** <https://www.ruby-forum.com/t/displaying-source-code-of-an-rhtml-file/53386>\
**Category:** Ruby\
**Created:** [February 3, 2006, 10:16am UTC](https://www.ruby-forum.com/t/displaying-source-code-of-an-rhtml-file/53386 "2006-02-03T10:16:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dohmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@dohmer](https://www.ruby-forum.com/u/dohmer)\
**Post date:** [February 3, 2006, 10:16am UTC](https://www.ruby-forum.com/t/displaying-source-code-of-an-rhtml-file/53386/1 "2006-02-03T10:16:25Z")

</div>

Hi  
I’m creating some embedded ruby web pages under Linux and Apache 2.0  
and after showing what it can do I like to display the source code.  
I was wondering if there is an easier way to do this than what I am  
doing at present. An example is where I wish to show the line  
containing  
%\>  
Obviously just trying having a rhtml file with % at the start of a  
line means it is interpreted as ruby code so at present I am using  
% print “%”  
&gt

This works but is a pain. Is there a way to specify to a block of  
code, don’t interpret this code but simple display it in the page it  
came from ?  
TIA  
Paul

---

<div class="post-metadata">

**Author:** ![dohmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@dohmer](https://www.ruby-forum.com/u/dohmer)\
**Post date:** [February 3, 2006, 10:43am UTC](https://www.ruby-forum.com/t/displaying-source-code-of-an-rhtml-file/53386/2 "2006-02-03T10:43:29Z")

</div>

On Fri, 2006-02-03 at 18:13 +0900, Paul J. wrote:

> Hi  
> I’m creating some embedded ruby web pages under Linux and Apache 2.0  
> and after showing what it can do I like to display the source code.  
> I was wondering if there is an easier way to do this than what I am  
> doing at present. An example is where I wish to show the line  
> containing

Do you mean like this?

```
<html>

  <head>
    <title>Just code</title>
  </head>

  <body>
    <h1>Here is the code</h1>

    <pre><code><%= ERB::Util.html_escape(File.read( __FILE__ )) %>
    </pre></code>

  </body>
</html>

```

Alternatively, if you mean showing it in blocks you’ll have to escape it  
anyway, or the browsers will eat it, won’t they? So just pass them  
through html\_escape.

Alternatively, check out Rote ([http://rote.rubyforge.org](http://rote.rubyforge.org)) for some  
ERB-based ruby-code-macro supporting syntax highlighting fun, where you  
can just do:

```
#:code#ruby
class SomeClass < Other
  def etc(&blk)
    #...
  end
end
#:code#

```

---

<div class="post-metadata">

**Author:** ![dohmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/439d5e/32.png) [@dohmer](https://www.ruby-forum.com/u/dohmer)\
**Post date:** [February 3, 2006, 2:50pm UTC](https://www.ruby-forum.com/t/displaying-source-code-of-an-rhtml-file/53386/3 "2006-02-03T14:50:46Z")

</div>

I think ‘\<%%’, and possibly ‘%%\>’, will escape the ‘%’ in rhtml
