style_config.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. """可配置的样式与辅助开关。
  2. 将样式集中到本文件,方便按需注释或将 `enabled` 置为 False。
  3. 每条规则都给出了针对的语法成分及效果说明,帮助快速定位高亮条件。
  4. """
  5. from dataclasses import dataclass
  6. from typing import Iterable, List
  7. @dataclass
  8. class StyleRule:
  9. selector: str
  10. target: str
  11. description: str
  12. css: str
  13. enabled: bool = True
  14. def to_css(self) -> str:
  15. return f"{self.selector}{{{self.css}}}"
  16. def build_style_block(rules: Iterable["StyleRule"]) -> str:
  17. body = "".join(rule.to_css() for rule in rules if rule.enabled)
  18. return f"<style>{body}</style>"
  19. STYLE_RULES: List[StyleRule] = [
  20. StyleRule(
  21. selector=".analysis",
  22. target="语法分析容器",
  23. description="设置整体行距与字号,并保持换行,保证输出易读。",
  24. css="line-height:1.65;font-size:1rem;font-weight:400",
  25. ),
  26. StyleRule(
  27. selector=".analysis span",
  28. target="所有高亮片段",
  29. description="为每个高亮片段加入适度内边距和圆角,提升视觉分隔感。",
  30. css="padding:.04rem .08rem;border-radius:.15rem",
  31. ),
  32. StyleRule(
  33. selector=".sentence-scope",
  34. target="句子外层容器",
  35. description="包裹整句,方便显示序号与复杂度指示。",
  36. css=("position:relative;display:inline;padding:0;margin:0;box-decoration-break:clone"),
  37. ),
  38. StyleRule(
  39. selector=".sentence-scope::before",
  40. target="句子编号",
  41. description="在句首展示圈号,快速定位句子编号。",
  42. css=(
  43. "content:attr(data-sid)' ';color:#475569!important;font-size:.85em;"
  44. "margin-right:.4rem;display:inline-flex;align-items:center;justify-content:center;"
  45. "min-width:1.5em;padding:0;background:transparent!important;border:none!important;"
  46. "box-shadow:none!important;text-shadow:none;filter:none;white-space:nowrap"
  47. ),
  48. ),
  49. StyleRule(
  50. selector=".paragraph-scope",
  51. target="段落容器",
  52. description="块级包裹原始段落,保持输入段落分隔并留出下边距。",
  53. css=(
  54. "display:block;padding:0;margin:15px 0 15px 0;background:none;border-radius:0;"
  55. "line-height:1.65;color:inherit;"
  56. ),
  57. ),
  58. StyleRule(
  59. selector=".analysis .paragraph-scope[data-list-kind]",
  60. target="列表容器",
  61. description="当段落来自列表时为其留出项目符号区域并缩进。",
  62. css="position:relative;padding-left:1.35rem;margin-left:.25rem",
  63. ),
  64. StyleRule(
  65. selector=".analysis .paragraph-scope[data-list-kind][data-list-depth='2']",
  66. target="二级列表缩进",
  67. description="二级列表额外缩进。",
  68. css="margin-left:1.5rem",
  69. ),
  70. StyleRule(
  71. selector=".analysis .paragraph-scope[data-list-kind][data-list-depth='3']",
  72. target="三级列表缩进",
  73. description="三级列表额外缩进。",
  74. css="margin-left:2.5rem",
  75. ),
  76. StyleRule(
  77. selector=".analysis .paragraph-scope[data-list-kind][data-list-depth='4']",
  78. target="四级列表缩进",
  79. description="四级列表额外缩进。",
  80. css="margin-left:3.5rem",
  81. ),
  82. StyleRule(
  83. selector=".analysis .paragraph-scope[data-list-kind][data-list-depth='5']",
  84. target="五级以上缩进",
  85. description="更深层级列表保持缩进阶梯。",
  86. css="margin-left:4.25rem",
  87. ),
  88. StyleRule(
  89. selector=".analysis .paragraph-scope[data-list-kind]::before",
  90. target="列表项目符号",
  91. description="绘制原始列表的符号或编号。",
  92. css="content:'';position:absolute;left:0;top:0;color:#475569;font-weight:600",
  93. ),
  94. StyleRule(
  95. selector=".analysis .paragraph-scope[data-list-kind='ul']::before",
  96. target="无序列表",
  97. description="使用圆点恢复无序列表样式。",
  98. css="content:'•';",
  99. ),
  100. StyleRule(
  101. selector=".analysis .paragraph-scope[data-list-kind='ol']::before",
  102. target="有序列表",
  103. description="使用原编号恢复有序列表样式。",
  104. css="content:attr(data-list-index) '. ';",
  105. ),
  106. StyleRule(
  107. selector=".role-subject",
  108. target="主语",
  109. description="淡黄色底纹突出主语位置。",
  110. css="background-color:#fcfee1",
  111. ),
  112. StyleRule(
  113. selector=".role-predicate",
  114. target="谓语动词",
  115. description="字体加粗,强调谓语中心。",
  116. css="color:#000000;font-weight:700;",
  117. ),
  118. StyleRule(
  119. selector=".role-predicate-clause",
  120. target="从句谓语动词",
  121. description="使用深蓝色加粗以凸显从句谓语。",
  122. css="color:#0d1c5e;font-weight:700;font-style:italic;",
  123. ),
  124. StyleRule(
  125. selector=".role-object-do",
  126. target="直接宾语",
  127. description="浅绿字体显示直接宾语。",
  128. # css="background-color:#e5ffcc",
  129. css ="color:#2a5700"
  130. ),
  131. StyleRule(
  132. selector=".role-object-io",
  133. target="间接宾语",
  134. description="黄绿字体区分间接宾语。",
  135. # css="background-color:#cef0a3",
  136. css ="color:#0b6779"
  137. ),
  138. # StyleRule(
  139. # selector=".role-complement",
  140. # target="表语/主补语",
  141. # description="实线下划线指示补语区域。",
  142. # css="border-bottom:2px dotted #af6a18",
  143. # ),
  144. # StyleRule(
  145. # selector=".role-object-complement",
  146. # target="宾补",
  147. # description="虚线下划线提示补充说明的宾补。",
  148. # css="border-bottom:2px dotted #92252c",
  149. # ),
  150. # StyleRule(
  151. # selector=".role-apposition",
  152. # target="同位语",
  153. # description="蓝色立线和缩进强调同位语说明。",
  154. # css="border-left:2px dotted #63a4d4;padding-left:.15rem",
  155. # ),
  156. StyleRule(
  157. selector=".role-adverbial",
  158. target="状语短语",
  159. description="深绿实线突出状语信息。",
  160. # css="background-color:#f6fef8",
  161. css="border-bottom:1.5px dotted #c8f9d4",
  162. ),
  163. StyleRule(
  164. selector=".verbal-infinitive",
  165. target="不定式结构",
  166. description="颜色提示 to+动词的不定式短语。",
  167. css="color:#200d72",
  168. ),
  169. StyleRule(
  170. selector=".verbal-gerund",
  171. target="动名词结构",
  172. description="淡紫底纹提示 V-ing 充当名词的结构。",
  173. css="color:#3f033d",
  174. ),
  175. StyleRule(
  176. selector=".role-connector",
  177. target="连接词",
  178. description="灰蓝底纹突出并列/从属连词,避免分散显示。",
  179. css="background-color:#e2e8f0;color:#1f2937",
  180. ),
  181. # StyleRule(
  182. # selector=".role-determiner",
  183. # target="限定词/冠词",
  184. # description="更浅的背景温和提示限定词。",
  185. # css="background-color:#f8fafc;color:#475569",
  186. # ),
  187. # StyleRule(
  188. # selector=".role-modifier",
  189. # target="形容词或并列修饰",
  190. # description="虚线下划线标出修饰信息,保证主体和修饰对比。",
  191. # css="border-bottom:1px dotted #93c5fd",
  192. # ),
  193. StyleRule(
  194. selector=".role-parenthetical",
  195. target="插入语",
  196. description="灰色虚线边框表示插入语。",
  197. css="border:1px dotted #888",
  198. ),
  199. # StyleRule(
  200. # selector=".role-absolute",
  201. # target="独立主格",
  202. # description="淡紫底色展示独立主格结构。",
  203. # css="background-color:#f0e8ff",
  204. # ),
  205. # StyleRule(
  206. # selector=".clause-noun,.clause-relative,.clause-adverbial,.clause-nonfinite",
  207. # target="从句容器(公共样式)",
  208. # description="统一使用彩色立线和左内边距包裹从句内容。",
  209. # css="border-left:2px solid currentColor;padding-left:.25rem;margin-left:.1rem",
  210. # ),
  211. StyleRule(
  212. selector=".clause-noun",
  213. target="名词从句",
  214. description="绿色配色突出名词性从句。",
  215. css="color:#5c8f1d;background-color:rgba(158,201,134,.18)",
  216. ),
  217. StyleRule(
  218. selector=".clause-relative",
  219. target="定语从句",
  220. description="紫色底色标记定语从句,便于和主句区分。",
  221. css="color:#6b4fa1;background-color:rgba(146,132,189,.15)",
  222. ),
  223. StyleRule(
  224. selector=".clause-adverbial",
  225. target="状语从句",
  226. description="灰色底色展示状语从句,配合数据属性显示功能类别。",
  227. css="color:#0f5132;background-color:rgba(128,203,196,.18)",
  228. ),
  229. StyleRule(
  230. selector=".clause-nonfinite",
  231. target="非限定从句 / 非谓语",
  232. description="橙色底纹提示非限定结构。",
  233. css="color:#c7780a;background-color:rgba(253,203,110,.18)",
  234. ),
  235. # StyleRule(
  236. # selector=".phrase-fixed",
  237. # target="固定搭配",
  238. # description="米色底与虚线强调固定表达或习语。",
  239. # css="background-color:#fff8f0;border-bottom:1px dashed #c28150",
  240. # ),
  241. ]
  242. STYLE_BLOCK = build_style_block(STYLE_RULES)