Skip to content

Commit

Permalink
fix(example-code-dom): fixes to api
Browse files Browse the repository at this point in the history
- remove public `enhance` method

- executable code should fallback to innerHTML not innerText
  • Loading branch information
zenflow committed Apr 5, 2018
1 parent cbaf3ca commit cac4d26
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 23 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# TODO
- work on compile
- test -dom
- greenkeeper /w support for monorepo
- lerna-semantic-release
Expand Down
13 changes: 0 additions & 13 deletions packages/example-code-dom/src/enhance.js

This file was deleted.

6 changes: 4 additions & 2 deletions packages/example-code-dom/src/enhanceAll.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { enhance } from './enhance'
import { enhanceElement } from './enhanceElement'

export function enhanceAll() {
enhance(document.querySelectorAll('code'))
for (const element of document.querySelectorAll('code')) {
enhanceElement(element)
}
}
9 changes: 3 additions & 6 deletions packages/example-code-dom/src/enhanceElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ export function enhanceElement(element) {
if (String(element.tagName).toUpperCase() !== 'CODE') {
throw new TypeError('element must be a <code> element')
}
if (
element.classList.contains('executable') &&
element.classList.contains('js')
) {
element.classList.contains('executable') &&
element.classList.contains('js') &&
executableJs(element)
}
}

function executableJs(element) {
const code = element.dataset.compiledCode || element.innerText
const code = element.dataset.compiledCode || element.innerHTML

element.prepend(
Object.assign(document.createElement('button'), {
Expand Down
1 change: 0 additions & 1 deletion packages/example-code-dom/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './enhanceElement'
export * from './enhance'
export * from './enhanceAll'

0 comments on commit cac4d26

Please sign in to comment.