Skip to content

Syntax highlighting #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 19, 2020
145 changes: 83 additions & 62 deletions src/.vuepress/theme/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
<header class="navbar">
<SidebarButton @toggle-sidebar="$emit('toggle-sidebar')" />

<RouterLink
:to="$localePath"
class="home-link"
>
<RouterLink :to="$localePath" class="home-link">
<img
v-if="$site.themeConfig.logo"
class="logo"
:src="$withBase($site.themeConfig.logo)"
:alt="$siteTitle"
>
/>
<span
v-if="$siteTitle"
ref="siteName"
Expand All @@ -26,11 +23,10 @@
'max-width': linksWrapMaxWidth + 'px'
} : {}"
>
<AlgoliaSearchBox
v-if="isAlgoliaSearch"
:options="algolia"
<AlgoliaSearchBox v-if="isAlgoliaSearch" :options="algolia" />
<SearchBox
v-else-if="$site.themeConfig.search !== false && $page.frontmatter.search !== false"
/>
<SearchBox v-else-if="$site.themeConfig.search !== false && $page.frontmatter.search !== false" />
<NavLinks class="can-hide" />
</div>
</header>
Expand All @@ -52,39 +48,45 @@ export default {
AlgoliaSearchBox
},

data () {
data() {
return {
linksWrapMaxWidth: null
}
},

computed: {
algolia () {
return this.$themeLocaleConfig.algolia || this.$site.themeConfig.algolia || {}
algolia() {
return (
this.$themeLocaleConfig.algolia || this.$site.themeConfig.algolia || {}
)
},

isAlgoliaSearch () {
isAlgoliaSearch() {
return this.algolia && this.algolia.apiKey && this.algolia.indexName
}
},

mounted () {
mounted() {
const MOBILE_DESKTOP_BREAKPOINT = 719 // refer to config.styl
const NAVBAR_VERTICAL_PADDING = parseInt(css(this.$el, 'paddingLeft')) + parseInt(css(this.$el, 'paddingRight'))
const NAVBAR_VERTICAL_PADDING =
parseInt(css(this.$el, 'paddingLeft')) +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseInt(..., 10) ?

parseInt(css(this.$el, 'paddingRight'))
const handleLinksWrapWidth = () => {
if (document.documentElement.clientWidth < MOBILE_DESKTOP_BREAKPOINT) {
this.linksWrapMaxWidth = null
} else {
this.linksWrapMaxWidth = this.$el.offsetWidth - NAVBAR_VERTICAL_PADDING
- (this.$refs.siteName && this.$refs.siteName.offsetWidth || 0)
this.linksWrapMaxWidth =
this.$el.offsetWidth -
NAVBAR_VERTICAL_PADDING -
((this.$refs.siteName && this.$refs.siteName.offsetWidth) || 0)
}
}
handleLinksWrapWidth()
window.addEventListener('resize', handleLinksWrapWidth, false)
}
}

function css (el, property) {
function css(el, property) {
// NOTE: Known bug, will return 'auto' if style value is 'auto'
const win = el.ownerDocument.defaultView
// null means not to return pseudo styles
Expand All @@ -93,48 +95,67 @@ function css (el, property) {
</script>

<style lang="stylus">
$navbar-vertical-padding = 0.7rem
$navbar-horizontal-padding = 1.5rem

.navbar
padding $navbar-vertical-padding $navbar-horizontal-padding
line-height $navbarHeight - 1.4rem
a, span, img
display inline-block
.logo
height $navbarHeight - 1.4rem
min-width $navbarHeight - 1.4rem
margin-right 0.5rem
vertical-align top
.site-name
font-size 1.3rem
font-weight 600
color $textColor
position relative
.links
padding-left 1.5rem
box-sizing border-box
background-color white
white-space nowrap
font-size 0.9rem
position absolute
right $navbar-horizontal-padding
top $navbar-vertical-padding
display flex
.search-box
flex: 0 0 auto
vertical-align top

@media (max-width: $MQMobile)
.navbar
padding-left 4rem
.can-hide
display none
.links
padding-left 1.5rem
.site-name
width calc(100vw - 9.4rem)
overflow hidden
white-space nowrap
text-overflow ellipsis
$navbar-vertical-padding = 0.7rem;
$navbar-horizontal-padding = 1.5rem;

.navbar {
padding: $navbar-vertical-padding $navbar-horizontal-padding;
line-height: $navbarHeight - 1.4rem;

a, span, img {
display: inline-block;
}

.logo {
height: $navbarHeight - 1.4rem;
min-width: $navbarHeight - 1.4rem;
margin-right: 0.5rem;
vertical-align: top;
}

.site-name {
font-size: 1.3rem;
font-weight: 500;
color: $textColor;
position: relative;
}

.links {
padding-left: 1.5rem;
box-sizing: border-box;
background-color: white;
white-space: nowrap;
font-size: 0.9rem;
position: absolute;
right: $navbar-horizontal-padding;
top: $navbar-vertical-padding;
display: flex;

.search-box {
flex: 0 0 auto;
vertical-align: top;
}
}
}

@media (max-width: $MQMobile) {
.navbar {
padding-left: 4rem;

.can-hide {
display: none;
}

.links {
padding-left: 1.5rem;
}

.site-name {
width: calc(100vw - 9.4rem);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
}
</style>
45 changes: 38 additions & 7 deletions src/.vuepress/theme/styles/code.styl
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@
line-height 1.4
padding 1.25rem 1.5rem
margin 0.85rem 0
background-color $codeBgColor
background-color #f6f6f6
border-radius 6px
overflow auto
code
color #fff
color #3a385d
padding 0
background-color transparent
border-radius 0

div[class*="language-"]
position relative
background-color $codeBgColor
background-color #f6f6f6
border-radius 6px
.highlight-lines
background-color #f6f6f6
color #3a385d
user-select none
padding-top 1.3rem
position absolute
Expand All @@ -39,7 +41,7 @@ div[class*="language-"]
width 100%
line-height 1.4
.highlighted
background-color rgba(0, 0, 0, 66%)
background-color rgba(255, 255, 255, 90%)
pre, pre[class*="language-"]
background transparent
position relative
Expand All @@ -50,7 +52,7 @@ div[class*="language-"]
top 0.8em
right 1em
font-size 0.75rem
color rgba(255, 255, 255, 0.4)
color rgb(0 0 6 / 0.5)
&:not(.line-numbers-mode)
.line-numbers-wrapper
display none
Expand All @@ -66,7 +68,7 @@ div[class*="language-"]
display block
width $lineNumbersWrapperWidth
height 100%
background-color rgba(0, 0, 0, 66%)
background-color rgba(255, 255, 255, 95%)
pre
padding-left $lineNumbersWrapperWidth + 1 rem
vertical-align middle
Expand Down Expand Up @@ -138,4 +140,33 @@ div.reactivecontent
width 1000px
margin-left -100px

@import '~prismjs/themes/prism-tomorrow.css'
// @import '~prismjs/themes/prism-tomorrow.css'

.token.punctuation
color #a8a9cc

.token.tag, .token.attr-name, .token.namespace, .token.deleted
color #b2085f

.token.string, .token.char, .token.attr-value, .token.regex, .token.variable
color #0a7a34

.token.selector, .token.important, .token.atrule, .token.keyword, .token.builtin
color #b92dbc

.token.boolean, .token.number, .token.function
color #c25205

.token.property, .token.class-name, .token.constant, .token.symbol
color #717c11

.token.operator, .token.entity, .token.url
color #0b7e7d

.token.comment, .token.block-comment, .token.prolog, .token.doctype, .token.cdata
color #848486

div[class*=language-].line-numbers-mode .line-numbers-wrapper, div[class*=language-].line-numbers-mode:after
background-color #f6f6f6
color #c4c4c6
border-right 1px solid #e7e6e6
4 changes: 2 additions & 2 deletions src/.vuepress/theme/styles/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ul, ol
padding-left 1.2em

strong
font-weight 600
font-weight 500

h1, h2, h3, h4, h5, h6
font-weight 500
Expand Down Expand Up @@ -135,7 +135,7 @@ h1, h2, h3, h4, h5, h6

h1
font-size 2.2rem
font-weight 600
font-weight 500

h2
font-size 1.65rem
Expand Down