This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 12730 - Suggestion: Codeblock element
Summary: Suggestion: Codeblock element
Status: RESOLVED INVALID
Alias: None
Product: HTML WG
Classification: Unclassified
Component: LC1 HTML5 spec (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 enhancement
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-23 23:39 UTC by Adam Moore
Modified: 2011-08-04 05:34 UTC (History)
6 users (show)

See Also:


Attachments

Description Adam Moore 2011-05-23 23:39:17 UTC
Suggestion in section 4.5 Grouping Content

Problem: I'm building webpages that give lessons in C#. They are pages with multiple blocks of code between paragraphs explaining the code. The code blocks are enclosed by PRE and CODE tags

Example:

<pre class="c-sharp"><code>
public class MyException : ApplicationException
{
	private ExceptionLevel exceptionLevel;
	private LogLevel logLevel;
	private Exception myException;
	private string exceptionMessage;

	public string ExceptionMessage
	{
		get { return this.exceptionMessage; }
		set { this.exceptionMessage = value; }
	}

	public MyException()
	{ }

	public MyException(ExceptionLevel exceptionLevel,
						LogLevel logLevel,
						Exception exception,
						string exceptionMessage)
	{
		this.exceptionLevel = exceptionLevel;
		this.logLevel = logLevel;
		this.myException = exception;
		this.exceptionMessage = exceptionMessage;
	}
}
</code></pre>

Because these pages are for students learning the programming language, syntax highlighting is necessary for the pages to be readable. There is far too much content to go through and add all the color formatting with span tags, so I have decided to use a syntax highlighting script. Thus far, the only syntax highlighting script I have found requires the PRE tag to have a class of the programming language that is enclosed by the CODE tag.  This is backwards - the Code tag should describe the programming language enclosed within, not the PRE tag. Plus, there is code smell in the source of my html document. Well over half of the code tags are enclosed in pre tags simply because I need to display a block of pre-formatted code. This is a very common need, probably more common than displaying a single line of code.

Solution:
<codeblock>

Codeblock would be an element used to enclose a block of pre-formatted code without having to nest a code element within a pre element.

Old: <pre class="c-sharp"><code>
New: <codeblock class="c-sharp">
Comment 1 Tab Atkins Jr. 2011-05-24 00:11:50 UTC
Even if <codeblock> were added, your syntax highlighters still wouldn't work until they were updated to look at <codeblock> instead of <pre>.  It seems easier to just update them to look at <code> instead - that way we don't need to change the spec and browsers as well as syntax highlighting scripts.
Comment 2 Adam Moore 2011-05-24 16:10:11 UTC
(In reply to comment #1)
> Even if <codeblock> were added, your syntax highlighters still wouldn't work
> until they were updated to look at <codeblock> instead of <pre>.  It seems
> easier to just update them to look at <code> instead - that way we don't need
> to change the spec and browsers as well as syntax highlighting scripts.

Thanks for the suggestion Tab. That's probably what I'll end up doing.
Comment 3 Simon Pieters 2011-05-25 07:15:49 UTC
Closing per comment 2. Reopen if you still want the editor to consider the proposal.
Comment 4 Michael[tm] Smith 2011-08-04 05:34:07 UTC
mass-move component to LC1