| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- """可配置的样式与辅助开关。
- 将样式集中到本文件,方便按需注释或将 `enabled` 置为 False。
- 每条规则都给出了针对的语法成分及效果说明,帮助快速定位高亮条件。
- """
- from dataclasses import dataclass
- from typing import Iterable, List
- @dataclass
- class StyleRule:
- selector: str
- target: str
- description: str
- css: str
- enabled: bool = True
- def to_css(self) -> str:
- return f"{self.selector}{{{self.css}}}"
- def build_style_block(rules: Iterable["StyleRule"]) -> str:
- body = "".join(rule.to_css() for rule in rules if rule.enabled)
- return f"<style>{body}</style>"
- STYLE_RULES: List[StyleRule] = [
- StyleRule(
- selector=".analysis",
- target="语法分析容器",
- description="设置整体行距与字号,并保持换行,保证输出易读。",
- css="line-height:1.65;font-size:1rem;font-weight:400",
- ),
- StyleRule(
- selector=".analysis span",
- target="所有高亮片段",
- description="为每个高亮片段加入适度内边距和圆角,提升视觉分隔感。",
- css="padding:.04rem .08rem;border-radius:.15rem",
- ),
- StyleRule(
- selector=".sentence-scope",
- target="句子外层容器",
- description="包裹整句,方便显示序号与复杂度指示。",
- css=("position:relative;display:inline;padding:0;margin:0;box-decoration-break:clone"),
- ),
- StyleRule(
- selector=".sentence-scope::before",
- target="句子编号",
- description="在句首展示圈号,快速定位句子编号。",
- css=(
- "content:attr(data-sid)' ';color:#475569!important;font-size:.85em;"
- "margin-right:.4rem;display:inline-flex;align-items:center;justify-content:center;"
- "min-width:1.5em;padding:0;background:transparent!important;border:none!important;"
- "box-shadow:none!important;text-shadow:none;filter:none;white-space:nowrap"
- ),
- ),
- StyleRule(
- selector=".paragraph-scope",
- target="段落容器",
- description="块级包裹原始段落,保持输入段落分隔并留出下边距。",
- css=(
- "display:block;padding:0;margin:15px 0 15px 0;background:none;border-radius:0;"
- "line-height:1.65;color:inherit;"
- ),
- ),
- StyleRule(
- selector=".analysis .paragraph-scope[data-list-kind]",
- target="列表容器",
- description="当段落来自列表时为其留出项目符号区域并缩进。",
- css="position:relative;padding-left:1.35rem;margin-left:.25rem",
- ),
- StyleRule(
- selector=".analysis .paragraph-scope[data-list-kind][data-list-depth='2']",
- target="二级列表缩进",
- description="二级列表额外缩进。",
- css="margin-left:1.5rem",
- ),
- StyleRule(
- selector=".analysis .paragraph-scope[data-list-kind][data-list-depth='3']",
- target="三级列表缩进",
- description="三级列表额外缩进。",
- css="margin-left:2.5rem",
- ),
- StyleRule(
- selector=".analysis .paragraph-scope[data-list-kind][data-list-depth='4']",
- target="四级列表缩进",
- description="四级列表额外缩进。",
- css="margin-left:3.5rem",
- ),
- StyleRule(
- selector=".analysis .paragraph-scope[data-list-kind][data-list-depth='5']",
- target="五级以上缩进",
- description="更深层级列表保持缩进阶梯。",
- css="margin-left:4.25rem",
- ),
- StyleRule(
- selector=".analysis .paragraph-scope[data-list-kind]::before",
- target="列表项目符号",
- description="绘制原始列表的符号或编号。",
- css="content:'';position:absolute;left:0;top:0;color:#475569;font-weight:600",
- ),
- StyleRule(
- selector=".analysis .paragraph-scope[data-list-kind='ul']::before",
- target="无序列表",
- description="使用圆点恢复无序列表样式。",
- css="content:'•';",
- ),
- StyleRule(
- selector=".analysis .paragraph-scope[data-list-kind='ol']::before",
- target="有序列表",
- description="使用原编号恢复有序列表样式。",
- css="content:attr(data-list-index) '. ';",
- ),
- StyleRule(
- selector=".role-subject",
- target="主语",
- description="淡黄色底纹突出主语位置。",
- css="background-color:#fcfee1",
- ),
- StyleRule(
- selector=".role-predicate",
- target="谓语动词",
- description="字体加粗,强调谓语中心。",
- css="color:#000000;font-weight:700;",
- ),
- StyleRule(
- selector=".role-predicate-clause",
- target="从句谓语动词",
- description="使用深蓝色加粗以凸显从句谓语。",
- css="color:#0d1c5e;font-weight:700;font-style:italic;",
- ),
- StyleRule(
- selector=".role-object-do",
- target="直接宾语",
- description="浅绿字体显示直接宾语。",
- # css="background-color:#e5ffcc",
- css ="color:#2a5700"
- ),
- StyleRule(
- selector=".role-object-io",
- target="间接宾语",
- description="黄绿字体区分间接宾语。",
- # css="background-color:#cef0a3",
- css ="color:#0b6779"
- ),
- # StyleRule(
- # selector=".role-complement",
- # target="表语/主补语",
- # description="实线下划线指示补语区域。",
- # css="border-bottom:2px dotted #af6a18",
- # ),
- # StyleRule(
- # selector=".role-object-complement",
- # target="宾补",
- # description="虚线下划线提示补充说明的宾补。",
- # css="border-bottom:2px dotted #92252c",
- # ),
- # StyleRule(
- # selector=".role-apposition",
- # target="同位语",
- # description="蓝色立线和缩进强调同位语说明。",
- # css="border-left:2px dotted #63a4d4;padding-left:.15rem",
- # ),
- StyleRule(
- selector=".role-adverbial",
- target="状语短语",
- description="深绿实线突出状语信息。",
- # css="background-color:#f6fef8",
- css="border-bottom:1.5px dotted #c8f9d4",
- ),
- StyleRule(
- selector=".verbal-infinitive",
- target="不定式结构",
- description="颜色提示 to+动词的不定式短语。",
- css="color:#200d72",
- ),
- StyleRule(
- selector=".verbal-gerund",
- target="动名词结构",
- description="淡紫底纹提示 V-ing 充当名词的结构。",
- css="color:#3f033d",
- ),
- StyleRule(
- selector=".role-connector",
- target="连接词",
- description="灰蓝底纹突出并列/从属连词,避免分散显示。",
- css="background-color:#e2e8f0;color:#1f2937",
- ),
- # StyleRule(
- # selector=".role-determiner",
- # target="限定词/冠词",
- # description="更浅的背景温和提示限定词。",
- # css="background-color:#f8fafc;color:#475569",
- # ),
- # StyleRule(
- # selector=".role-modifier",
- # target="形容词或并列修饰",
- # description="虚线下划线标出修饰信息,保证主体和修饰对比。",
- # css="border-bottom:1px dotted #93c5fd",
- # ),
- StyleRule(
- selector=".role-parenthetical",
- target="插入语",
- description="灰色虚线边框表示插入语。",
- css="border:1px dotted #888",
- ),
- # StyleRule(
- # selector=".role-absolute",
- # target="独立主格",
- # description="淡紫底色展示独立主格结构。",
- # css="background-color:#f0e8ff",
- # ),
- # StyleRule(
- # selector=".clause-noun,.clause-relative,.clause-adverbial,.clause-nonfinite",
- # target="从句容器(公共样式)",
- # description="统一使用彩色立线和左内边距包裹从句内容。",
- # css="border-left:2px solid currentColor;padding-left:.25rem;margin-left:.1rem",
- # ),
- StyleRule(
- selector=".clause-noun",
- target="名词从句",
- description="绿色配色突出名词性从句。",
- css="color:#5c8f1d;background-color:rgba(158,201,134,.18)",
- ),
- StyleRule(
- selector=".clause-relative",
- target="定语从句",
- description="紫色底色标记定语从句,便于和主句区分。",
- css="color:#6b4fa1;background-color:rgba(146,132,189,.15)",
- ),
- StyleRule(
- selector=".clause-adverbial",
- target="状语从句",
- description="灰色底色展示状语从句,配合数据属性显示功能类别。",
- css="color:#0f5132;background-color:rgba(128,203,196,.18)",
- ),
- StyleRule(
- selector=".clause-nonfinite",
- target="非限定从句 / 非谓语",
- description="橙色底纹提示非限定结构。",
- css="color:#c7780a;background-color:rgba(253,203,110,.18)",
- ),
-
-
- # StyleRule(
- # selector=".phrase-fixed",
- # target="固定搭配",
- # description="米色底与虚线强调固定表达或习语。",
- # css="background-color:#fff8f0;border-bottom:1px dashed #c28150",
- # ),
- ]
- STYLE_BLOCK = build_style_block(STYLE_RULES)
|