Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
fix: smarter typeit shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq committed Aug 10, 2019
1 parent a6bf8d8 commit c0237f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets/css/_common/_page/post.scss
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
}

.space {
white-space: pre-wrap;
white-space: pre;
}
}

Expand Down
6 changes: 4 additions & 2 deletions layouts/shortcodes/typeit.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
{{ $content = highlight $content (.Get "code") "encoding=utf-8" }}
{{ $content = replaceRE `<div class="highlight">\s*?<pre class="chroma">\s*?<code.*?>(?s)(.*?)</code>\s*?</pre>\s*?</div>` "$1" $content }}
{{ $content = trim $content "\n" }}
{{ $content = replaceRE `\n</span>` "</span><br />" $content | replaceRE `\n` "<br />" }}
{{ $content = replaceRE `>( +)<span` "><span class=space>$1</span><span" $content }}
{{ $content = replaceRE `\n</span>` "</span>\n" $content }}
{{ $content = replaceRE `(?m)^(<span.*?>)(.*?)\[(.*?)\]\((.*?)\)(.*?)(</span>)` "$1$2$6<a href=$4>$3</a>$1$5$6" $content }}
{{ $content = replaceRE `(?m)^( +)<span` "<span class=space>$1</span><span" $content }}
{{ $content = replaceRE `</span>( +)<span` "</span></span><span class=space>$1</span><span" $content | replaceRE `\n` "<br />" }}
<div id={{ printf "r%s" $id }} hidden=true>{{ $content | safeHTML }}</div>
<div class={{ .Get "class" | default "typeit-code" }} id={{ $id }}></div>
{{ else }}
Expand Down

0 comments on commit c0237f3

Please sign in to comment.