Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
scoop up the right pre elements' text content (#6194)
Browse files Browse the repository at this point in the history
Fixes #6161
  • Loading branch information
peterbe authored and Schalk Neethling committed Dec 6, 2019
1 parent 11e9820 commit 6d51409
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions kuma/javascript/src/live-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,14 @@ export function addLiveExampleButtons(rootElement) {
// direct siblings and also descendants of direct siblings
// (because sometimes some of the source code is tucked inside
// a hidden div).
let html = rootElement.querySelector(
`#${sectid} ~ pre[class*=html], #${sectid} ~ * pre[class*=html]`
);
let css = rootElement.querySelector(
`#${sectid} ~ pre[class*=css], #${sectid} ~ * pre[class*=css]`
);
let js = rootElement.querySelector(
`#${sectid} ~ pre[class*=js], #${sectid} ~ * pre[class*=js]`
);
let html = section.querySelectorAll('pre[class*=html]');
let css = section.querySelectorAll('pre[class*=css]');
let js = section.querySelectorAll('pre[class*=js]');

// Now get the source code out of those pre elements
let htmlCode = html ? html.textContent : '';
let jsCode = js ? js.textContent : '';
let cssCode = css ? css.textContent : '';
let htmlCode = [...html].map(p => p.textContent).join('');
let jsCode = [...js].map(p => p.textContent).join('');
let cssCode = [...css].map(p => p.textContent).join('');

// If we found any source code, then add buttons
if (htmlCode || cssCode || jsCode) {
Expand Down

0 comments on commit 6d51409

Please sign in to comment.