Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add <code> element inside applicable <pre> elements #3768

Merged
merged 1 commit into from
Jul 23, 2018

Conversation

Zirro
Copy link
Contributor

@Zirro Zirro commented Jun 20, 2018

Resolves #3753 and #3764.

This is not ready to be merged yet as it'll also require a few changes to the build system and CSS to target <code> elements rather than <pre> elements. I'd also like to go over it again to make sure it's correct in all locations.

I added an explicit html class rather than having it be implicit as was the case before, since there are some non-HTML/CSS/JS/IDL <pre>s as well. Figured it might come in handy some day.

@sideshowbarker, would these changes work well for you once the syntax highlighting has been adjusted to account for the <code> elements?


/browsers.html ( diff )
/browsing-the-web.html ( diff )
/canvas.html ( diff )
/common-dom-interfaces.html ( diff )
/common-microsyntaxes.html ( diff )
/comms.html ( diff )
/custom-elements.html ( diff )
/dnd.html ( diff )
/dom.html ( diff )
/edits.html ( diff )
/embedded-content-other.html ( diff )
/embedded-content.html ( diff )
/form-control-infrastructure.html ( diff )
/form-elements.html ( diff )
/forms.html ( diff )
/grouping-content.html ( diff )
/history.html ( diff )
/iframe-embed-object.html ( diff )
/image-maps.html ( diff )
/imagebitmap-and-animations.html ( diff )
/images.html ( diff )
/input.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/introduction.html ( diff )
/links.html ( diff )
/media.html ( diff )
/microdata.html ( diff )
/obsolete.html ( diff )
/offline.html ( diff )
/parsing.html ( diff )
/rendering.html ( diff )
/scripting.html ( diff )
/sections.html ( diff )
/semantics-other.html ( diff )
/semantics.html ( diff )
/server-sent-events.html ( diff )
/structured-data.html ( diff )
/syntax.html ( diff )
/system-state.html ( diff )
/tables.html ( diff )
/text-level-semantics.html ( diff )
/timers-and-user-prompts.html ( diff )
/web-messaging.html ( diff )
/web-sockets.html ( diff )
/webappapis.html ( diff )
/webstorage.html ( diff )
/window-object.html ( diff )
/workers.html ( diff )

@sideshowbarker
Copy link
Contributor

@sideshowbarker, would these changes work well for you once the syntax highlighting has been adjusted to account for the <code> elements?

In wattsi and the html-build sources, the code related to syntax highlighting is agnostic toward whether or not there’s a code element there. It all just passes any contents of the pre elements through to the highlighter script.

So there’s nothing special about those code elements as far as our build goes.

In other words, there are no build adjustments to be made on our side for this.

But whether the external highlighter script that we call needs to be adjusted to do something different because of those elements, I dunno.

@domenic
Copy link
Member

domenic commented Jun 20, 2018

Wow, thanks @Zirro!

@sideshowbarker, it seems like Zirro moved the class="lang" from the <pre> to the <code>, following the spec's suggestion. Since classes aren't semantic anyway, I'm not sure that move is really necessary, but it might be worthwhile to align with the spec if it isn't too much trouble for you...

In that case, we'd need to adjust wattsi, right? Hmm.

@tabatkins
Copy link
Collaborator

Nope, my highlighter is fine, it doesn't care one bit whether there's a code or not (or any other markup).

You'll just need to change wattsi to look for the class on the code to know what language to highlight as.

@sideshowbarker
Copy link
Contributor

it seems like Zirro moved the class="lang" from the <pre> to the <code>

That seems unnecessary and I strongly prefer this not be landed that way

following the spec's suggestion

I suggest we not follow that suggestion :) And further I think we should consider also changing the spec to not suggest that, because it’s not objectively a better way to do the markup by any measure

Since classes aren't semantic anyway, I'm not sure that move is really necessary

Right

but it might be worthwhile to align with the spec if it isn't too much trouble for you… In that case, we'd need to adjust wattsi, right?

Yeah, we’d need to adjust the wattsi code, and it’d be significantly more trouble to adjust it to look for a code first child of each pre and get the classname from that.

The cost of doing that would still be worthwhile if there were a compelling benefit. But it doesn’t seem like there is any benefit compelling enough to merit the cost

@domenic
Copy link
Member

domenic commented Jun 21, 2018

Makes sense. @Zirro, any objections to moving the class to the pre?

I guess one reason the spec might suggest this is that you could then use the same highlighter code for inline code samples, not just big pre blocks.

@Zirro Zirro force-pushed the code-element-classes branch 2 times, most recently from bfccca1 to 91eea3a Compare June 23, 2018 17:16
@Zirro Zirro changed the title Add <code> with language class inside every applicable <pre> element Add <code> element inside applicable <pre> elements Jun 23, 2018
@Zirro
Copy link
Contributor Author

Zirro commented Jun 23, 2018

@domenic That's fine with me. Done, and rebased on latest master.

Copy link
Contributor

@sideshowbarker sideshowbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t support adding code children to all the pre elements. It’s not necessary and in fact we have some evidence that it may actually measurably more harmful than not using code children in pre.

See @tabatkins comment at #2751 (comment), where he indicates that the CSS specs are very intentionally not using code children in their pre blocks because:

Probably for the same reason we just use pre in the CSS specs - <pre><code> makes the magical-newline-omitting of pre work even worse than pre by itself.

So I think the change we instead should be making here is to update the suggestions and examples in the spec to align with what most authors actually seem to be doing (and what the CSS specs are doing) — that is, to not suggest using code children as the first child of every single pre element that has an example of JavaScript or HTML or CSS or whatever in it.

I’ll create a PR with a patch for that.

@sideshowbarker
Copy link
Contributor

I added an explicit html class rather than having it be implicit as was the case before, since there are some non-HTML/CSS/JS/IDL <pre>s as well. Figured it might come in handy some day.

Yeah — that’s a great change. I really think we need that. Lacking that at this point, I’ve needed to make the syntax-highlighter code assume that any pre element without an explicit class should get highlighted as HTML. But as you note, in the spec there some pre elements without class attributes which aren’t HTML but instead just an example of a poem or something. So as far as the syntax highlighter goes, we really need an explicit class on the HTML pre elements so that we can highlight those as intended — while skipping highlighting for the ones that aren’t HTML or CSS or JavaScript.

@domenic domenic added the do not merge yet Pull request must not be merged per rationale in comment label Jun 25, 2018
@domenic
Copy link
Member

domenic commented Jun 25, 2018

I guess we should wait to merge this until the discussion in #3772 gets a bit further. In the meantime, let me put the commit message I drafted here for safe keeping:

Editorial: mark up code blocks with their language and <code>

Fixes #3753 (for JS) and also marks up the HTML examples with their own
class. Fixes #3764.

This will help with ongoing work to syntax-highlight all code in the
spec; see https://github.com/whatwg/html/issues/3753.

@sideshowbarker
Copy link
Contributor

Upon further consideration I’m dropping my objection to this change, and I have a patch ready to land that aligns with this PR, by adding support to Wattsi for sending code contents thru the highlighter pipeline in the case where the code element has a class value with idl, js, css, or html.

So @Zirro are you still able to roll back this branch to the original state of the patch at the time when you initially raised the PR? If so, then I think that would be the better way to land this. I mean specifically, with the class attribute on the code element rather than the pre element.

@Zirro
Copy link
Contributor Author

Zirro commented Jul 6, 2018

Okay, I've moved the classes back over to the code elements. It looks like some of the shared CSS will also need adjustment before this is merged, though.

@domenic domenic added do not merge yet Pull request must not be merged per rationale in comment and removed do not merge yet Pull request must not be merged per rationale in comment labels Jul 9, 2018
Copy link
Contributor

@sideshowbarker sideshowbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s an pre element at line 734 of the source on this branch, with id=intro-early-example. It contains an HTML markup example but <code class="html">…</code> hasn’t been added around its contents. Is that intentional?

@Zirro
Copy link
Contributor Author

Zirro commented Jul 11, 2018

Thanks for catching that. It looks like I missed pre elements with attributes other than class or with other classes than example. This seems to affect 31 elements - the one you found, in addition to pre elements with the bad class (edit: ...and a few others). I'll fix this over the weekend.

@sideshowbarker
Copy link
Contributor

Thanks for catching that. It looks like I missed pre elements with attributes other than class or with other classes than example. This seems to affect 31 elements - the one you found, in addition to pre elements with the bad class. I'll fix this over the weekend.

Cool. I think it may affect a few more than just those. Search for <pre>EXAMPLE in the source. There are 30 of those — mostly HTML and JS examples, with one CSS example.

And search for <pre lang="[^"]+">&lt; in the source and you should find 6 more cases of HTML examples.

@domenic domenic force-pushed the code-element-classes branch 2 times, most recently from 396eebf to 11c0989 Compare July 11, 2018 21:33
domenic added a commit to whatwg/whatwg.org that referenced this pull request Jul 11, 2018
The main purpose of this commit is to adapt to the new markup style in whatwg/html#3768. This also fixes minor inconsistencies and redundancies noted throughout the stylesheet for pre elements.
domenic added a commit to whatwg/whatwg.org that referenced this pull request Jul 11, 2018
The main purpose of this commit is to adapt to the new markup style in whatwg/html#3768. This also fixes minor inconsistencies and redundancies noted throughout the stylesheet for pre elements. And it removes special treatment of the "asn" class, which does not appear in any current specs.
domenic added a commit to whatwg/whatwg.org that referenced this pull request Jul 11, 2018
The main purpose of this commit is to adapt to the new markup style in whatwg/html#3768. This also fixes minor inconsistencies and redundancies noted throughout the stylesheet for pre elements. (Most notably, it will treat Bikeshed-produced IDL and CSS blocks the same as those in HTML.) And it removes special treatment of the "asn" class, which does not appear in any current specs.
@domenic domenic removed the do not merge yet Pull request must not be merged per rationale in comment label Jul 11, 2018
@sideshowbarker
Copy link
Contributor

I'm ready to merge this, and whatwg/html-build#162, once whatwg/whatwg.org#215 and whatwg/whatwg.org#214 get approvals. It'd also be good to get @sideshowbarker's final signoff.

Reviewed here and approved — and also approved the whatwg/whatwg.org PRs.

So I think we’re finally ready to merge all this.

@sideshowbarker
Copy link
Contributor

sideshowbarker commented Jul 18, 2018

So I meant to say in my previous comment that the Travis CI check is now green because I figured out and fixed the problem.

The cause was 100% my flub… I introduced a regression in wattsi’s behavior in whatwg/wattsi@b7d18be#diff-1922eb90770bdd34ac96cc9db339faebL1927.

It almost certainly isn’t caused by the HTML that wattsi generates, because as far as I can see, wattsi isn’t actually capable of generating HTML output without the doctype — it’s hardcoded

I was wrong about that. That had it hardcoded to call a function to conditionally write the doctype — but the assumption I wrote that with didn’t hold up for the case when writing the index-html files with syntax highlighting not enabled.

So in whatwg/wattsi@f3e6a62 I fixed (unregressed) it to (once again) unconditionally emit the doctype when writing HTML files.

domenic pushed a commit to whatwg/html-build that referenced this pull request Jul 23, 2018
This change adds https://github.com/tabatkins/highlighter as a submodule
and updates the build script to use the highlight server when running
wattsi, as documented at
tabatkins/highlighter#6 (comment)

Relies on whatwg/wattsi#63
Addresses #113
Relates to whatwg/html#3768
and whatwg/whatwg.org#215
@domenic domenic merged commit a6e5462 into whatwg:master Jul 23, 2018
domenic added a commit to whatwg/whatwg.org that referenced this pull request Jul 23, 2018
The main purpose of this commit is to adapt to the new markup style in whatwg/html#3768. This also fixes minor inconsistencies and redundancies noted throughout the stylesheet for pre elements. (Most notably, it will treat Bikeshed-produced IDL and CSS blocks the same as those in HTML.) And it removes special treatment of the "asn" class, which does not appear in any current specs.
sideshowbarker added a commit to whatwg/html-build that referenced this pull request Jul 24, 2018
This change adds https://github.com/tabatkins/highlighter as a submodule
and updates the build script to use the highlight server when running
wattsi, as documented at
tabatkins/highlighter#6 (comment)

This change reverts the revert made in ffe6f19. It fixes the problem
which made that revert necessary; the fix is to make the PYTHONPATH in
the local environment include the path to the Pygments copy in the
highlighter submodule.

Fixes #169

Relies on whatwg/wattsi#63
Addresses #113
Relates to whatwg/html#3768
and whatwg/whatwg.org#215
sideshowbarker added a commit to whatwg/html-build that referenced this pull request Jul 24, 2018
This change adds https://github.com/tabatkins/highlighter as a submodule
and updates the build script to use the highlight server when running
wattsi, as documented at
tabatkins/highlighter#6 (comment)

This change reverts the revert made in ffe6f19. It fixes the problem
which made that revert necessary; the fix is to make the PYTHONPATH in
the local environment include the path to the Pygments copy in the
highlighter submodule.

Fixes #169

Relies on whatwg/wattsi#63
Addresses #113
Relates to whatwg/html#3768
and whatwg/whatwg.org#215
sideshowbarker added a commit to whatwg/html-build that referenced this pull request Jul 24, 2018
This change adds https://github.com/tabatkins/highlighter as a submodule
and updates the build script to use the highlight server when running
wattsi, as documented at
tabatkins/highlighter#6 (comment)

This change reverts the revert made in ffe6f19. It fixes the problem
which made that revert necessary; the fix is to make the PYTHONPATH in
the local environment include the path to the Pygments copy in the
highlighter submodule.

Fixes #169

Relies on whatwg/wattsi#63
Addresses #113
Relates to whatwg/html#3768
and whatwg/whatwg.org#215
domenic pushed a commit to whatwg/html-build that referenced this pull request Jul 24, 2018
This change adds https://github.com/tabatkins/highlighter as a submodule
and updates the build script to use the highlight server when running
wattsi, as documented at
tabatkins/highlighter#6 (comment)

This change reverts the revert made in ffe6f19. It fixes the problem
which made that revert necessary; the fix is to make the PYTHONPATH in
the local environment include the path to the Pygments copy in the
highlighter submodule.

Fixes #169.

Relies on whatwg/wattsi#63.
Addresses #113.
Relates to whatwg/html#3768
and whatwg/whatwg.org#215.
domenic pushed a commit to whatwg/html-build that referenced this pull request Jul 24, 2018
This change adds https://github.com/tabatkins/highlighter as a submodule
and updates the build script to use the highlight server when running
wattsi, as documented at
tabatkins/highlighter#6 (comment)

This change reverts the revert made in ffe6f19. It fixes the problem
which made that revert necessary; the fix is to make the PYTHONPATH in
the local environment include the path to the Pygments copy in the
highlighter submodule.

Fixes #169.

Relies on whatwg/wattsi#63.
Addresses #113.
Relates to whatwg/html#3768
and whatwg/whatwg.org#215.
sideshowbarker added a commit to whatwg/wattsi that referenced this pull request Aug 20, 2018
The existing wattsi code for causing IDL blocks to be omitted from the
dev edition quit working when whatwg/html#3768
moved class=idl attributes off `pre` elements and instead onto to
`code` children of those elements,

So the first part of this change causes those `code class=idl` elements
to be dropped as expected. But as a result of that, the now-empty `pre`
element parents of those `code` elements are left behind. So the second
part of this change looks for those empty `pre` elements and drops them.

Fixes #84
sideshowbarker added a commit that referenced this pull request Aug 20, 2018
This change drops the `data-x=""` attribute+value that was included in
all `code` elements added in #3768
(a6e5462).

whatwg/wattsi#86 makes it unnecessary to to use
`data-x=""` for `code` elements that are children of `pre` elements.
sideshowbarker added a commit that referenced this pull request Aug 20, 2018
This change drops the `data-x=""` attribute+value that was included in
all `code` elements added in #3768
(a6e5462).

whatwg/wattsi#86 makes it unnecessary to to use
`data-x=""` for `code` elements that are children of `pre` elements.
sideshowbarker added a commit that referenced this pull request Aug 20, 2018
This change drops the `data-x=""` attribute+value that was included in
all `code` elements added in #3768
(a6e5462).

whatwg/wattsi#86 makes it unnecessary to use
`data-x=""` for `code` elements that are children of `pre` elements.
domenic pushed a commit to whatwg/wattsi that referenced this pull request Aug 21, 2018
The existing wattsi code for causing IDL blocks to be omitted from the
dev edition quit working when whatwg/html#3768
moved class=idl attributes off `pre` elements and instead onto to
`code` children of those elements.

So the first part of this change causes those `code class=idl` elements
to be dropped as expected. But as a result of that, the now-empty `pre`
element parents of those `code` elements are left behind. So the second
part of this change looks for those empty `pre` elements and drops them.

Fixes #84.
sideshowbarker added a commit to whatwg/wattsi that referenced this pull request Aug 21, 2018
The existing wattsi code for causing IDL blocks to be omitted from the
dev edition quit working when whatwg/html#3768
moved class=idl attributes off `pre` elements and instead onto to
`code` children of those elements,

So the first part of this change causes those `code class=idl` elements
to be dropped as expected. But as a result of that, the now-empty `pre`
element parents of those `code` elements are left behind. So the second
part of this change looks for those empty `pre` elements and drops them.

This change reverts the e1e3599 revert that was made because — as
initially implemented in c13e47b — stray `</pre>` end tags got left
behind for all `pre` elements that were omitted. This change corrects
that problem (it ensures the end tags get removed as expected).

Fixes #84
sideshowbarker added a commit to whatwg/wattsi that referenced this pull request Aug 22, 2018
The existing wattsi code for causing IDL blocks to be omitted from the
dev edition quit working when whatwg/html#3768
moved class=idl attributes off `pre` elements and instead onto to
`code` children of those elements,

So the first part of this change causes those `code class=idl` elements
to be dropped as expected. But as a result of that, the now-empty `pre`
element parents of those `code` elements are left behind. So the second
part of this change looks for those empty `pre` elements and drops them.

This change reverts the e1e3599 revert that was made because — as
initially implemented in c13e47b — stray `</pre>` end tags got left
behind for all `pre` elements that were omitted. This change corrects
that problem (it ensures the end tags get removed as expected).

Fixes #84
sideshowbarker added a commit to whatwg/wattsi that referenced this pull request Aug 22, 2018
The existing wattsi code for causing IDL blocks to be omitted from the
dev edition quit working when whatwg/html#3768
moved class=idl attributes off `pre` elements and instead onto to
`code` children of those elements,

So the first part of this change causes those `code class=idl` elements
to be dropped as expected. But as a result of that, the now-empty `pre`
element parents of those `code` elements are left behind. So the second
part of this change looks for those empty `pre` elements and drops them.

This change reverts the e1e3599 revert that was made because — as
initially implemented in c13e47b — stray `</pre>` end tags got left
behind for all `pre` elements that were omitted. This change corrects
that problem (it ensures the end tags get removed as expected).

Fixes #84
domenic pushed a commit to whatwg/wattsi that referenced this pull request Aug 22, 2018
The existing wattsi code for causing IDL blocks to be omitted from the dev edition quit working when whatwg/html#3768 moved class=idl attributes off `pre` elements and instead onto to `code` children of those elements,

So the first part of this change causes those `code class=idl` elements to be dropped as expected. But as a result of that, the now-empty `pre` element parents of those `code` elements are left behind. So the second part of this change looks for those empty `pre` elements and drops them.

This change reverts the e1e3599 revert that was made because — as initially implemented in c13e47b — stray `</pre>` end tags got left behind for all `pre` elements that were omitted. This change corrects that problem (it ensures the end tags get removed as expected).

Fixes #84.
sideshowbarker added a commit that referenced this pull request Sep 5, 2018
This change drops the `data-x=""` attribute+value that was included in
all `code` elements added in #3768
(a6e5462).

whatwg/wattsi#86 makes it unnecessary to use
`data-x=""` for `code` elements that are children of `pre` elements.
sideshowbarker added a commit that referenced this pull request Aug 22, 2020
This change drops the `data-x=""` attribute+value that was included in
all `code` elements added in #3768
(a6e5462).

whatwg/wattsi#86 makes it unnecessary to use
`data-x=""` for `code` elements that are children of `pre` elements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants