Browse Source

💄 (library): 百科页术语按状态着色,与 workspace 一致

渲染器 HTML 输出给社区术语加 term_community 类;wiki.css 按找到蓝、社区绿、没找到红着色,
去掉斜体(原来全部写死成蓝色斜体,红色只在 reader.css 里)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 22 hours ago
parent
commit
8945d1ca66

+ 6 - 1
api-v13/app/Services/Markup/Templates/TermTemplate.php

@@ -122,7 +122,12 @@ final class TermTemplate extends Template
     public function html(Call $call, RenderContext $ctx): string
     {
         $props = $this->props($call, $ctx);
-        $class = isset($props['id']) ? 'term-ref' : 'term-ref term_invalid';
+        // 与 v6 术语组件的三种状态对应:没找到(红)、取自社区术语(绿)、找到(蓝)
+        $class = match (true) {
+            ! isset($props['id']) => 'term-ref term_invalid',
+            ! empty($props['isCommunity']) => 'term-ref term_community',
+            default => 'term-ref',
+        };
 
         return '<span class="'.$class.'" data-id="'.e($props['id'] ?? '').'" data-term="'.e($props['word']).'">'
             .e($props['meaning'] ?? $props['word']).'</span>';

+ 10 - 2
api-v13/resources/css/modules/wiki.css

@@ -231,13 +231,21 @@
    五、term-ref 行内术语标记
    ══════════════════════════════════════════ */
 
+/* 颜色与 v6 术语组件一致:找到蓝(主色)、社区术语绿、没找到红;不斜体 */
 .term-ref {
-    font-style: italic;
     color: var(--tblr-primary);
-    border-bottom: 1px dotted var(--tblr-primary);
+    border-bottom: 1px dotted currentColor;
     cursor: pointer;
 }
 
+.term-ref.term_community {
+    color: green;
+}
+
+.term-ref.term_invalid {
+    color: var(--tblr-danger);
+}
+
 /* ══════════════════════════════════════════
    六、Term Popover(桌面)
    ══════════════════════════════════════════ */

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

@@ -91,6 +91,9 @@ describe('term', function () {
 
         $props = markupDataTree('{{term|kusala}}', ['channels' => [$this->channel]])[0]['props'];
         expect($props)->toMatchArray(['meaning' => '善', 'isCommunity' => true]);
+        // HTML 带上社区标记,library 百科页据此着绿色(与 v6 术语组件一致)
+        expect(markupDataRender('{{term|kusala}}', Format::Html, ['channels' => [$this->channel]]))
+            ->toContain('class="term-ref term_community"');
     });
 
     it('filters by tag with word@tag and overrides the label with word#text', function () {