Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Maybe fixes #207? Force upgrades before highlighting. #254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions app/elements/pages/page-guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ <h4>Guides</h4>
if (this.content.indexOf('<!doctype') >= 0) {
this._catalogGuideError();
} else { console.log( this.content);
this.$.content.innerHTML = this.content;
Polymer.dom(this.$.content).innerHTML = this.content;
this._decorateHeadings();
this._highlight();
this.scopeSubtree(this.$.content);
// this.scopeSubtree(this.$.content);
if (window.location.hash !== "") {
var el = Polymer.dom(this.$.content).querySelector(window.location.hash);
if (el) el.scrollIntoView();
Expand All @@ -167,25 +167,29 @@ <h4>Guides</h4>
},

_decorateHeadings: function() {
var h2s = this.$.content.querySelectorAll('h2');
var h2s = Polymer.dom(this.$.content).querySelectorAll('h2');
for (var i = 0; i < h2s.length; i++) {
var link = document.createElement('a');
link.className = "reference-link";
link.href = "#" + h2s[i].id;
var icon = document.createElement('iron-icon');
icon.icon = 'link';
link.appendChild(icon);
h2s[i].parentNode.insertBefore(link, h2s[i]);
var parent = Polymer.dom(h2s[i]).parentNode;
Polymer.dom(parent).insertBefore(link, h2s[i]);
}
},
_highlight: function() {
var els = this.$.content.querySelectorAll('pre code');
// Ensure that the prism-highligher element is upgraded
// before firing the highlight event. See: Polymer/polymer-element-catalog#207
Polymer.dom.flush();
var els = Polymer.dom(this.$.content).querySelectorAll('pre code');
for (var i = 0; i < els.length; i++) {
var code = els[i].textContent;
var event = this.fire('syntax-highlight', {code: code});
if (event.detail.code && !els[i].highlighted) {
els[i].highlighted = true;
els[i].innerHTML = event.detail.code;
Polymer.dom(els[i]).innerHTML = event.detail.code;
}
}
},
Expand All @@ -205,4 +209,4 @@ <h4>Guides</h4>
this.router.go('/404');
}
});
</script>
</script>