34 lines
1.7 KiB
HTML
34 lines
1.7 KiB
HTML
{{- /*
|
||
边注的渲染核心:短代码 {{< note >}} 与标题边注(front matter 的 titleNote)共用。
|
||
|
||
参数:
|
||
page —— 页面(.Page / .),用于 Store 编号与 RenderString
|
||
class —— "cite" 表示书目边注,一行一项;留空则按普通注释渲染
|
||
title —— 为 true 时挂在 h1 上,固定编 1 号,不占正文计数
|
||
inner —— 内容,Markdown 或裸 HTML
|
||
|
||
约束:inner 按 inline 渲染,一旦分成两段,goldmark 会产出 <p>,
|
||
塞进 <span class="post-note"> 里属于非法嵌套,浏览器会提前闭合 span,
|
||
卡片宽度与高度归零、notes.js 的定位与折线随之失效。
|
||
所以内容必须写成一整段;需要分行时用 <br /> 或 <span class="note-line">。
|
||
*/ -}}
|
||
{{- $page := .page -}}
|
||
{{- $class := .class | default "" -}}
|
||
{{- $inner := .inner -}}
|
||
{{- $isTitle := .title | default false -}}
|
||
{{- $n := 1 -}}
|
||
{{- if not $isTitle -}}
|
||
{{- $count := add ($page.Store.Get "noteCount" | default 0) 1 -}}
|
||
{{- $page.Store.Set "noteCount" $count -}}
|
||
{{- $n = add $count (cond (ne ($page.Params.titleNote | default "") "") 1 0) -}}
|
||
{{- end -}}
|
||
<span class="post-note-anchor" aria-hidden="true"></span><sup class="post-note-mark">{{ $n }}</sup><span class="post-note{{ with $class }} {{ . }}{{ end }}"><span class="post-note-num">{{ $n }}</span>{{- with $inner -}}
|
||
{{- if eq $class "cite" -}}
|
||
{{- range split (trim . "\r\n") "\n" -}}
|
||
{{- $line := trim . "\r" -}}
|
||
{{- if ne (trim $line " ") "" -}}<span class="note-line">{{ $line | $page.RenderString (dict "display" "inline") }}</span>{{- end -}}
|
||
{{- end -}}
|
||
{{- else -}}
|
||
{{- . | $page.RenderString (dict "display" "inline") -}}
|
||
{{- end -}}
|
||
{{- end -}}</span> |