Prev: Can I refer width value not to the parent container cascade but to the current top browser window?
Next: b or strong?
From: Jukka K. Korpela on 6 Feb 2010 07:07 dorayme wrote: >> does CSS have a selector that allows the selection of content? I want >> to syntax highlight specific keywords in my pre and code tags, >> ideally operators, numerics, strings, and comments, too. > > No. "No" is the correct answer to the question in the given practical context. In general, however, there are some CSS selectors that select part of an element's textual content, such as p:first-line. They are of rather limited usefulness. Highlighting keywords requires inline markup for them, such as <b>int</b>. Such markup might be generated using preprocessor, or using server-side programming, or using client-side programming. You could use CSS to augment or replace the default rendering of <b> elements as desired. Note that <pre> and <code> elements are by default rendered using a monospace font. There's usually no particular reason to use monospace fonts for computer code, unless you regard tradition as a reason. But within text, it's often a good idea to render code in a font different from the normal text font, especially since code strings like print might otherwise be mistaken as normal word. -- Yucca, http://www.cs.tut.fi/~jkorpela/
From: Thomas 'PointedEars' Lahn on 8 Feb 2010 20:01 Jukka K. Korpela wrote: > Note that <pre> and <code> elements are by default rendered using a > monospace font. There's usually no particular reason to use monospace > fonts for computer code, Yes, there is: all characters use the same width, therefore it can be seen at a glance when code reaches a certain column (as it is often going to be displayed on text terminals, too), and source code is indented using the same width as other characters. By contrast, the width of the characters of proportial fonts vary, and their space and tab characters are considerably thinner, therefore so harder to recognize and easier to overlook. > unless you regard tradition as a reason. This particular tradition has a very practical reason, though. You haven't written much computer code lately, have you? PointedEars
From: Jukka K. Korpela on 9 Feb 2010 10:17 Thomas 'PointedEars' Lahn wrote: > Jukka K. Korpela wrote: > >> Note that <pre> and <code> elements are by default rendered using a >> monospace font. There's usually no particular reason to use monospace >> fonts for computer code, > > Yes, there is: all characters use the same width, That's what monospace means. > therefore it can be > seen at a glance when code reaches a certain column Why would that matter? Even if you're displaying FORTRAN IV, why would that matter (when presenting a source program)? > (as it is often > going to be displayed on text terminals, too), And why would _that_ matter, even if it were true? > and source code is > indented using the same width as other characters. Source code is indented using spaces, so why would it matter what the widths of other characters are? (You can indent using tabs, but that's not safe, and doesn't change this point.) > By contrast, the > width of the characters of proportial fonts vary, Really? :-) > and their space and > tab characters are considerably thinner, therefore so harder to > recognize and easier to overlook. The width of space varies by font, and the typically larger width in monospace fonts implies more coarseness rather than anything else. Tab characters have no width; they are control characters. >> unless you regard tradition as a reason. > > This particular tradition has a very practical reason, though. You failed to give any reason, practical or theoretical. > You haven't written much computer code lately, have you? If you need to know, I write computer code on a daily basis, and program code fairly often too. I might just as well ask you how many compilers you have written or how many books on programming you have written, but I resist the temptation. It's really irrelevant, since we are not discussing program _writing_ but about _displaying_ computer code on a web page. -- Yucca, http://www.cs.tut.fi/~jkorpela/
From: Darin McGrew on 9 Feb 2010 16:42 Jukka K. Korpela <jkorpela(a)cs.tut.fi> wrote: > Source code is indented using spaces, so why would it matter what the widths > of other characters are? (You can indent using tabs, but that's not safe, > and doesn't change this point.) The example that comes to mind is when a series of arguments won't fit on a single line, and you want to align the first argument on the second line with the first argument on the first line. With some formatting styles, the width of non-space characters wouldn't matter, for example: my_function( arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12 ) But with other formatting styles, it does matter, for example: my_function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) -- Darin McGrew, mcgrew(a)stanfordalumni.org, http://www.rahul.net/mcgrew/ Web Design Group, darin(a)htmlhelp.com, http://www.HTMLHelp.com/ "You learn nothing new the third time a mule kicks you in the head."
From: Ben C on 9 Feb 2010 16:54
On 2010-02-09, Jukka K. Korpela <jkorpela(a)cs.tut.fi> wrote: [...] >> and source code is >> indented using the same width as other characters. > > Source code is indented using spaces, so why would it matter what the widths > of other characters are? (You can indent using tabs, but that's not safe, > and doesn't change this point.) Source code is often indented with tabs, and if you're using a proportional font I'd say it's preferable to use tabs. Otherwise you can only indent at the start of lines, but this sort of layout is common in programming and reasonably agreeable: union thing { int foo; /* blah blah */ float bar; /* blah */ }; In fact being able to use a proportional font is one of the things that comes up in the great tabs vs spaces arguments. >> By contrast, the >> width of the characters of proportial fonts vary, > > Really? :-) > >> and their space and >> tab characters are considerably thinner, therefore so harder to >> recognize and easier to overlook. > > The width of space varies by font, and the typically larger width in > monospace fonts implies more coarseness rather than anything else. Tab > characters have no width; they are control characters. > >>> unless you regard tradition as a reason. >> >> This particular tradition has a very practical reason, though. > > You failed to give any reason, practical or theoretical. > >> You haven't written much computer code lately, have you? > > If you need to know, I write computer code on a daily basis, and program > code fairly often too. I might just as well ask you how many compilers you > have written or how many books on programming you have written, but I resist > the temptation. It's really irrelevant, since we are not discussing program > _writing_ but about _displaying_ computer code on a web page. In practice a lot of code will look badly formatted if just stuffed into a white-space: pre box in a proportional font because people often lay things out on the assumption that the font is monospaced. |