Browse Source

Merge pull request #2507 from visuddhinanda/development

Development
visuddhinanda 22 hours ago
parent
commit
5e3757d348

+ 29 - 38
api-v13/app/Services/Markup/Templates/ArticleTemplate.php

@@ -2,16 +2,22 @@
 
 namespace App\Services\Markup\Templates;
 
-use App\Services\Markup\Format;
 use App\Services\Markup\Ir\Call;
 use App\Services\Markup\Render\RenderContext;
+use App\Services\Markup\Templates\Concerns\CitesParagraph;
+use App\Services\Markup\Templates\Concerns\EmbedsArticle;
 
 /**
- * 嵌入文章 / 章节:`{{article|type|id|title|channel|style|book|paragraphs|anthology}}`。
- * `type=chapter` 且没给 id 时由 book + paragraphs 拼出 id。
+ * 嵌入文章 / 文集 / 章节 / 段落:`{{article|type|id|title|channel|style|book|paragraphs|anthology}}`。
+ *
+ * 章节另有独立的 {@see ChapterTemplate}(`{{chapter}}`);这里的 `type=chapter` 是旧写法,
+ * 没给 id 时由 book + paragraphs 拼出 id,拼法与它共用。
  */
 final class ArticleTemplate extends Template
 {
+    use CitesParagraph;
+    use EmbedsArticle;
+
     protected string $component = 'article';
 
     public function params(): array
@@ -34,29 +40,9 @@ final class ArticleTemplate extends Template
     public function props(Call $call, RenderContext $ctx): array
     {
         $type = (string) $call->param('type');
-        $id = (string) $call->param('id');
-        $book = (string) $call->param('book');
-        $paragraphs = (string) $call->param('paragraphs');
-        if ($type === 'chapter' && $id === '') {
-            $id = ((int) $book).'-'.((int) $paragraphs);
-        }
-        $props = ['type' => $type, 'id' => $id];
-        // style 为空时不给:前端组件用它自己的默认值(modal),传空串反而什么都不渲染
-        foreach (['style', 'channel', 'title', 'anthology'] as $name) {
-            $value = (string) $call->param($name);
-            if ($value !== '') {
-                $props[$name] = $value;
-            }
-        }
-        if ($book !== '') {
-            $props['book'] = $book;
-        }
-        if ($paragraphs !== '') {
-            $props['paragraphs'] = $paragraphs;
-        }
-        $props['parentChannels'] = $call->scope->channels;
+        $id = $type === 'chapter' ? $this->paragraphId($call) : (string) $call->param('id');
 
-        return $props;
+        return $this->embedProps($call, $type, $id, ['style', 'channel', 'title', 'anthology', 'book', 'paragraphs']);
     }
 
     /**
@@ -64,25 +50,30 @@ final class ArticleTemplate extends Template
      */
     public function references(Call $call): array
     {
-        $type = (string) $call->param('type');
-        if (! in_array($type, ['chapter', 'para'], true)) {
-            return [];
-        }
-        $id = (string) $call->param('id');
-        if ($id === '') {
-            $id = $call->param('book').'-'.$call->param('paragraphs');
-        }
+        return $this->citesParagraph($call) ? self::paragraphRef($this->paragraphId($call)) : [];
+    }
 
-        return self::paragraphRef($id);
+    /**
+     * 章节 / 段落:`style=reference` 且没给标题时显示缩写 + 段号,与 {{chapter}}、{{para}} 相同。
+     */
+    protected function title(Call $call): string
+    {
+        return $this->citesParagraph($call)
+            ? $this->citedTitle($call, $this->paragraphId($call))
+            : (string) $call->param('title');
     }
 
-    public function plain(Call $call, RenderContext $ctx, Format $format): string
+    private function citesParagraph(Call $call): bool
     {
-        return $format === Format::Prompt ? '' : (string) $call->param('title');
+        return in_array((string) $call->param('type'), ['chapter', 'para'], true);
     }
 
-    public function html(Call $call, RenderContext $ctx): string
+    private function paragraphId(Call $call): string
     {
-        return '';
+        return ChapterTemplate::resolveId(
+            (string) $call->param('id'),
+            (string) $call->param('book'),
+            (string) $call->param('paragraphs'),
+        );
     }
 }

+ 69 - 0
api-v13/app/Services/Markup/Templates/ChapterTemplate.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Services\Markup\Templates;
+
+use App\Services\Markup\Ir\Call;
+use App\Services\Markup\Render\RenderContext;
+use App\Services\Markup\Templates\Concerns\CitesParagraph;
+use App\Services\Markup\Templates\Concerns\EmbedsArticle;
+
+/**
+ * 嵌入经文章节:`{{chapter|id=book-para|title|channel|style}}`,没给 id 时用 `book=` + `para=`。
+ *
+ * 与 `{{article|type=chapter|…}}` 等价(前端是同一个 `article` 组件),
+ * 后者拼 id 也走 {@see self::resolveId()}。`style=reference` 且没给标题时显示缩写 + 段号({@see CitesParagraph})。
+ */
+final class ChapterTemplate extends Template
+{
+    use CitesParagraph;
+    use EmbedsArticle;
+
+    protected string $component = 'article';
+
+    public function params(): array
+    {
+        return [
+            'id' => ParamSpec::at(1),
+            'title' => ParamSpec::at(2),
+            'channel' => ParamSpec::at(3),
+            'style' => ParamSpec::at(4),
+            'book' => new ParamSpec,
+            'para' => new ParamSpec,
+        ];
+    }
+
+    /**
+     * 章节 id(`book-para`):给了 id 就用 id,否则由书号 + 段号拼出;书号也没给时为空。
+     */
+    public static function resolveId(string $id, string $book, string $para): string
+    {
+        if ($id !== '' || $book === '') {
+            return $id;
+        }
+
+        return ((int) $book).'-'.((int) $para);
+    }
+
+    /**
+     * @return array<string, mixed>
+     */
+    public function props(Call $call, RenderContext $ctx): array
+    {
+        return $this->embedProps($call, 'chapter', $this->id($call), ['style', 'channel', 'title']);
+    }
+
+    public function references(Call $call): array
+    {
+        return self::paragraphRef($this->id($call));
+    }
+
+    protected function title(Call $call): string
+    {
+        return $this->citedTitle($call, $this->id($call));
+    }
+
+    private function id(Call $call): string
+    {
+        return self::resolveId((string) $call->param('id'), (string) $call->param('book'), (string) $call->param('para'));
+    }
+}

+ 31 - 0
api-v13/app/Services/Markup/Templates/Concerns/CitesParagraph.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace App\Services\Markup\Templates\Concerns;
+
+use App\Services\Markup\Ir\Call;
+use App\Services\PaliSeriesesService;
+
+/**
+ * 嵌入经文段落 / 章节的模板({{para}}、{{chapter}}、{{article|type=chapter|para}})的标题规则:
+ * `style=reference`(行内引用)且没给标题时,标题用 wikipali 缩写 + 段号(如 `dī.ni.1.168`),
+ * 查不到缩写时用 id 本身。
+ */
+trait CitesParagraph
+{
+    /**
+     * @param  string  $id  段落 / 章节 id(`book-para`)
+     */
+    protected function citedTitle(Call $call, string $id): string
+    {
+        $title = (string) $call->param('title');
+        if ($title !== '' || (string) $call->param('style') !== 'reference') {
+            return $title;
+        }
+        $ref = self::paragraphRef($id)[0] ?? null;
+        if ($ref === null) {
+            return $id;
+        }
+
+        return app(PaliSeriesesService::class)->citation($ref[0], $ref[1]) ?? $id;
+    }
+}

+ 52 - 0
api-v13/app/Services/Markup/Templates/Concerns/EmbedsArticle.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Services\Markup\Templates\Concerns;
+
+use App\Services\Markup\Format;
+use App\Services\Markup\Ir\Call;
+use App\Services\Markup\Render\RenderContext;
+
+/**
+ * 交给前端 `article` 组件嵌入的模板({{article}}、{{chapter}})共用的输出:
+ * props 的拼法、纯文本只留标题、html 不输出(只有前端组件能渲染)。
+ * 标题走 {@see self::title()},模板可覆盖。
+ */
+trait EmbedsArticle
+{
+    /**
+     * @param  list<string>  $optional  有值才写进 props 的参数,按顺序
+     * @return array<string, mixed>
+     */
+    protected function embedProps(Call $call, string $type, string $id, array $optional): array
+    {
+        $props = ['type' => $type, 'id' => $id];
+        // style 为空时不给:前端组件用它自己的默认值(modal),传空串反而什么都不渲染
+        foreach ($optional as $name) {
+            $value = $name === 'title' ? $this->title($call) : (string) $call->param($name);
+            if ($value !== '') {
+                $props[$name] = $value;
+            }
+        }
+        $props['parentChannels'] = $call->scope->channels;
+
+        return $props;
+    }
+
+    /**
+     * 显示的标题(props 与纯文本共用);嵌入经文的模板按 {@see CitesParagraph} 补缺省标题。
+     */
+    protected function title(Call $call): string
+    {
+        return (string) $call->param('title');
+    }
+
+    public function plain(Call $call, RenderContext $ctx, Format $format): string
+    {
+        return $format === Format::Prompt ? '' : $this->title($call);
+    }
+
+    public function html(Call $call, RenderContext $ctx): string
+    {
+        return '';
+    }
+}

+ 6 - 2
api-v13/app/Services/Markup/Templates/ParaTemplate.php

@@ -4,12 +4,16 @@ namespace App\Services\Markup\Templates;
 
 use App\Services\Markup\Ir\Call;
 use App\Services\Markup\Render\RenderContext;
+use App\Services\Markup\Templates\Concerns\CitesParagraph;
 
 /**
  * 嵌入经文段落:`{{para|id=book-para|title|style}}`。
+ * `style=reference` 且没给标题时显示缩写 + 段号({@see CitesParagraph})。
  */
 final class ParaTemplate extends Template
 {
+    use CitesParagraph;
+
     protected string $component = 'para';
 
     public function params(): array
@@ -24,7 +28,7 @@ final class ParaTemplate extends Template
     {
         $props = [
             'id' => (string) $call->param('id'),
-            'title' => (string) $call->param('title'),
+            'title' => $this->citedTitle($call, (string) $call->param('id')),
             'style' => (string) $call->param('style'),
         ];
         if ($call->scope->channels !== []) {
@@ -41,6 +45,6 @@ final class ParaTemplate extends Template
 
     public function text(Call $call, RenderContext $ctx): string
     {
-        return (string) $call->param('title');
+        return $this->citedTitle($call, (string) $call->param('id'));
     }
 }

+ 1 - 0
api-v13/app/Services/Markup/Templates/TemplateRegistry.php

@@ -19,6 +19,7 @@ final class TemplateRegistry
         'ql' => QuoteLinkTemplate::class,
         'exercise' => ExerciseTemplate::class,
         'article' => ArticleTemplate::class,
+        'chapter' => ChapterTemplate::class,
         'nissaya' => NissayaTemplate::class,
         'mermaid' => MermaidTemplate::class,
         'qa' => QaTemplate::class,

+ 27 - 6
api-v13/app/Services/Markup/Templates/TocTemplate.php

@@ -7,8 +7,10 @@ use App\Services\Markup\Ir\Call;
 use App\Services\Markup\Ir\Document;
 use App\Services\Markup\Ir\Element;
 use App\Services\Markup\Ir\Node;
+use App\Services\Markup\Ir\Text;
 use App\Services\Markup\Render\HtmlRenderer;
 use App\Services\Markup\Render\RenderContext;
+use App\Services\Markup\Render\TextRenderer;
 use App\Services\Markup\Templates\Concerns\OwnsBlockTitle;
 
 /**
@@ -18,7 +20,9 @@ use App\Services\Markup\Templates\Concerns\OwnsBlockTitle;
  * - 标题:目录自带一行标题,规则见 {@see OwnsBlockTitle}(labels.toc;`title=` 改文字或隐藏;
  *   紧跟在手写标题后面时不显示)
  * - 兼容旧写法:紧挨在 `{{toc}}` 前面的标题(手写的「## 目录」)不进目录
- * - 遍历整篇内容,写在哪里都能列全;标题里的术语、格式在目录里照常显示
+ * - 遍历整篇内容,写在哪里都能列全
+ * - 目录项只给纯文本:标题里的术语取译名、格式去掉。目录项本身是链接,再套一层术语链接
+ *   (悬停弹卡片、点击打开词条)会和跳转到标题抢鼠标
  *
  * tree:`{name: 'toc', props: {title}, children: [ul]}`;html:`<nav class="toc">`。
  */
@@ -104,12 +108,29 @@ final class TocTemplate extends Template
         }
     }
 
+    /**
+     * 目录项文字:标题的纯文本(术语取译名,没有译名取原词;格式去掉)。
+     *
+     * @param  list<Node>  $nodes
+     */
+    private function label(array $nodes, Call $call, RenderContext $ctx): string
+    {
+        $text = new RenderContext(
+            $ctx->options->with(['format' => Format::Text]),
+            $ctx->resolver,
+            new TextRenderer(Format::Text),
+            $ctx->idPrefix,
+        );
+
+        return trim((string) preg_replace('/\s+/u', ' ', $text->renderString(new Document($nodes, true, '', [], $call->scope, fragment: true))));
+    }
+
     /**
      * 按层级嵌套的 `ul > li > a`。
      *
      * @param  list<array{level: int, id: string, nodes: list<Node>}>  $headings
      */
-    private function tree(array $headings): ?Element
+    private function tree(array $headings, Call $call, RenderContext $ctx): ?Element
     {
         if ($headings === []) {
             return null;
@@ -133,7 +154,7 @@ final class TocTemplate extends Template
                 $stack[] = ['level' => end($stack)['level'] + 1, 'list' => $nested];
             }
             end($stack)['list']->children[] = new Element('li', [], [
-                new Element('a', ['href' => '#'.$heading['id']], $heading['nodes']),
+                new Element('a', ['href' => '#'.$heading['id']], [new Text($this->label($heading['nodes'], $call, $ctx))]),
             ]);
         }
 
@@ -152,14 +173,14 @@ final class TocTemplate extends Template
 
     public function children(Call $call, RenderContext $ctx): ?Document
     {
-        $list = $this->tree($this->headings($call, $ctx));
+        $list = $this->tree($this->headings($call, $ctx), $call, $ctx);
 
         return $list === null ? null : new Document([$list], false, '', [], $call->scope);
     }
 
     public function html(Call $call, RenderContext $ctx): string
     {
-        $list = $this->tree($this->headings($call, $ctx));
+        $list = $this->tree($this->headings($call, $ctx), $call, $ctx);
         if ($list === null || ! $ctx->renderer instanceof HtmlRenderer) {
             return '';
         }
@@ -205,7 +226,7 @@ final class TocTemplate extends Template
         $title = $this->title($call, $ctx);
         $out = $title === '' ? [] : [$title];
         foreach ($headings as $heading) {
-            $text = trim($ctx->renderString(new Document($heading['nodes'], true, '', [], $call->scope, fragment: true)));
+            $text = $this->label($heading['nodes'], $call, $ctx);
             $out[] = str_repeat('  ', $heading['level'] - $top).$line($text, $heading['id']);
         }
 

+ 10 - 0
api-v13/app/Services/PaliSeriesesService.php

@@ -43,4 +43,14 @@ class PaliSeriesesService
 
         return $result;
     }
+
+    /**
+     * wikipali 缩写 + 段号的引用,如 `dī.ni.1.168`(缩写本身以点结尾)。查不到缩写时为 null。
+     */
+    public function citation(int $book, int $paragraph): ?string
+    {
+        $abbr = $this->find($book, $paragraph)['abbr_wp'] ?? null;
+
+        return $abbr === null ? null : $abbr.$paragraph;
+    }
 }

+ 38 - 2
api-v13/tests/Feature/MarkupSyntaxTest.php

@@ -466,6 +466,40 @@ describe('templates without data', function () {
         expect(markupRender('{{article|type=article|id=x|title=T}}', Format::Prompt))->toBe('');
     });
 
+    it('renders chapter like article type=chapter', function () {
+        $legacy = markupTree('{{article|type=chapter|book=168|paragraphs=915|title=T}}')[0];
+        $chapter = markupTree('{{chapter|book=168|para=915|title=T}}')[0];
+        expect($chapter['name'])->toBe('article');
+        expect($chapter['props'])->toBe(['type' => 'chapter', 'id' => '168-915', 'title' => 'T', 'parentChannels' => []]);
+        expect($chapter['props'])->toBe(array_diff_key($legacy['props'], ['book' => 0, 'paragraphs' => 0]));
+
+        expect(markupTree('{{chapter|168-915|T|c1|card}}')[0]['props'])
+            ->toMatchArray(['id' => '168-915', 'title' => 'T', 'channel' => 'c1', 'style' => 'card']);
+        // id 优先于 book + para
+        expect(markupTree('{{chapter|id=1-2|book=3|para=4}}')[0]['props']['id'])->toBe('1-2');
+        expect(markupTree('{{chapter}}')[0]['props']['id'])->toBe('');
+        expect(markupRender('{{chapter|1-2|T}}', Format::Text))->toBe('T');
+        expect(markupRender('{{chapter|1-2|T}}', Format::Prompt))->toBe('');
+    });
+
+    it('titles para and chapter references with the wikipali abbreviation and paragraph', function () {
+        // pali_serieses:book 1 自 para 2 起是 namakkāra.
+        expect(markupTree('{{para|id=1-2|style=reference}}')[0]['props']['title'])->toBe('namakkāra.2');
+        expect(markupTree('{{chapter|1-5|style=reference}}')[0]['props']['title'])->toBe('namakkāra.5');
+        expect(markupTree('{{chapter|book=1|para=5|style=reference}}')[0]['props']['title'])->toBe('namakkāra.5');
+        expect(markupTree('{{article|type=chapter|book=1|paragraphs=5|style=reference}}')[0]['props']['title'])->toBe('namakkāra.5');
+        expect(markupTree('{{article|type=para|id=1-5|style=reference}}')[0]['props']['title'])->toBe('namakkāra.5');
+        expect(markupRender('{{chapter|1-5|style=reference}}', Format::Text))->toBe('namakkāra.5');
+        expect(markupRender('{{para|id=1-2|style=reference}}', Format::Text))->toBe('namakkāra.2');
+
+        // 给了标题就用标题;不是 reference 不补;查不到缩写用 id;文章不补
+        expect(markupTree('{{chapter|1-5|T|style=reference}}')[0]['props']['title'])->toBe('T');
+        expect(markupTree('{{chapter|1-5|style=card}}')[0]['props'])->not->toHaveKey('title');
+        expect(markupTree('{{para|id=1-2|style=card}}')[0]['props']['title'])->toBe('');
+        expect(markupTree('{{chapter|99999-1|style=reference}}')[0]['props']['title'])->toBe('99999-1');
+        expect(markupTree('{{article|type=article|id=x|style=reference}}')[0]['props'])->not->toHaveKey('title');
+    });
+
     it('renders nissaya templates and nissaya channel lines', function () {
         expect(markupTree('{{nissaya|evaṃ|ဤသို့=thus}}')[0]['props'])
             ->toMatchArray(['pali' => 'evaṃ', 'meaning' => ['ဤသို့', 'thus']]);
@@ -681,9 +715,11 @@ describe('toc', function () {
         ]);
     });
 
-    it('keeps templates inside heading text', function () use ($source, $toc) {
+    it('gives plain text, not the templates inside heading text', function () use ($source, $toc) {
+        // 目录项是链接,再套一层术语链接会和跳转抢鼠标
         $link = $toc(markupTree($source))['children'][0]['children'][0]['children'][0];
-        expect(collect($link['children'])->firstWhere('name', 'term')['props']['word'])->toBe('dhamma');
+        expect($link['children'])->toBe([['type' => 'text', 'value' => '甲 dhamma']]);
+        expect(markupRender($source, Format::Html))->not->toMatch('/<nav class="toc">.*term-ref.*<\/nav>/s');
     });
 
     it('skips a hand-written heading right before it', function () use ($toc, $items) {

+ 6 - 0
api-v13/tests/Feature/MarkupTemplateDataTest.php

@@ -357,6 +357,12 @@ describe('ref', function () {
         expect($titles(markupDataTree($source)))->toBe(['second work', 'third work', 'first work']);
     });
 
+    it('collects references from chapter, by id or by book and para', function () use ($titles) {
+        expect($titles(markupDataTree('{{chapter|998-12}} {{chapter|book=997|para=3}}{{ref}}')))
+            ->toBe(['second work', 'third work']);
+        expect($titles(markupDataTree('{{chapter|title=t}}{{ref}}')))->toBe([]);
+    });
+
     it('picks the nearest title, counting a reference to the first paragraph of a work', function () use ($titles) {
         expect($titles(markupDataTree('{{para|id=998-10}}{{ref}}')))->toBe(['second work']);
         expect($titles(markupDataTree('{{para|id=998-9}}{{ref}}')))->toBe(['first work']);

+ 5 - 1
dashboard-v6/src/components/markup/MarkupView.tsx

@@ -3,6 +3,7 @@ import type { CSSProperties } from "react";
 
 import { renderNodes } from "./render";
 import type { MarkupNode } from "./types";
+import "./markup.css";
 
 const { Text } = Typography;
 
@@ -21,7 +22,10 @@ const MarkupView = ({ nodes, className, placeholder, style }: IWidget) => {
     return <Text type="secondary">{placeholder}</Text>;
   }
   return (
-    <Text className={className} style={style}>
+    <Text
+      className={className ? `markup-view ${className}` : "markup-view"}
+      style={style}
+    >
       {renderNodes(nodes)}
     </Text>
   );

+ 9 - 0
dashboard-v6/src/components/markup/markup.css

@@ -0,0 +1,9 @@
+/*
+ * antd 6 给每个 .ant-typography 都写死了 font-size: var(--ant-font-size)(14px),
+ * 标题里的术语、链接等模板组件(Typography.Link / Text)因此不随标题变大。
+ * 标题里的一律继承标题的字号与行高。
+ */
+.markup-view :is(h1, h2, h3, h4, h5, h6) .ant-typography {
+  font-size: inherit;
+  line-height: inherit;
+}

+ 12 - 8
dashboard-v6/src/components/template/Article.tsx

@@ -10,16 +10,12 @@ import TypeAnthology from "../article/TypeAnthology";
 import TypePali from "../article/TypePali";
 import TypePage from "../article/TypePage";
 import { articlePath, fullUrl } from "../../utils";
+import { DisplayWrapper } from "../general/DisplayWrapper";
 
 const { Text } = Typography;
 
 export type TDisplayStyle =
-  | "modal"
-  | "card"
-  | "toggle"
-  | "link"
-  | "window"
-  | "popover";
+  "modal" | "card" | "toggle" | "link" | "window" | "popover" | "reference";
 
 interface IWidgetChapterCtl {
   type?: ArticleType;
@@ -140,7 +136,7 @@ export const ArticleCtl = ({
 
   const channelsToken = channel?.split(",").map((item) => item.split("@"));
   channelsToken?.forEach((value) =>
-    sessionStorage.setItem(value[0], value[1] ?? "")
+    sessionStorage.setItem(value[0], value[1] ?? ""),
   );
   const orgChannels = channel
     ? channel.split(",").map((item) => item.split("@")[0])
@@ -184,7 +180,7 @@ export const ArticleCtl = ({
         {
           id: "buttons.open.in.new.tab",
         },
-        { item: "" }
+        { item: "" },
       )}
     </Link>
   );
@@ -253,6 +249,14 @@ export const ArticleCtl = ({
     case "window":
       output = <div style={{ width: "100%" }}>{article}</div>;
       break;
+    case "reference":
+      // 行内引用:标题(缺省是后端给的「缩写 + 段号」)虚线下划线,悬停看正文
+      output = (
+        <DisplayWrapper style="reference" title={aTitle}>
+          {article}
+        </DisplayWrapper>
+      );
+      break;
     default:
       break;
   }

+ 20 - 3
dashboard-v6/src/components/tpl-builder/templates.ts

@@ -46,10 +46,16 @@ export type TplValues = Record<string, string | undefined>;
 /** 前端 DisplayWrapper 支持的显示方式(types/template.ts 的 TDisplayStyle) */
 const DISPLAY_STYLES = ["modal", "card", "toggle", "link", "window", "popover"];
 
-const style = (defaultValue?: string): TplField => ({
+/** 嵌入经文的模板(chapter、para)另有行内引用 reference:不写标题时显示「缩写 + 段号」 */
+const PARAGRAPH_STYLES = [...DISPLAY_STYLES, "reference"];
+
+const style = (
+  defaultValue?: string,
+  options: string[] = DISPLAY_STYLES,
+): TplField => ({
   name: "style",
   kind: "select",
-  options: DISPLAY_STYLES,
+  options,
   defaultValue,
 });
 
@@ -86,12 +92,23 @@ export const TEMPLATES: TplSpec[] = [
       style(),
     ],
   },
+  {
+    name: "chapter",
+    fields: [
+      { name: "id", kind: "text", placeholder: "book-para" },
+      { name: "book", kind: "number" },
+      { name: "para", kind: "number" },
+      { name: "title", kind: "text" },
+      { name: "channel", kind: "channel" },
+      style(undefined, PARAGRAPH_STYLES),
+    ],
+  },
   {
     name: "para",
     fields: [
       { name: "id", kind: "text", placeholder: "book-para", required: true },
       { name: "title", kind: "text" },
-      style(),
+      style(undefined, PARAGRAPH_STYLES),
     ],
   },
   {

+ 3 - 0
dashboard-v6/src/locales/en-US/tpl-builder.ts

@@ -9,6 +9,7 @@ const items = {
   "tpl-builder.select.attachment": "Choose from attachments",
 
   "tpl-builder.tpl.article": "Article / chapter",
+  "tpl-builder.tpl.chapter": "Chapter",
   "tpl-builder.tpl.para": "Paragraph",
   "tpl-builder.tpl.sent": "Sentence",
   "tpl-builder.tpl.quote": "Quote",
@@ -31,6 +32,8 @@ const items = {
 
   "tpl-builder.desc.article":
     "Embed an article, an anthology or a chapter / paragraph. A chapter can be given by book + paragraph instead of an id.",
+  "tpl-builder.desc.chapter":
+    "Embed a chapter; the id is book-paragraph, or give book + paragraph instead.",
   "tpl-builder.desc.para": "Embed a paragraph; the id is book-paragraph.",
   "tpl-builder.desc.sent":
     "Embed a sentence; the id is book-paragraph-start-end. Without a channel, the content's own channel is used.",

+ 3 - 0
dashboard-v6/src/locales/zh-Hans/tpl-builder.ts

@@ -9,6 +9,7 @@ const items = {
   "tpl-builder.select.attachment": "从网盘选择",
 
   "tpl-builder.tpl.article": "文章 / 章节",
+  "tpl-builder.tpl.chapter": "经文章节",
   "tpl-builder.tpl.para": "经文段落",
   "tpl-builder.tpl.sent": "句子",
   "tpl-builder.tpl.quote": "引用段落",
@@ -31,6 +32,8 @@ const items = {
 
   "tpl-builder.desc.article":
     "嵌入一篇文章、文集或一个章节 / 段落。章节可以只给书号 + 段号,不填 id。",
+  "tpl-builder.desc.chapter":
+    "嵌入一个章节,id 写成 书号-段号,也可以不写 id、改填书号与段号。",
   "tpl-builder.desc.para": "嵌入一段经文,id 写成 书号-段号。",
   "tpl-builder.desc.sent":
     "嵌入一个句子,id 写成 书号-段号-起始词-结束词;不填 channel 用内容所属的版本。",

+ 3 - 0
dashboard-v6/src/locales/zh-Hant/tpl-builder.ts

@@ -9,6 +9,7 @@ const items = {
   "tpl-builder.select.attachment": "從網盤選擇",
 
   "tpl-builder.tpl.article": "文章 / 章節",
+  "tpl-builder.tpl.chapter": "經文章節",
   "tpl-builder.tpl.para": "經文段落",
   "tpl-builder.tpl.sent": "句子",
   "tpl-builder.tpl.quote": "引用段落",
@@ -31,6 +32,8 @@ const items = {
 
   "tpl-builder.desc.article":
     "嵌入一篇文章、文集或一個章節 / 段落。章節可以只給書號 + 段號,不填 id。",
+  "tpl-builder.desc.chapter":
+    "嵌入一個章節,id 寫成 書號-段號,也可以不寫 id、改填書號與段號。",
   "tpl-builder.desc.para": "嵌入一段經文,id 寫成 書號-段號。",
   "tpl-builder.desc.sent":
     "嵌入一個句子,id 寫成 書號-段號-起始詞-結束詞;不填 channel 用內容所屬的版本。",