Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Formatting code/scripts/configuration files rendered on a website

Question posted by: Hendrik Maryns (Guest) on June 27th, 2008 07:19 PM
Hi,

Since I was so pleased to discover how to enable my keyboard to type
symbols like … directly, I made a howto-page about it:
http://tcl.sfs.uni-tuebingen.de/~hendrik/keyboard.shtml.

I tried to follow the advice from
http://xhtml.com/en/xhtml/reference/pre/ to not use the <pretag, but I
am not satisfied with it, since tabs are not preserved (see bottom
part). This is not essential here, but would be nice. Can I do that
with an addition to the CSS given on the link above? (I removed #
margin: 1px 0; since I don’t like it.)

H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Hendrik Maryns's Avatar
Hendrik Maryns
Guest
n/a Posts
June 27th, 2008
07:19 PM
#2

Re: Formatting code/scripts/configuration files rendered on a website
Hendrik Maryns schreef:
Quote:
Originally Posted by
Hi,
>
Since I was so pleased to discover how to enable my keyboard to type
symbols like … directly, I made a howto-page about it:
http://tcl.sfs.uni-tuebingen.de/~hendrik/keyboard.shtml.
>
I tried to follow the advice from
http://xhtml.com/en/xhtml/reference/pre/ to not use the <pretag, but I
am not satisfied with it, since tabs are not preserved (see bottom
part). This is not essential here, but would be nice. Can I do that
with an addition to the CSS given on the link above? (I removed #
margin: 1px 0; since I don’t like it.)


Ok, found it already, simply add

white-space: pre;

to ol.code-unnumbered li (note: *not* to ol.code-unnumbered).

H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Jukka K. Korpela's Avatar
Jukka K. Korpela
Guest
n/a Posts
June 27th, 2008
07:19 PM
#3

Re: Formatting code/scripts/configuration files rendered on a website
Scripsit Hendrik Maryns:
Quote:
Originally Posted by
I tried to follow the advice from
http://xhtml.com/en/xhtml/reference/pre/ to not use the <pretag,


Why? Their page looks reasonable (at least when viewed text-only, the
usual bogosity check), and they have a superficially good argument
(<precarries no meaning), but what _is_ this xhtml.com? The only
information I found easily is an obfuscated E-mail address:
"For comments about xhtml.com, please contact: feedback [at] xhtml.com"

This gives an initial expectation of credibility around -100.

The argument isn't really that good. What do you use instead? If you
have data where whitespace really matters, like Python code, then why
would you _rely_ on CSS as regards to getting this important _content_
information delivered?

The usual CSS Caveats imply that <pre>, rather than any CSS constructs,
are the right way to go if the data _is_ really preformatted plain text
and preserving that is essential.
Quote:
Originally Posted by
but I am not satisfied with it, since tabs are not preserved


By HTML specifications, tab stops should appear in a certain way _and_
authors should not rely on this. Use the safe way: spaces.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Harlan Messinger's Avatar
Harlan Messinger
Guest
n/a Posts
June 27th, 2008
07:19 PM
#4

Re: Formatting code/scripts/configuration files rendered on a website
Jukka K. Korpela wrote:
Quote:
Originally Posted by
Scripsit Hendrik Maryns:
>
Quote:
Originally Posted by
>I tried to follow the advice from
>http://xhtml.com/en/xhtml/reference/pre/ to not use the <pretag,

>
Why? Their page looks reasonable (at least when viewed text-only, the
usual bogosity check), and they have a superficially good argument
(<precarries no meaning), but what _is_ this xhtml.com? The only
information I found easily is an obfuscated E-mail address:
"For comments about xhtml.com, please contact: feedback [at] xhtml.com"
>
This gives an initial expectation of credibility around -100.


There are no limits to the irrelevance of the factors on which you base
your credibility assessments, are there? Their credibility on the value
of the PRE tag can be judged by your personal feelings about munged
e-mail addresses? That's like saying that the initial expectation of
credibility of the remainder of your response (which is a great
treatment) is -100% because of your bogus invocation of their approach
to contact information.

Jukka K. Korpela's Avatar
Jukka K. Korpela
Guest
n/a Posts
June 27th, 2008
07:19 PM
#5

Re: Formatting code/scripts/configuration files rendered on a website
Scripsit Harlan Messinger:
Quote:
Originally Posted by
Their credibility on
the value of the PRE tag can be judged by your personal feelings
about munged e-mail addresses?


No, their _general_ credibility gets a low initial score due to the
_fact_ that they don't even tell who they are (and don't even tell their
names and real e-mail address).
Quote:
Originally Posted by
That's like saying that the initial
expectation of credibility of the remainder of your response (which
is a great treatment) is -100% because of your bogus invocation of
their approach to contact information.


That's like your usual babbling about irrelevant things. I think you
could do better. You might have, for example, made a _single_ reasonable
or reasonable-looking comment on the on-topic issue whether <preshould
really be avoided in favor of CSS (or even on the remotely-on-topic
issue whether xhtml.com should be relied on).

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Harlan Messinger's Avatar
Harlan Messinger
Guest
n/a Posts
June 27th, 2008
07:19 PM
#6

Re: Formatting code/scripts/configuration files rendered on a website
Jukka K. Korpela wrote:
Quote:
Originally Posted by
Scripsit Harlan Messinger:
>
Quote:
Originally Posted by
>Their credibility on
>the value of the PRE tag can be judged by your personal feelings
>about munged e-mail addresses?

>
No, their _general_ credibility gets a low initial score due to the
_fact_ that they don't even tell who they are (and don't even tell their
names and real e-mail address).


?? Most products you buy in the store carry neither the name of the
owner or CEO of either the manufacturer or the store. Why does a website
have to carry the name of its owner?
Quote:
Originally Posted by
>
Quote:
Originally Posted by
>That's like saying that the initial
>expectation of credibility of the remainder of your response (which
>is a great treatment) is -100% because of your bogus invocation of
>their approach to contact information.

>
That's like your usual babbling about irrelevant things.


Gee, responding when I call you on your appeal to irrelevant factors by
pretending it's irrelevant. Did you think of that all by yourself?
Quote:
Originally Posted by
I think you
could do better. You might have, for example, made a _single_ reasonable
or reasonable-looking comment on the on-topic issue whether <preshould
really be avoided in favor of CSS (or even on the remotely-on-topic
issue whether xhtml.com should be relied on).


Nice job of hand-waving.

Stanimir Stamenkov's Avatar
Stanimir Stamenkov
Guest
n/a Posts
June 27th, 2008
07:19 PM
#7

Re: Formatting code/scripts/configuration files rendered on a website
Wed, 18 Jun 2008 14:44:14 +0200, /Hendrik Maryns/:
Quote:
Originally Posted by
I tried to follow the advice from
http://xhtml.com/en/xhtml/reference/pre/ to not use the <pretag,


If the only reason not use <preis it "has no semantic meaning" you
could give it meaning, like:

<pre><code>...</code></pre>

At least I use the above often and there's a <blockcode[1] element
in the XHTML 2 draft which I mimic using that markup. Depending on
the content you could use also:

<pre><samp>...</samp></pre>

I guess one could come up with more examples. I tend to think of
<preas paragraph or generic block (<div>), interchangeably, which
has some predefined styling.

[1]
http://www.w3.org/TR/xhtml2/mod-str...tural_blockcode

--
Stanimir

Andy Dingley's Avatar
Andy Dingley
Guest
n/a Posts
June 27th, 2008
07:19 PM
#8

Re: Formatting code/scripts/configuration files rendered on a website
On 18 Jun, 20:19, "Jukka K. Korpela" <jkorp...@cs.tut.fiwrote:
Quote:
Originally Posted by
No, their _general_ credibility gets a low initial score due to the
_fact_ that they don't even tell who they are (and don't even tell their
names and real e-mail address).


The problem with that logic is that it describes Richard Bullis as
credible,
because his self-evident stupidity is such a strong authentication of
his identity.

Hendrik Maryns's Avatar
Hendrik Maryns
Guest
n/a Posts
June 27th, 2008
07:19 PM
#9

Re: Formatting code/scripts/configuration files rendered on a website
Jukka K. Korpela schreef:
Quote:
Originally Posted by
Scripsit Hendrik Maryns:
>
Quote:
Originally Posted by
>I tried to follow the advice from
>http://xhtml.com/en/xhtml/reference/pre/ to not use the <pretag,

>
Why? Their page looks reasonable (at least when viewed text-only, the
usual bogosity check), and they have a superficially good argument
(<precarries no meaning), but what _is_ this xhtml.com? The only
information I found easily is an obfuscated E-mail address:
"For comments about xhtml.com, please contact: feedback [at] xhtml.com"
>
This gives an initial expectation of credibility around -100.


Notwithstanding your objections, I found the site very helpful,
containing nice suggestions to format <codeand <kbd>.
Quote:
Originally Posted by
The argument isn't really that good. What do you use instead? If you
have data where whitespace really matters, like Python code, then why
would you _rely_ on CSS as regards to getting this important _content_
information delivered?
>
The usual CSS Caveats imply that <pre>, rather than any CSS constructs,
are the right way to go if the data _is_ really preformatted plain text
and preserving that is essential.
>
Quote:
Originally Posted by
>but I am not satisfied with it, since tabs are not preserved

>
By HTML specifications, tab stops should appear in a certain way _and_
authors should not rely on this. Use the safe way: spaces.


Can you explain this further? I do not want to use spaces there since
that’s not what I use in the original file as well. Tabs are meant for
aligning, right, well, that’s just what I want to happen there.

I could wrap the whole thing in a table, right, but that would make it
more work than it’s worth.

Cheers, H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Hendrik Maryns's Avatar
Hendrik Maryns
Guest
n/a Posts
June 27th, 2008
07:19 PM
#10

Re: Formatting code/scripts/configuration files rendered on a website
Stanimir Stamenkov schreef:
Quote:
Originally Posted by
Wed, 18 Jun 2008 14:44:14 +0200, /Hendrik Maryns/:
>
Quote:
Originally Posted by
>I tried to follow the advice from
>http://xhtml.com/en/xhtml/reference/pre/ to not use the <pretag,

>
If the only reason not use <preis it "has no semantic meaning" you
could give it meaning, like:
>
<pre><code>...</code></pre>


Hm, but what with the example from the site I gave? It is not really
code, but rather some configuration information in a file.
Quote:
Originally Posted by
<pre><samp>...</samp></pre>


This seems more appropriate, but maybe just <preseems the right way to
go, really, as Jukka suggested.

H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Jukka K. Korpela's Avatar
Jukka K. Korpela
Guest
n/a Posts
June 27th, 2008
07:19 PM
#11

Re: Formatting code/scripts/configuration files rendered on a website
Scripsit Stanimir Stamenkov:
Quote:
Originally Posted by
If the only reason not use <preis it "has no semantic meaning" you
could give it meaning, like:
>
<pre><code>...</code></pre>


That does not give any meaning to <pre>. Using semantic markup inside
non-semantic markup does not make the outer markup any more markup. Au
contraire, it empasizes its semantic emptyness.

Yet, <preis the only way in HTML to specify that whitespace is
significant, so if your data has "a b" that shall be intepreted as
different from "a b" in meaning, then <preis the correct markup.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Jukka K. Korpela's Avatar
Jukka K. Korpela
Guest
n/a Posts
June 27th, 2008
07:19 PM
#12

Re: Formatting code/scripts/configuration files rendered on a website
Scripsit Hendrik Maryns:
Quote:
Originally Posted by
Quote:
Originally Posted by
>By HTML specifications, tab stops should appear in a certain way
>_and_ authors should not rely on this. Use the safe way: spaces.

>
Can you explain this further?


Quoting the HTML 4.01 spec (which echoes HTML 2, though with some
obscurity):

"The horizontal tab character [...] is usually interpreted by visual
user agents as the smallest non-zero number of spaces necessary to line
characters up along tab stops that are every 8 characters. We strongly
discourage using horizontal tabs in preformatted text since it is common
practice, when editing, to set the tab-spacing to other values, leading
to misaligned documents."

http://www.w3.org/TR/html4/struct/text.html#h-9.3.4

Well, it doesn't explain much. But tab stop settings may depend on the
environment, so the tab character does not work reliably.
Quote:
Originally Posted by
I do not want to use spaces there since
that’s not what I use in the original file as well.


Yet, it's the effect that matters, and spaces are the safe way to
achieve that.

I've used the M-x untabify function in Emacs, the text editor, when I
have needed to convert text with tabs to text without them.
Quote:
Originally Posted by
I could wrap the whole thing in a table, right, but that would make it
more work than it’s worth.


I agree that it's not very practical, and neither is the idea of using
<divmarkup with classes and styling - though this would be the way to
achieve indentation that is easily modified just by changing one CSS
rule.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Stanimir Stamenkov's Avatar
Stanimir Stamenkov
Guest
n/a Posts
June 27th, 2008
07:19 PM
#13

Re: Formatting code/scripts/configuration files rendered on a website
Thu, 19 Jun 2008 20:00:52 +0300, /Jukka K. Korpela/:
Quote:
Originally Posted by
Scripsit Stanimir Stamenkov:
>
Quote:
Originally Posted by
>If the only reason not use <preis it "has no semantic meaning" you
>could give it meaning, like:
>>
><pre><code>...</code></pre>

>
That does not give any meaning to <pre>. Using semantic markup inside
non-semantic markup does not make the outer markup any more markup. Au
contraire, it empasizes its semantic emptyness.
>
Yet, <preis the only way in HTML to specify that whitespace is
significant, so if your data has "a b" that shall be intepreted as
different from "a b" in meaning, then <preis the correct markup.


So combining "the <premeaning is a block where whitespace matters"
further marking the content as <codeseems good way to go, or I'm
missing something?

--
Stanimir

Jukka K. Korpela's Avatar
Jukka K. Korpela
Guest
n/a Posts
June 27th, 2008
07:19 PM
#14

Re: Formatting code/scripts/configuration files rendered on a website
Scripsit Stanimir Stamenkov:
Quote:
Originally Posted by
So combining "the <premeaning is a block where whitespace matters"
further marking the content as <codeseems good way to go, or I'm
missing something?


I think that's the best way for computer code where whitespace matters.

Using <codeis not pragmatically very important, since <premarkup
already sets the font to monospace, but <codecarries semantic
information, could be used for styling, and it is observed by some
automatic translation software (so that they treat <codecontents as
literal, to be preserved as such).

For example, if you have both blocks of code and some fragments of code
in paragraphs, using <codefor all code is a good idea, for uniform
styling. (Or for non-uniform in a controlled manner, via classes, since
you might wish to make a visual distinction e.g. between source program
code and operating system commands.)

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Chris F.A. Johnson's Avatar
Chris F.A. Johnson
Guest
n/a Posts
June 27th, 2008
07:19 PM
#15

Re: Formatting code/scripts/configuration files rendered on a website
On 2008-06-19, Stanimir Stamenkov wrote:
Quote:
Originally Posted by
Thu, 19 Jun 2008 20:00:52 +0300, /Jukka K. Korpela/:
Quote:
Originally Posted by
>Scripsit Stanimir Stamenkov:
>>
Quote:
Originally Posted by
>>If the only reason not use <preis it "has no semantic meaning" you
>>could give it meaning, like:
>>>
>><pre><code>...</code></pre>

>>
>That does not give any meaning to <pre>. Using semantic markup inside
>non-semantic markup does not make the outer markup any more markup. Au
>contraire, it empasizes its semantic emptyness.
>>
>Yet, <preis the only way in HTML to specify that whitespace is
>significant, so if your data has "a b" that shall be intepreted as
>different from "a b" in meaning, then <preis the correct markup.

>
So combining "the <premeaning is a block where whitespace matters"
further marking the content as <codeseems good way to go, or I'm
missing something?


Rather than two nested elements, I'd use a class:

<pre class="code">

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

 
Not the answer you were looking for? Post your question . . .
182,257 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors