TonyXT / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
0 stars 0 forks source link

Semantic HTML #39

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Right now the prettify library doesn't really promote semantic HTML. The
class "prettyprint" doesn't convey what the content of the tag is;
especially not without the prettify library.

Asking the user to manually call the prettyPrint() function using the
onload attribute in the <body> tag isn't very semantic either. Preferrably
the only thing the user should need to do would be to include the
prettify.js file.

I've modified the prettify.js file to include the aforementioned
suggestions (it has been attached to this issue.) <pre class="code"> tags
and <code> (note that no class is required) tags will be highlighted as
soon as the DOM has finished loading (sooner than the onload event) if the
prettify.js file has been loaded.

Original issue reported on code.google.com by andreasblixt on 30 May 2008 at 2:09

Attachments:

GoogleCodeExporter commented 8 years ago
I think semantic markup advocates have many good ideas, but it is not a goal of 
this
project to promote semanticness or any other markup layout methodology.
While I think avoiding the need for an explicit onload call is good, this 
project has
too many clients to change the API that radically now.

Could a wrapper script help make it easier for those who want to use semantic 
HTML to
use this code?

Original comment by mikesamuel@gmail.com on 6 Jan 2009 at 6:34

GoogleCodeExporter commented 8 years ago
I understand why you don't want to change the function of the script in order 
to keep 
backwards compatibility. I would propose making the code more configurable, so 
that 
the user of the script can decide how they want it to behave.

A few configurable variables could be added to the top of the script, one for 
configuring what tags/classes should be prettified, and one that decides how 
the 
prettify engine should be initialized. The current method of calling 
prettyPrint() on 
load is noticably "slower" (onload code might be triggered several seconds 
later in 
the browser than using the method in my aforementioned code to detect DOM 
load.) But 
since it's, as you say, used in many older clients, it could be kept the 
default 
behavior.

Original comment by andreasblixt on 6 Jan 2009 at 8:17

GoogleCodeExporter commented 8 years ago
I agree that it is a Good Idea to promote semantic HTML. According to the HTML5 
spec, code should have the class ".language-*". I modified prettify to do this 
<http://github.com/ariofrio/google-code-prettify>. You can find a thorough 
description of the changes in 
<http://github.com/ariofrio/google-code-prettify/blob/master/CHANGES.ariofrio>.

I also support the idea to make the script more configurable, allowing it to be 
called on DOM load.

Original comment by riofr...@gmail.com on 1 Nov 2010 at 12:05

GoogleCodeExporter commented 8 years ago
Actually, take that code with a grain of salt, since it breaks a few things. I 
am currently investigating the source of the misbehaviours.

Original comment by riofr...@gmail.com on 1 Nov 2010 at 1:49

GoogleCodeExporter commented 8 years ago
Are you referring to 4.6.11 ( 
http://www.w3.org/TR/html5/text-level-semantics.html#the-code-element ) :

    Although there is no formal way to indicate the language
    of computer code being marked up, authors who wish to
    mark code elements with the language used, e.g. so that
    syntax highlighting scripts can use the right rules, may do
    so by adding a class prefixed with "language-" to the element.

You say "should," whereas that section of HTML5 says "may."
Am I missing a section with stronger language?

Original comment by mikesamuel@gmail.com on 1 Nov 2010 at 2:55

GoogleCodeExporter commented 8 years ago
Of course, when I said should, I meant in my opinion. The point is that it 
would be great to be able to configure these things to cater to different 
environments, HTML5-following or not.

Original comment by riofr...@gmail.com on 29 Jan 2011 at 8:46