Skip to content

Commit fcf24bc

Browse files
dillonzqkhusika
authored andcommitted
fix(css): typeit shortcode and stype
Signed-off-by: Khusika Dhamar Gusti <khusikadhamar@gmail.com>
1 parent 0ea89a5 commit fcf24bc

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

assets/css/_page/_single.scss

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,6 @@
325325
}
326326
}
327327

328-
.typeit {
329-
.code {
330-
padding: .375rem;
331-
font-size: .875rem;
332-
font-family: $code-font-family;
333-
font-weight: bold;
334-
word-break: break-all;
335-
}
336-
}
337-
338328
.version {
339329
height: 1.25em;
340330
vertical-align: text-bottom;
@@ -345,6 +335,28 @@
345335
@import "../_partial/_single/comment";
346336
}
347337

338+
.typeit {
339+
.highlight {
340+
padding: .375rem;
341+
font-size: .875rem;
342+
font-family: $code-font-family;
343+
font-weight: bold;
344+
word-break: break-all;
345+
white-space: pre-wrap;
346+
}
347+
348+
font-family: var(--ti-cursor-font-family, $global-font-family);
349+
font-size: var(--ti-cursor-font-size, $global-font-size);
350+
font-weight: var(--ti-cursor-font-weight, $global-font-weight);
351+
line-height: var(--ti-cursor-line-height, $global-line-height);
352+
color: var(--ti-cursor-color, $global-font-secondary-color);
353+
margin-left: var(--ti-cursor-margin-left, 0);
354+
355+
[theme=dark] & {
356+
color: var(--ti-cursor-color, $global-font-secondary-color-dark);
357+
}
358+
}
359+
348360
.lg-toolbar .lg-icon::after {
349361
color: #999;
350362
}

layouts/_shortcodes/typeit.html

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
{{- $content := trim .Inner "\n" -}}
2-
{{- $classList := .Get "class" | slice -}}
2+
{{- $classList := slice -}}
3+
{{- with .Get "class" -}}
4+
{{- $classList = $classList | append . -}}
5+
{{- end -}}
36
{{- $tag := .Get "tag" | default "div" -}}
47

5-
{{- with .Get "code" -}}
8+
{{- if .Get "code" -}}
69
{{- /* highlight code content without line number */ -}}
7-
{{- $content = highlight $content . "linenos=false" -}}
10+
{{- $content = highlight $content (.Get "code") "lineNos=false, noClasses=false" -}}
811
{{- /* delete outer label */ -}}
9-
{{- $content = replaceRE `<div class="highlight"><pre class="chroma"><code[^<>]*>(?s)(.*)</code></pre></div>` "$1" $content -}}
10-
{{- /* parsing markdown links */ -}}
11-
{{- $content = replaceRE `(<span[^<>]*>)([^<>]*)\[([^<>]+)\]\(([^<>]+)\)([^<>]*)(</span>)` "$1$2$6<a href=$4>$3</a>$1$5$6" $content -}}
12-
{{- /* replace " " to "&nbsp;" and replace "\n" to "<br />" */ -}}
13-
{{- $content = replaceRE ` ` "&nbsp;" $content | replaceRE `(<\w+)&nbsp;` "$1 " | replaceRE `\n` "<br />" -}}
14-
{{- /* fix "<br />" location error which is a bug of Typeit HTML parser */ -}}
15-
{{- $content = replaceRE `<br /></span>` "</span><br />" $content -}}
12+
{{- $content = replaceRE `.*<code[^<>]*>(?s)(.*)</code>.*` "$1" $content -}}
13+
{{- if .Get "code-link" -}}
14+
{{- /* parsing code links */ -}}
15+
{{- $content = replaceRE `(<span[^<>]*>)([^<>]*)\[([^<>]+)\]\(([^<>]+)\)([^<>]*)(</span>)` "$1$2$6<a href=\"$4\">$3</a>$1$5$6" $content -}}
16+
{{- end -}}
17+
{{- /* split multiline string */ -}}
18+
{{- $content = split $content "\n" -}}
1619
{{- $classList = $classList | append "highlight" -}}
1720
{{- else -}}
1821
{{- $content = $content | .Page.RenderString -}}
@@ -26,6 +29,11 @@
2629
{{- $group = $group | default slice | append $id -}}
2730
{{- dict $key $group | merge $typeitMap | .Page.Scratch.SetInMap "this" "typeitMap" -}}
2831

32+
{{- $attrs := printf `id="%v"` $id -}}
33+
{{- with $classList -}}
34+
{{- $attrs = delimit $classList " " | printf `%v class="%v"` $attrs -}}
35+
{{- end -}}
36+
2937
<div class="typeit">
30-
{{- printf `<%v id="%v" class="%v"></%v>` $tag $id (delimit $classList " ") $tag | safeHTML -}}
31-
</div>
38+
{{- printf `<%v %v></%v>` $tag $attrs $tag | safeHTML -}}
39+
</div>

0 commit comments

Comments
 (0)