[Discuss] HTML formatting question

manfred at mosabuam.com manfred at mosabuam.com
Fri Oct 13 13:35:41 PDT 2006


I am just going to assume that you want to format source code.. the  
approach works for anything though..

Here is a snippet of Java

public class Foo
{
     private String bar;

     public String getBar()
     {
         return bar;
     }

     public void setBar(String bar)
     {
         this.bar = bar;
     }
}

And here is a html'ified version

<html>
<head>
<title>Foo.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.keyword { color: rgb(0,0,128); font-weight: bold; }
.other { }
</style>
</head>
<body>
<h1>Foo.java</h1>

<pre>

<span class="keyword">public class </span><span class="other">Foo
{
     </span><span class="keyword">private </span><span  
class="other">String bar;

     </span><span class="keyword">public </span><span  
class="other">String getBar()
     {
         </span><span class="keyword">return </span><span class="other">bar;
     }

     </span><span class="keyword">public void </span><span  
class="other">setBar(String bar)
     {
         </span><span class="keyword">this</span><span  
class="other">.bar = bar;
     }
}
</span></pre>
</body>
</html>


Notice that pre preserves the spacing and the class/style does the  
coloring. Quite tedious but works. However if you need to do that more  
often I recommned using a good ide that will have an export. I used  
IntelliJ. It can add line numbers and add linking across your whole  
project. There is lots of similar stuff around for java (e.g. check  
the maven jxr plugin).

I am rambling

manfred
Vancouver Island Java User Group
http://www.mosabuam.com/vijug



Quoting Ronald Schouten <ron at atomeo.com>:

> I think the problem you are running into is that <pre> elements cannot be
> nested within <pre> elements and <font> tags are just plain wrong
> (deprecated) and will through an error no matter where they are. Without
> knowing what you want to contain in the <pre> element and why I would
> recommend using <span> elements or other more semantic mark-up to further
> identify and style your text.
>
> Hope that makes sense,
>
> Ron
>
> On 13/10/06, Thomas McVeigh <thom at idar.com> wrote:
>>
>>
>> On 13-Oct-06, at 11:50 AM, Adam Parkin wrote:
>>
>>> But the w3 validator chokes on this as apparently you cannot have a
>>> font tag inside a pre tag.
>>
>>
>> What I think you want is blockquote.
>>  Syntax:
>>     <blockquote> ... </blockquote>
>>
>> The blockquote tag is used to offset a block of text (a citation)
>> from the rest of the document. The exact appearance will be browser
>> dependent. However, the citation is usually indented on both the
>> right and left margins, may be in italics, and is preceded and
>> followed by paragraph breaks. You will still need to use the br, p,
>> and possibly other HTML tags to effect the textual display and
>> appearance that you desire. In fact, you can use any other HTML tag
>> inside a blockquote, including cite and q.
>>
>> It is recommended that you use the blockquote tag for long citations
>> and the cite tag for short citations.
>>
>> The separate closing tag is mandatory.
>> _______________________________________________
>> Discuss mailing list
>> Discuss at vlug.org
>> http://ladybug.vlug.org/cgi-bin/mailman/listinfo/discuss
>>
> _______________________________________________
> Discuss mailing list
> Discuss at vlug.org
> http://ladybug.vlug.org/cgi-bin/mailman/listinfo/discuss




More information about the Discuss mailing list