1+ // Code and syntax highlighting
2+ // stylelint-disable selector-no-qualifying-type, declaration-block-semicolon-newline-after,declaration-block-single-line-max-declarations, selector-no-type, selector-max-type, scss/comment-no-empty
3+
4+ // {% raw %}
5+
6+ // This instruction applies to all queues not within 'pre' or 'figure', avoiding 'code' generated by the highlight.
7+ :not (pre , figure ) {
8+ & > code {
9+ padding : 0.2em 0.15em ;
10+ font-weight : 400 ;
11+ background-color : $code-background-color ;
12+ border : $border $border-color ;
13+ border-radius : $border-radius ;
14+ }
15+ }
16+
17+ a :visited code {
18+ border-color : $border-color ;
19+ }
20+
21+ // the code may appear with 3 different types:
22+ // container \ case: default case, code with line number, code with html rendering
23+ // top level: div.highlighter-rouge, figure.highlight, figure.highlight
24+ // second level: div.highlight, div.table-wrapper, pre.highlight
25+ // third level: pre.highlight, td.code, absent
26+ // last level: code, pre, code (optionality)
27+ // highlighter level: span, span, span
28+ // the spacing are only in the second level for case 1, 3 and in the third level for case 2
29+ // in AsciiDoc, there is a parent container that contains optionally a title and the content.
30+
31+ // select top level container
32+ div .highlighter-rouge ,
33+ div .listingblock > div .content ,
34+ figure .highlight {
35+ margin-top : 0 ;
36+ margin-bottom : $sp-3 ;
37+ background-color : $code-background-color ;
38+ border-radius : $border-radius ;
39+ box-shadow : none ;
40+ -webkit-overflow-scrolling : touch ;
41+ position : relative ;
42+ padding : 10px ;
43+
44+ // copy button (or other button)
45+ // the button appear only when there is a hover on the code or focus on button
46+ > button {
47+ width : $sp-3 ;
48+ opacity : 0 ;
49+ position : absolute ;
50+ top : 0 ;
51+ right : 0 ;
52+ border : $sp-3 solid $code-background-color ;
53+ background-color : $code-background-color ;
54+ color : $body-text-color ;
55+ box-sizing : content-box ;
56+
57+ svg {
58+ fill : $body-text-color ;
59+ }
60+
61+ & :active {
62+ text-decoration : none ;
63+ outline : none ;
64+ opacity : 1 ;
65+ }
66+
67+ & :focus {
68+ opacity : 1 ;
69+ }
70+ }
71+
72+ // the button can be seen by doing a simple hover in the code, there is no need to go over the location of the button
73+ & :hover {
74+ > button {
75+ cursor : copy ;
76+ opacity : 1 ;
77+ }
78+ }
79+ }
80+
81+ // setting the spacing and scrollbar on the second level for the first case
82+ // remove all space on the second and third level
83+ // this is a mixin to accommodate for the slightly different structures generated via Markdown vs AsciiDoc
84+ @mixin scroll-and-spacing ($code-div , $pre-select ) {
85+ #{$code-div } {
86+ overflow-x : auto ;
87+ padding : $sp-3 ;
88+ margin : 0 ;
89+ border : 0 ;
90+ }
91+
92+ #{$pre-select } ,
93+ code {
94+ padding : 0 ;
95+ margin : 0 ;
96+ border : 0 ;
97+ }
98+ }
99+
100+ // for Markdown
101+ div .highlighter-rouge {
102+ @include scroll-and-spacing (" div.highlight" , " pre.highlight" );
103+ }
104+
105+ // for AsciiDoc. we also need to fix the margins for its parent container.
106+ div .listingblock {
107+ @include scroll-and-spacing (" div.content" , " div.content > pre" );
108+
109+ margin-top : 0 ;
110+ margin-bottom : $sp-3 ;
111+ }
112+
113+ // {% highlight LANG %}...{% endhighlight %},
114+ // {% highlight LANG linenos %}...{% endhighlight %}:
115+
116+ // setting the spacing and scrollbar on the second level for the thirt case
117+ // the css rule are apply only to the last code enviroment
118+ // setting the scroolbar
119+ figure .highlight {
120+ pre ,
121+ :not (pre ) > code {
122+ overflow-x : auto ;
123+
124+ margin : 0 ;
125+ border : 0 ;
126+ }
127+ }
128+
129+ // ```[LANG]...```, kramdown line_numbers = true,
130+ // {% highlight LANG linenos %}...{% endhighlight %}:
131+
132+ // setting the spacing and scrollbar on the thirt level for the second case
133+ .highlight .table-wrapper {
134+ padding : $sp-3 0 ;
135+ margin : 0 ;
136+ border : 0 ;
137+ box-shadow : none ;
138+
139+ td ,
140+ pre {
141+ @include fs-2 ;
142+
143+ min-width : 0 ;
144+ padding : 0 ;
145+ background-color : $code-background-color ;
146+ border : 0 ;
147+ }
148+
149+ td .gl {
150+ width : 1em ;
151+ padding-right : $sp-3 ;
152+ padding-left : $sp-3 ;
153+ }
154+
155+ pre {
156+ margin : 0 ;
157+ line-height : 2 ;
158+ }
159+ }
160+
161+ // Code examples: html render of a code
162+ .code-example ,
163+ .listingblock > .title {
164+ padding : $sp-3 ;
165+ margin-bottom : $sp-3 ;
166+ overflow : auto ;
167+ border : 1px solid $border-color ;
168+ border-radius : $border-radius ;
169+
170+ + .highlighter-rouge ,
171+ + .sectionbody .listingblock ,
172+ + .content ,
173+ + figure .highlight {
174+ position : relative ;
175+ margin-top : - $sp-4 ;
176+ border-right : 1px solid $border-color ;
177+ border-bottom : 1px solid $border-color ;
178+ border-left : 1px solid $border-color ;
179+ border-top-left-radius : 0 ;
180+ border-top-right-radius : 0 ;
181+ }
182+ }
183+
184+ // Mermaid diagram code blocks should be left unstyled.
185+ code .language-mermaid {
186+ padding : 0 ;
187+ background-color : inherit ;
188+ border : 0 ;
189+ }
190+
191+ // Override OneDarkJekyll Colors for Code Blocks
192+ .highlight ,
193+ pre .highlight {
194+ background : $code-background-color ; // Code Background
195+ // For Backwards Compatibility Before $code-linenumber-color was added
196+ @if variable-exists (code-linenumber-color ) {
197+ color : $code-linenumber-color ; // Code Line Numbers
198+ } @else {
199+ color : $body-text-color ; // Code Line Numbers
200+ }
201+ }
202+
203+ // Override OneDarkJekyll Colors for Code Blocks
204+ .highlight pre {
205+ background : $code-background-color ; // Code Background
206+ }
207+
208+ // {% endraw %}
0 commit comments