473,804 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1430
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="annotati on" >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="annotati on" >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
4026
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 load the data by something like that: LOAD FROM "/pathto/artikel.data" OF DEL MODIFIED BY DATESISO CHARDEL0xbf SAVECOUNT 50000 MESSAGES "/pathto/artikel.msg" INSERT INTO artikel;
14
11336
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, e.g. f(x)=x^8+x^4+x^3+x+1 in C? How to represent the multiplication & division process of polynomial? Regards.
4
4287
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 is stored in a double linked list, the whole list is sorted for the next round. My problem appears when subjecting the program to heavy load, that is, when I run the simulation for more than 10,000 miliseconds (every event occurs in...
11
12130
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 http-equiv="Expires" content="0"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> This tags are part of the <headelement. Sample code that I have seen shows how to add metatags of the form:
4
32085
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 hopefully answer, the following questions: • what is a graph? • how can a graph be represented as an ADT? • how can we search/walk through a graph using the BFS algorithm?
0
1098
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 master pages in my application... and i want to use some validation controls in my content pages.. I 've tried but it causes an Error like Server Error in '/Winfairr' Application....
4
1911
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 page and page path. With PHP it's easy to embed instruction in the html and output thhat as a .php page. How do I write a .html as a file? I can think of some awkward ways to do this.
20
3098
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 like 65% of the time of the second routine. Yet both do the same thing. However, the second one seems better in terms of the way the code is written since it helps encapsulate the transformation in the inner loop better making it easier to read,...
4
2076
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. thanks A(n) ______ is another way of writing a logarithmic equation. a. exponetial equation b. instruction function c. time complexity (MY CHOICE)
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9572
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10070
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.