Skip to content

Commit

Permalink
fix: update default style for code block
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Mar 27, 2019
1 parent 06b12d1 commit cdc2ed4
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 40 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`main 1`] = `"<div class=\\"saber-highlight\\" v-pre=\\"\\" data-lang=\\"vue\\"><pre class=\\"saber-highlight-code language-vue\\"><code class=\\"language-vue\\">&lt;div&gt;hehe&lt;/div&gt;</code></pre></div>"`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const path = require('path')

const RE = /\s*{([^}]+)}/

const parseOptions = str => {
Expand All @@ -19,17 +17,9 @@ module.exports = (md, { highlightedLineBackground } = {}) => {
`<div${preWrapperAttrs}>${codeMask}<pre${preAttrs}><code${codeAttrs}>${code.trim()}</code></pre></div>`

md.renderer.rules.fence = (...args) => {
const [tokens, idx, options, env, self] = args
const [tokens, idx, options, , self] = args
const token = tokens[idx]

const fenceOptionsCSS = `<style src="${path.join(
__dirname,
'fence-options.css'
)}"></style>`
if (!env.hoistedTags.includes(fenceOptionsCSS)) {
env.hoistedTags.push(fenceOptionsCSS)
}

const langName = token.info.replace(RE, '').trim()

const code = options.highlight
Expand All @@ -41,14 +31,14 @@ module.exports = (md, { highlightedLineBackground } = {}) => {
const langClass = langName ? `language-${langName}` : ''
const preAttrs = renderAttrs([
...(token.attrs || []),
['class', ['code-block', langClass].filter(Boolean).join(' ')]
['class', ['saber-highlight-code', langClass].filter(Boolean).join(' ')]
])
const codeAttrs = renderAttrs([
...(token.attrs || []),
['class', langClass]
])
const preWrapperAttrs = renderAttrs([
['class', 'code-wrapper'],
['class', 'saber-highlight'],
['v-pre', ''],
['data-lang', langName]
])
Expand All @@ -66,7 +56,7 @@ module.exports = (md, { highlightedLineBackground } = {}) => {
token.info = langName

const codeMask =
`<div class="code-mask${langClass ? ` ${langClass}` : ''}">` +
`<div class="saber-highlight-mask${langClass ? ` ${langClass}` : ''}">` +
md.utils
.escapeHtml(token.content)
.split('\n')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Markdown = require('saber-markdown')
const fenceOptionsPlugin = require('./fence-options-plugin')
const fenceOptionsPlugin = require('./highlight-plugin')

test('main', () => {
const md = new Markdown()
Expand Down
1 change: 1 addition & 0 deletions packages/saber/lib/renderer/app/create-app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './polyfills'
import './css/saber-highlight.css'
import { join, dirname } from 'path'
import Vue from 'vue'
import routes from '#cache/routes'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
.code-wrapper {
.saber-highlight {
position: relative;
margin: 2rem 0;
background-color: #282c34;
border-radius: 4px;
overflow: hidden;
background: #fdfaf6;
box-shadow: inset 0 0 0 1px #faede5;
border-radius: 4px;
}

.code-line.highlighted {
background-color: #000;
}

.code-wrapper:before {
.saber-highlight:before {
content: attr(data-lang);
position: absolute;
right: 10px;
top: 5px;
font-size: .75rem;
color: rgba(255, 255, 255, 0.4);
color: #cacaca;
}

.code-mask, .code-block {
.saber-highlight-mask, .saber-highlight-code {
line-height: 1.5;
background-color: transparent !important;
text-shadow: none !important;
Expand All @@ -29,7 +26,7 @@
white-space: pre;
}

.code-mask {
.saber-highlight-mask {
position: absolute;
top: 0;
bottom: 0;
Expand All @@ -41,7 +38,12 @@
padding-right: 0 !important;
}

.code-block {
.saber-highlight-code {
position: relative;
z-index: 2;
}

.code-line.highlighted {
background: #faede5;
box-shadow: inset 2px 0 0 0 #f1beb6;
}
10 changes: 2 additions & 8 deletions website/pages/docs/markdown-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,11 @@ try {
}
```
You also need to include a Prism theme in your app to make it display properly, we recommend `prism-tomorrow.css`:
You also need to include a Prism theme in your app to make it display properly, we recommend `prism.css`:
```js
// saber-browser.js
import 'prismjs/themes/prism-tomorrow.css'
```
Or in a specific layout component:
```vue
<style src="prismjs/themes/prism-tomorrow.css"></style>
import 'prismjs/themes/prism.css'
```
### Line Highlighting in Code Blocks
Expand Down
1 change: 0 additions & 1 deletion website/src/layouts/docs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ export default {
}
</script>

<style src="prismjs/themes/prism-tomorrow.css"></style>
<style scoped src="../css/page.css"></style>
1 change: 0 additions & 1 deletion website/src/layouts/tutorial.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ export default {
}
</script>

<style src="prismjs/themes/prism-tomorrow.css"></style>
<style scoped src="../css/page.css"></style>
1 change: 1 addition & 0 deletions website/src/saber-browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'nprogress/nprogress.css'
import 'prismjs/themes/prism.css'
import './css/global.css'

export default ({ router, rootOptions }) => {
Expand Down

0 comments on commit cdc2ed4

Please sign in to comment.