// ------------------------------------------ // CODE HIGHLIGHTER // Based on Prism.js - Coy Theme // @origin Tim Shedor // https://github.com/tshedor/workshop-wp-theme // ------------------------------------------------------- $code-font-family : "Consolas", Courier, "monospace" !default; $code-theme : light !default; // dark or light $code-margin-bottom : 1.5em !default; @if $include-typography { $code-margin-bottom : $p-margin-bottom; } $code-markup-color : $blue-color; $code-js-color : #ff8f00; // orange $code-css-color : $green-color; $code-ruby-color : $red-color; $code-php-color : #626293; // purple $code-sass-color : #c6538c; // pink $code-python-color : #376a94; // dark-blue // Add decoration to the code-block @mixin code-decor($color) { &:after { background: $color; } code { @include background-image(linear-gradient(transparent 50%, rgba($color, .03) 50% ) ); } .line-highlight:before, .line-highlight[data-end]:after { background: $color; } } // Add styling to code-block @mixin code-block($theme: $code-theme) { @if $code-theme == light { @include contrasted(#fff); } @else if $code-theme == dark { @include contrasted(#252525); } } @if $include-code { /* ---------------------- EDGE CODE Highlighter ---------------------- */ // Reset code, kbd, samp { display: inline-block; &, pre { font-size: 1em; font-family: $code-font-family; } } pre, code { @include code-block(); white-space: pre; word-spacing: normal; @include css3(tab-size, 2, $webkit:false, $moz:true, $ms:false, $o:true); @include css3(hyphens, none, $webkit:true, $moz:true, $ms:true, $o:false); } pre { position: relative; overflow: auto; padding: 0; margin-bottom: $code-margin-bottom; max-height: 30em; @include code-decor($passive-color); @include box-shadow(-1px 0px 0px 0px #ddd, 0px 0px 0px 1px #ddd); @include below(small) { &:hover { &:after { opacity: 0; } } } &:after { content: ""; position: absolute; top: .5em; right: .5em; width: 1em; height: 1em; background: $passive-color; @if $code-theme == dark { opacity: .5; } @else { opacity: .2; } padding: em(5px 10px); font-family: $code-font-family; color: white; text-transform: uppercase; @include transition($g-transition); } &[data-lang="markup"] { @include code-decor($code-markup-color); } &[data-lang="css"] { @include code-decor($code-css-color); } &[data-lang="javascript"] { @include code-decor($code-js-color); } &[data-lang="ruby"] { @include code-decor($code-ruby-color); } &[data-lang="python"] { @include code-decor($code-python-color); } > code { display: block; overflow: auto; background-size: 3em 3em; background-origin: content-box; padding-left: 0.5em; } } :not(pre) { > code { @include code-block(); } } /* Inline code */ :not(pre) > code[class*="language-"] { display: inline-block; overflow: hidden; position:relative; padding: 0; color: #c92c2c; vertical-align: bottom; } @if $code-theme == light { .token.comment, .token.block-comment, .token.prolog, .token.doctype, .token.cdata { color: #7D8B99; } .token.punctuation { color: #5F6364; } .token.property, .token.tag, .token.boolean, .token.number, .token.function-name, .token.constant, .token.symbol { color: #c92c2c; } .token.selector, .token.attr-name, .token.string, .token.function, .token.builtin { color: #2f9c0a; } .token.operator, .token.entity, .token.url, .token.variable { color: #a67f59; background: rgba(255, 255, 255, 0.5); } .token.atrule, .token.attr-value, .token.keyword, .token.class-name { color: #1990b8; } .token.regex, .token.important { color: #e90; } [data-lang="css"] .token.string, .style .token.string { color: #a67f59; background: rgba(255, 255, 255, 0.5); } } @else if $code-theme == dark { .token.property, .token.tag, .token.constant, .token.symbol { color: #f92672; } .token.boolean, .token.number{ color: #ae81ff; } .token.selector, .token.attr-name, .token.string, .token.builtin { color: #a6e22e; } .token.operator, .token.entity, .token.url, .language-css .token.string, .style .token.string, .token.variable { color: #f8f8f2; } .token.atrule, .token.attr-value { color: #e6db74; } .token.keyword{ color: #66d9ef; } .token.regex, .token.important { color: #fd971f; } } .token.important { font-weight: normal; } .token.entity { cursor: help; } .namespace { opacity: .7; } /* Plugin styles */ .token.tab:not(:empty):before, .token.cr:before, .token.lf:before { color: #e0d7d1; } /* Line Highlighter */ .line-highlight { position: absolute; right: 0; left: 0; pointer-events: none; line-height: inherit; white-space: pre; @if $code-theme == dark { @include background-image(linear-gradient(left, rgba(#e2e2e2, .1) 70%, rgba(#e2e2e2, 0) ) ); } @else { @include background-image(linear-gradient(left, rgba(#8c8c8c, .1) 70%, rgba(#8c8c8c, 0) ) ); } } .line-highlight:before, .line-highlight[data-end]:after { content: attr(data-start); position: absolute; z-index: 2; top: .4em; left: .5em; min-width: 1em; padding: 0 .5em; color: hsl(24, 20%, 95%); font: bold 65%/1.5 sans-serif; text-align: center; vertical-align: .3em; border-radius: 999px; text-shadow: none; box-shadow: 0 1px white; } .line-highlight[data-end]:after { content: attr(data-end); top: auto; bottom: .4em; } /* Line numbers */ pre.line-numbers { position: relative; counter-reset: linenumber; } pre.line-numbers > code { position: relative; padding-left: 2.5em; } .line-numbers .line-numbers-rows { position: absolute; pointer-events: none; top: 0; font-size: 100%; left: .5em; letter-spacing: -1px; @include disable-user-select(); } .line-numbers-rows > span { pointer-events: none; display: block; counter-increment: linenumber; } .line-numbers-rows > span:before { content: counter(linenumber); color: #ddd; display: block; padding-right: 0.8em; text-align: right; } } // $include-code