2

Question

What's the most lightweight, semantic, and over-all best way of referencing snippets of code within XHTML 1.1?


Claim

Snippets of code within HTML are not semantically proper. Snippets (ideally) would only be referenced or linked (using <object>, <a>, etc.), not embedded, escaped, and styled in full.


Rationale

  • Let browsers render code snippets
    • Having many custom server-side implementations tells me it should be standardized
    • Browsers can have plug-ins for copy+paste, download, etc.
      • Seems to me this is where it belongs (not in Javascript)
  • Why not use <code>
    • Escaped code is ugly
    • We render it for the client
    • No semantic representation of the language itself (MIME type would be nice)
  • Javascript is functionality, not presentation.
    • Syntax needs to be portable (i.e. no proprietary functionality)
    • No need for hacked-together solutions

Illustration

Resource      Tag    Actual resource              Alternative format
Image         img    An image located on server   `alt` attribute
Source code   ?      A file containing code       `code` tag? `a` link?

Example solution

code_sample.php is in the same directory as an HTML page containing the following:

<a href="code_sample.php" type="text/x-php">
  Example of widget creation
</a>
  • Pros
  • Cons
    • Not semantic enough? Seems wrong to replace hyperlinks with source code for presentation
    • <object> might be better, but wouldn't degrade as nicely.

What's the most lightweight, semantic, and over-all best way of referencing snippets of code within XHTML 1.1?

Tim
  • 2,383
  • 1
  • 15
  • 19

0 Answers0