Skip to content

Commit 810cc98

Browse files
committed
Tweak the comment a bit, and optimize the whitespace trimming.
1 parent 27408d1 commit 810cc98

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

base.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ p:first-child, ul, ol {margin-top: 0}
7474
del {text-decoration: line-through; color: #8B0040;}
7575
ins {text-decoration: underline; color: #005100;}
7676

77-
pre {
78-
margin-left: 1em;
77+
pre {
78+
margin-left: 1em;
7979
margin-top: .5em;
8080
margin-bottom: .5em;
8181
}

codeblock.html

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11

22
<!-- Code Block
3-
Code block elements are used to wrap program fragments in C++. The
4-
element is partially formatted for improved rendering by removing
5-
leading and trailing whitespace that is generally annoying in
6-
<pre> blocks.
3+
Code block elements are used to wrap program fragments in C++.
74
8-
Also, without this, <pre> block was being rendered outside of examples.
9-
That's not desirable.
5+
For improved source clarity, this element removes leading and trailing
6+
whitespace from its contents.
7+
8+
This element also prevents the HTML parser from ending a surrounding <p> tag
9+
when it sees the opening <pre>.
1010
1111
TODO: This could call into a syntax highlighter that styles
1212
comments correctly.
1313
-->
1414
<polymer-element name="cxx-codeblock">
1515
<template>
16+
<style>
17+
:host { display: block; }
18+
</style>
1619
<pre><code><content></content></code></pre>
1720
</template>
1821
<script>
1922
Polymer('cxx-codeblock', {
20-
applyAuthorStyles: true,
21-
ready: function() {
22-
this.innerHTML = this.innerHTML.trim();
23+
attached: function() {
24+
if (this.firstChild.nodeType == Node.TEXT_NODE)
25+
this.firstChild.nodeValue = this.firstChild.nodeValue.replace(/^\s+/, '');
26+
if (this.lastChild.nodeType == Node.TEXT_NODE)
27+
this.lastChild.nodeValue = this.lastChild.nodeValue.replace(/\s+$/, '');
2328
}
2429
});
2530
</script>

0 commit comments

Comments
 (0)