Implement a ruby shortcode, with ruby/t to make <rt> elements
This commit is contained in:
parent
8c60dbf128
commit
6d0fd81a7b
2 changed files with 32 additions and 0 deletions
1
layouts/shortcodes/ruby.html
Normal file
1
layouts/shortcodes/ruby.html
Normal file
|
@ -0,0 +1 @@
|
|||
<ruby{{ with .Get 0 }} lang="{{ . }}"{{ end }}>{{- .Inner -}}</ruby>{{- "" -}}
|
31
layouts/shortcodes/ruby/t.html
Normal file
31
layouts/shortcodes/ruby/t.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
{{- $lang := "" -}}
|
||||
{{- $text := "" -}}
|
||||
|
||||
{{- if eq (len .Params) 2 -}}
|
||||
{{- $lang = .Get 0 -}}
|
||||
{{- $text = .Get 1 -}}
|
||||
{{- else if eq (len .Params) 1 -}}
|
||||
{{- $text = .Get 0 -}}
|
||||
{{- else -}}
|
||||
{{
|
||||
errorf "%s: Invalid number of parameters to %s: Expected 1 or 2, got %d."
|
||||
.Position .Name (len .Params)
|
||||
}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $parent := .Parent -}}
|
||||
{{- "" -}}
|
||||
<rp>(</rp>
|
||||
{{- "" -}}
|
||||
<rt
|
||||
{{- with $lang }} lang="{{ . }}"{{ end -}}
|
||||
>{{ $text }}</rt>
|
||||
{{- "" -}}
|
||||
<rp>)</rp>
|
||||
{{- "" -}}
|
||||
{{- else -}}
|
||||
{{
|
||||
errorf "%s: The %q shortcode is not meant to be called outside of a parent ruby shortcode."
|
||||
.Position .Name
|
||||
}}
|
||||
{{- end -}}
|
Loading…
Add table
Add a link
Reference in a new issue