.js-example
Add a class of
js-example
to any HTML element and the code for that element and all of its contents will be output as a code example immediately following the element.
content
content
data-ex-no-content
Add the
data-ex-no-content='true'
attribute to ignore the contents of the element and replace them with an ellipsis in the output code example.
content
content
data-ex-only
Add the
data-ex-only='true'
attribute to not render the element and only output the code example.
content
content
The above attributes can both be applied to not render the element AND ignore its contents.
content
content
You can specify the language you want to highlight as by setting the
data-ex-language
attribute. In this current implementation, accepted values are 'markup', 'css', 'scss', and 'js'.
When not doing markup examples, use a
<pre>
tag.
.c-card {
border: 1px solid dodgerblue;
border-radius: 0.2rem;
box-shadow: 0 1rem 1rem -1rem;
margin-bottom: 1rem;
}
.c-card__title {
background: dodgerblue;
color: white;
padding: 1rem;
margin: 0;
}
.c-card__content {
margin: 0;
padding: 1rem;
}
//line-break
.c-card {
border: 1px solid dodgerblue;
border-radius: 0.2rem;
box-shadow: 0 1rem 1rem -1rem;
margin-bottom: 1rem;
}
.c-card__title {
background: dodgerblue;
color: white;
padding: 1rem;
margin: 0;
}
.c-card__content {
margin: 0;
padding: 1rem;
}
//line-break
.c-card {
border: 1px solid dodgerblue;
border-radius: 0.2rem;
box-shadow: 0 1rem 1rem -1rem;
margin-bottom: 1rem;
&__title {
background: dodgerblue;
color: white;
padding: 1rem;
margin: 0;
}
&__content {
margin: 0;
padding: 1rem;
}
}
//line-break
.c-card {
border: 1px solid dodgerblue;
border-radius: 0.2rem;
box-shadow: 0 1rem 1rem -1rem;
margin-bottom: 1rem;
&__title {
background: dodgerblue;
color: white;
padding: 1rem;
margin: 0;
}
&__content {
margin: 0;
padding: 1rem;
}
}
//line-break
const examples = document.querySelectorAll('.js-example')
examples.forEach((ex) => {
ex.classList.remove('js-example')
})
//line-break
const examples = document.querySelectorAll('.js-example')
examples.forEach((ex) => {
ex.classList.remove('js-example')
})
Because I built this with pug, some of the preformatted text was a little weird. I countered this by adding
//line-break
in some of the code examples and then replacing each instance of that with
''
in the javascript. This seems to force a line break within the pre tags.