473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Web pages for algorithm instruction/documentation.

Hi:

being a relatively inexperienced HTML user I would like to
ask you if you know of any macro(?), css style(?) or any
other convenient method which would allow to quote pieces
of code with line numbers and support some sort of inline
or maybe in a 2nd column documentation of the code?

I use my own macros for that in TeX: verbatim quote with
1st number declared to be a value of choice.

So far I found nothing like it possible in HTML, but the
world of Web is so vast in its inventiveness, I wanted
ask if such solution exists some place or is described in
one of the books?

Thanks in advance.

Thomas
Apr 19 '06 #1
3 1416
ThomasH wrote:
other convenient method which would allow to quote pieces
of code with line numbers and support some sort of inline
or maybe in a 2nd column documentation of the code?


Interesting question! It's not easy.

On the whole, I'd suggest using a <table>. Whatever you do, the markup
is nasty and bulky. It's not a job for hand coding, it's a job for a
script to generate (XSLT, Perl, sed whatever)

The root of the problem is HTML's poor flow model. It's just not
possible to have three column cells across a row and to preserve the
row alignments, unless you start using heavy-handed markup on every
cell. This is basically a <table> (and the anti-table weenies should
shut up, as this _is_ tabular data as soon as you make this
requirement). There's no way I know to have "a column of code" and to
attach annotations to it accurately aligned to line positions, or to
add the line numbering.

Maybe you could do it with <ol> and a <li> per line, but the CSS
properties to control numbering are poorly supported.
Here's my quick half-cup-of-coffee hack at it instead with floats. It
degrades without CSS fairly well, owing to the use of <pre>, but it's
very whitespace sensitive.

You may also need to (and should) wrap the code in <![CDATA[ ... ]]>
sections, in case of embedded "<" etc.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en"><head>
<title>Code Listing</title>

<style type="text/css" >
body {
color: #000;
background-color: #8FECFF;
font-size: 1em;
}

pre.code-listing {
border: thin inset #777;
background-color: #eee;
color: #000;
margin: 1em;
padding: 2em 1em ;
}

.code-listing>* {
margin: 0;
padding: 0;
}

.code-listing .line-no {
clear: left;
float: left;
display: block;
width: 3em;
text-align: right;
padding-right: 2em;
}

.code-listing .code {
display: block;
float: left;
clear: none;
width: 50%;
}

.code-listing .annotation {
float: left;
clear: none;
display: block;

background-color: #FAFFCF;
color: #000;
font-family: serif;
font-style: oblique;
padding: 0.125em 1em;
}
</style>

</head><body>

<pre class="code-listing" >
<span class="line-no" >1</span><span class="code" >while getopts
"hlnstvq" flag</span>
<span class="line-no" >2</span><span class="code" >do</span><span
class="annotation" >Foo bar bat</span>
<span class="line-no" >3</span><span class="code" > case "$flag"
in</span>
<span class="line-no" >4</span><span class="code" > l)
LOCAL_FILES_FOR_LOCAL_PEOPLE=y;;</span>
<span class="line-no" >5</span><span class="code" > n)
NO_NOTES=y;;</span>
<span class="line-no" >6</span><span class="code" > s)
QUICK_VIEW=y;;</span>
<span class="line-no" >7</span><span class="code" > t)
TRUNKS_ONLY=y;;</span>
<span class="line-no" >8</span><span class="code" > q)
QUIET=y;;</span>
<span class="line-no" >9</span><span class="code" > v)
VERBOSE=y;;</span>
<span class="line-no" >10</span><span class="code" > h)
help;;</span>
<span class="line-no" >11</span><span class="code" > ?) echo
"Ignoring unimplemented option: "$flag</span>
<span class="line-no" >12</span><span class="code" > esac</span>
<span class="line-no" >13</span><span class="code" >done</span>
</pre>

</body> </html>

Apr 20 '06 #2
In article <8Z**************@news.oracle.com>,
ThomasH <he******@coco.net> wrote:
Hi:

being a relatively inexperienced HTML user I would like to
ask you if you know of any macro(?), css style(?) or any
other convenient method which would allow to quote pieces
of code with line numbers and support some sort of inline
or maybe in a 2nd column documentation of the code?

I use my own macros for that in TeX: verbatim quote with
1st number declared to be a value of choice.

So far I found nothing like it possible in HTML, but the
world of Web is so vast in its inventiveness, I wanted
ask if such solution exists some place or is described in
one of the books?


An orderered list, ol, will give you automatic line numbering
(and usually indentation - it does in the browsers I use, anyway)
for subsequent list items, li. You could create a li class
that suggests a fixed-width font such as courier for rendering.

Computer code often seems to be marked up using the pre element
- see "9.3.4 Preformatted text: The PRE element" of the html 4
specs. That doesn't give automatic line-numbering, though. Not
sure if it's kosher to use <li><pre>
Apr 20 '06 #3
Andy Dingley wrote on 20-Apr-06 06:13:
ThomasH wrote:
other convenient method which would allow to quote pieces
of code with line numbers and support some sort of inline
or maybe in a 2nd column documentation of the code?
Interesting question! It's not easy.


Thanks for the both hints.

Obviously, we do not have out of the box solutions
comparable to what we can do with the mighty TeX macros!

Currently I experiment with is a script making indeed
a html table(!) from a file, using monospaced font, and
placing comments to the code in a left column. I will
make some experiments of my script in conjunction with
your CSS (I am a very beginner with CSS and PHP) in an
attempt to "marry" these both ideas.

As soon I will get something presentable, I will post
it here. Someone recommended me to use Awk or perl
generator in lieu of the shell script for better
portability. This also sound interesting.

Thomas

On the whole, I'd suggest using a <table>. Whatever you do, the markup
is nasty and bulky. It's not a job for hand coding, it's a job for a
script to generate (XSLT, Perl, sed whatever)

The root of the problem is HTML's poor flow model. It's just not
possible to have three column cells across a row and to preserve the
row alignments, unless you start using heavy-handed markup on every
cell. This is basically a <table> (and the anti-table weenies should
shut up, as this _is_ tabular data as soon as you make this
requirement). There's no way I know to have "a column of code" and to
attach annotations to it accurately aligned to line positions, or to
add the line numbering.

Maybe you could do it with <ol> and a <li> per line, but the CSS
properties to control numbering are poorly supported.
Here's my quick half-cup-of-coffee hack at it instead with floats. It
degrades without CSS fairly well, owing to the use of <pre>, but it's
very whitespace sensitive.

You may also need to (and should) wrap the code in <![CDATA[ ... ]]>
sections, in case of embedded "<" etc.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en"><head>
<title>Code Listing</title>

<style type="text/css" >
body {
color: #000;
background-color: #8FECFF;
font-size: 1em;
}

pre.code-listing {
border: thin inset #777;
background-color: #eee;
color: #000;
margin: 1em;
padding: 2em 1em ;
}

.code-listing>* {
margin: 0;
padding: 0;
}

.code-listing .line-no {
clear: left;
float: left;
display: block;
width: 3em;
text-align: right;
padding-right: 2em;
}

.code-listing .code {
display: block;
float: left;
clear: none;
width: 50%;
}

.code-listing .annotation {
float: left;
clear: none;
display: block;

background-color: #FAFFCF;
color: #000;
font-family: serif;
font-style: oblique;
padding: 0.125em 1em;
}
</style>

</head><body>

<pre class="code-listing" >
<span class="line-no" >1</span><span class="code" >while getopts
"hlnstvq" flag</span>
<span class="line-no" >2</span><span class="code" >do</span><span
class="annotation" >Foo bar bat</span>
<span class="line-no" >3</span><span class="code" > case "$flag"
in</span>
<span class="line-no" >4</span><span class="code" > l)
LOCAL_FILES_FOR_LOCAL_PEOPLE=y;;</span>
<span class="line-no" >5</span><span class="code" > n)
NO_NOTES=y;;</span>
<span class="line-no" >6</span><span class="code" > s)
QUICK_VIEW=y;;</span>
<span class="line-no" >7</span><span class="code" > t)
TRUNKS_ONLY=y;;</span>
<span class="line-no" >8</span><span class="code" > q)
QUIET=y;;</span>
<span class="line-no" >9</span><span class="code" > v)
VERBOSE=y;;</span>
<span class="line-no" >10</span><span class="code" > h)
help;;</span>
<span class="line-no" >11</span><span class="code" > ?) echo
"Ignoring unimplemented option: "$flag</span>
<span class="line-no" >12</span><span class="code" > esac</span>
<span class="line-no" >13</span><span class="code" >done</span>
</pre>

</body> </html>

Apr 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Olaf Gschweng | last post by:
We're new into DB2 and have some problem with DB2 8.1 (?) on a Linux system. We load some big tables of a DB2 database from files every day. We do a "DELETE FROM table" for each table and then we...
14
by: Tiza Naziri | last post by:
Hi, Anybody have an idea on how to start writing a C code for generating the inverse of finite field GF(2^8) using extended Euclidean algorithm? What I mean is how to represent a polynomial,...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
11
by: EagleRed | last post by:
I am writing an ASP.NET 2.0 application that uses master pages. I have some pages that must not be cached on the client. In ASP.NET 1.1 I achieved this using metatags: <meta...
4
prometheuzz
by: prometheuzz | last post by:
Hello (Java) enthusiasts, In this article I’d like to tell you a little bit about graphs and how you can search a graph using the BFS (breadth first search) algorithm. I’ll address, and...
0
by: alagan | last post by:
Hai Guys, I'm Mathiyalgan... Working as asp.net developer in a small software concern . I've seen ur Article in the website...4guysfromrolla... It is quite nice... I hav used...
4
by: Jeff | last post by:
I've been working on porting some perl CMS code to PHP. What I would do in perl is search through a template for instruction and replace those instructions with specific bits for that particular...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
4
by: yogi_bear_79 | last post by:
I am stuck on a few open-book multiple choice questions for this class. I have answers, but I can not back them up. Any insight would be helpful, a link to read, or just hey dummy you are wrong. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.