feat: language alias
This commit is contained in:
70
layouts/partials/language-alias.html
Normal file
70
layouts/partials/language-alias.html
Normal file
@ -0,0 +1,70 @@
|
||||
{{/*
|
||||
Convert the alias of the syntax language to the official name
|
||||
See: <https://github.com/rouge-ruby/rouge/wiki/List-of-supported-languages-and-lexers>
|
||||
*/}}
|
||||
|
||||
{{ $lang := .language | default "" }}
|
||||
|
||||
{{ $result := "" }}
|
||||
|
||||
{{ if eq $lang "actionscript" "as" "as3" }}
|
||||
{{ $result = "ActionScript" }}
|
||||
{{ else if eq $lang "applescript" }}
|
||||
{{ $result = "AppleScript" }}
|
||||
{{ else if eq $lang "brightscript" "bs" "brs" }}
|
||||
{{ $result = "BrightScript" }}
|
||||
{{ else if eq $lang "cfscript" "cfc" }}
|
||||
{{ $result = "CFScript" }}
|
||||
{{ else if eq $lang "coffeescript" "coffee" "coffee-script" }}
|
||||
{{ $result = "CoffeeScript" }}
|
||||
{{ else if eq $lang "cs" "csharp" }}
|
||||
{{ $result = "C#" }}
|
||||
{{ else if eq $lang "erl" }}
|
||||
{{ $result = "Erlang" }}
|
||||
{{ else if eq $lang "graphql" }}
|
||||
{{ $result = "GraphQL" }}
|
||||
{{ else if eq $lang "haskell" "hs" }}
|
||||
{{ $result = "Haskell" }}
|
||||
{{ else if eq $lang "javascript" "js" }}
|
||||
{{ $result = "JavaScript" }}
|
||||
{{ else if eq $lang "make" "mf" "gnumake" "bsdmake" }}
|
||||
{{ $result = "Makefile" }}
|
||||
{{ else if eq $lang "md" "mkd" }}
|
||||
{{ $result = "Markdown" }}
|
||||
{{ else if eq $lang "m" }}
|
||||
{{ $result = "Matlab" }}
|
||||
{{ else if eq $lang "objective_c" "objc" "obj-c" "obj_c" "objectivec" }}
|
||||
{{ $result = "Objective-C" }}
|
||||
{{ else if eq $lang "perl" "pl" }}
|
||||
{{ $result = "Perl" }}
|
||||
{{ else if eq $lang "php" "php3" "php4" "php5" }}
|
||||
{{ $result = "PHP" }}
|
||||
{{ else if eq $lang "py" }}
|
||||
{{ $result = "Python" }}
|
||||
{{ else if eq $lang "rb" }}
|
||||
{{ $result = "Ruby" }}
|
||||
{{ else if eq $lang "rs" "no_run" "ignore" "should_panic" }}
|
||||
{{ $result = "Rust" }}
|
||||
{{ else if eq $lang "bash" "zsh" "ksh" "sh" }}
|
||||
{{ $result = "Shell" }}
|
||||
{{ else if eq $lang "st" "squeak" }}
|
||||
{{ $result = "Smalltalk" }}
|
||||
{{ else if eq $lang "tex" }}
|
||||
{{ $result = "TeX" }}
|
||||
{{ else if eq $lang "latex" }}
|
||||
{{ $result = "LaTex" }}
|
||||
{{ else if eq $lang "ts" "typescript" }}
|
||||
{{ $result = "TypeScript" }}
|
||||
{{ else if eq $lang "vb" "visualbasic" }}
|
||||
{{ $result = "Visual Basic" }}
|
||||
{{ else if eq $lang "vue" "vuejs" }}
|
||||
{{ $result = "Vue.js" }}
|
||||
{{ else if eq $lang "yml" }}
|
||||
{{ $result = "YAML" }}
|
||||
{{ else if eq $lang "css" "html" "scss" "ssh" "toml" "xml" "yaml" "json" }}
|
||||
{{ $result = upper $lang }}
|
||||
{{ else }}
|
||||
{{ $result = title $lang }}
|
||||
{{ end }}
|
||||
|
||||
{{ return $result }}
|
@ -50,7 +50,22 @@
|
||||
{{ $content = replaceRE `<div class="CHIRPY-HIGHLIGHT-MARKER highlight"([^>]*?)file="([^"]*)"([^>]*?)>` `<div class="highlight"$1file="$2"$3><div class="code-header"> <span data-label-text="$2"><i class="far fa-file-code fa-fw"></i></span> <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div>` $content }}
|
||||
|
||||
<!-- Process remaining highlight divs that still have the marker (no file attribute) -->
|
||||
{{ $content = replaceRE `<div class="CHIRPY-HIGHLIGHT-MARKER highlight"([^>]*?)>([\s\S]*?)<code class="language-([^"]*)"` `<div class="highlight"$1><div class="code-header"> <span data-label-text="$3"><i class="fas fa-code fa-fw small"></i></span> <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div>$2<code class="language-$3"` $content }}
|
||||
{{ $content = replaceRE `<div class="CHIRPY-HIGHLIGHT-MARKER highlight"([^>]*?)>([\s\S]*?)<code class="language-([^"]*)"` `<div class="highlight"$1><div class="code-header"> <span data-label-text-language="$3"><i class="fas fa-code fa-fw small"></i></span> <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div>$2<code class="language-$3"` $content }}
|
||||
|
||||
<!-- Process language aliases in data-label-text -->
|
||||
{{ $pattern := `<span data-label-text-language="([^"]*)"` }}
|
||||
|
||||
<!-- 查找所有语言标签,逐个处理 -->
|
||||
{{ range findRE $pattern $content -1 }}
|
||||
{{ $langRaw := replaceRE $pattern "$1" . }}
|
||||
{{ $langNormalized := partial "language-alias.html" (dict "language" $langRaw) }}
|
||||
|
||||
{{ if ne $langNormalized "" }}
|
||||
{{ $replacement := printf `<span data-label-text="%s"` $langNormalized }}
|
||||
{{ $original := printf `<span data-label-text-language="%s"` $langRaw }}
|
||||
{{ $content = replace $content $original $replacement }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ $content | safeHTML }}
|
Reference in New Issue
Block a user