Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
feat(nuxt-styleguide-renderer-default): add markup highlighting
Browse files Browse the repository at this point in the history
by using prism.js for code blocks.

fixes #15
  • Loading branch information
Markus Siering committed Nov 8, 2018
1 parent c815531 commit ba8daef
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
27 changes: 27 additions & 0 deletions packages/nuxt-styleguide-renderer-default/component/CodeBlock.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<Prism :language="language">
<slot />
</Prism>
</template>

<style>
@import 'prismjs/themes/prism.css';
</style>

<script>
import 'prismjs'
import Prism from 'vue-prism-component'
export default {
name: 'CodeBlock',
components: {
Prism,
},
props: {
language: {
type: String,
default: 'html',
},
},
}
</script>
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<template>
<div><pre><code>{{ code }}</code></pre></div>
<div><code-block language="html">{{ code }}</code-block></div>
</template>

<style>
</style>

<script>
import pretty from 'pretty'
import CodeBlock from './CodeBlock.vue'
export default {
components: {
CodeBlock,
},
props: {
comp: {
type: Object,
Expand Down
12 changes: 10 additions & 2 deletions packages/nuxt-styleguide-renderer-default/component/Component.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<sg-frame>
<h1>{{ name }}</h1>
<pre><code>import {{ importName }} from '{{ importPath }}';</code></pre>
<code-block language="js">import {{ importName }} from '{{ importPath }}';</code-block>
<h2>Demo:</h2>
<div
v-for="(state) in states"
Expand Down Expand Up @@ -106,13 +106,21 @@

<script>
import CodeView from './CodeView.vue'
import CodeBlock from './CodeBlock.vue'
import SgComponentDemo from './ComponentDemo.vue'
import SgStyleguideNav from '../nav/nav.vue'
import SgFrame from '../frame.vue'
import SgTags from './Tags.vue'
export default {
components: { SgStyleguideNav, SgTags, SgFrame, SgComponentDemo, CodeView },
components: {
SgStyleguideNav,
SgTags,
SgFrame,
SgComponentDemo,
CodeView,
CodeBlock,
},
props: {
Comp: { type: Object, default: null },
name: { type: String, default: null },
Expand Down
4 changes: 3 additions & 1 deletion packages/nuxt-styleguide-renderer-default/designTokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h1>{{ name }}</h1>
<div v-html="description" />
<sg-tags :tags="tags" />
<pre><code>@import "{{ importPath }}";</code></pre>
<code-block language="css">@import "{{ importPath }}";</code-block>

<sg-color-demo
v-if="colors.length"
Expand All @@ -29,6 +29,7 @@
</template>

<script>
import CodeBlock from './component/CodeBlock.vue'
import SgTags from './component/Tags.vue'
import SgColorDemo from './component/ColorDemo.vue'
import SgDefaultDtDemo from './component/SgDefaultDtDemo.vue'
Expand All @@ -39,6 +40,7 @@ import SgFrame from './frame.vue'
export default {
components: {
CodeBlock,
SgTags,
SgFrame,
SgColorDemo,
Expand Down
3 changes: 2 additions & 1 deletion packages/nuxt-styleguide-renderer-default/frame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ code {
background: $grey;
border-radius: 1px;
padding: 0 0.3em;
font-size: 1.1em;
font-size: 0.85em;
}
.hamburger {
Expand Down Expand Up @@ -191,6 +191,7 @@ code {
background: black;
color: white;
transform: translateY(-100vh);
z-index: 42;
}
}
</style>
6 changes: 4 additions & 2 deletions packages/nuxt-styleguide-renderer-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"dependencies": {
"node-sass": "^4.9.0",
"pretty": "^2.0.0",
"sass-loader": "^7.0.1"
"prismjs": "^1.15.0",
"sass-loader": "^7.0.1",
"vue-prism-component": "^1.1.1"
}
}
}

0 comments on commit ba8daef

Please sign in to comment.