// ------------------------------------------ // 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, .04) 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 small { &:hover { &:after { opacity: 0; } } } &:after { content: ""; position: absolute; top: .5em; right: .5em; width: 1em; height: 1em; background: $passive-color; 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: visible; 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; } .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); } .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; left: 0; right: 0; padding: inherit 0; background: hsla(24, 20%, 50%,.08); background: -moz-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0)); background: -webkit-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0)); background: -o-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0)); background: linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0)); pointer-events: none; line-height: inherit; white-space: pre; } .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; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .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