epub-translator 0.0.7__py3-none-any.whl → 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. epub_translator/__init__.py +4 -2
  2. epub_translator/data/fill.jinja +66 -0
  3. epub_translator/data/mmltex/README.md +67 -0
  4. epub_translator/data/mmltex/cmarkup.xsl +1106 -0
  5. epub_translator/data/mmltex/entities.xsl +459 -0
  6. epub_translator/data/mmltex/glayout.xsl +222 -0
  7. epub_translator/data/mmltex/mmltex.xsl +36 -0
  8. epub_translator/data/mmltex/scripts.xsl +375 -0
  9. epub_translator/data/mmltex/tables.xsl +130 -0
  10. epub_translator/data/mmltex/tokens.xsl +328 -0
  11. epub_translator/data/translate.jinja +15 -12
  12. epub_translator/epub/__init__.py +4 -2
  13. epub_translator/epub/common.py +43 -0
  14. epub_translator/epub/math.py +193 -0
  15. epub_translator/epub/placeholder.py +53 -0
  16. epub_translator/epub/spines.py +42 -0
  17. epub_translator/epub/toc.py +505 -0
  18. epub_translator/epub/zip.py +67 -0
  19. epub_translator/iter_sync.py +24 -0
  20. epub_translator/language.py +23 -0
  21. epub_translator/llm/__init__.py +2 -1
  22. epub_translator/llm/core.py +233 -0
  23. epub_translator/llm/error.py +38 -35
  24. epub_translator/llm/executor.py +159 -136
  25. epub_translator/llm/increasable.py +28 -28
  26. epub_translator/llm/types.py +17 -0
  27. epub_translator/serial/__init__.py +2 -0
  28. epub_translator/serial/chunk.py +52 -0
  29. epub_translator/serial/segment.py +17 -0
  30. epub_translator/serial/splitter.py +50 -0
  31. epub_translator/template.py +35 -33
  32. epub_translator/translator.py +208 -178
  33. epub_translator/utils.py +7 -0
  34. epub_translator/xml/__init__.py +4 -3
  35. epub_translator/xml/deduplication.py +38 -0
  36. epub_translator/xml/firendly/__init__.py +2 -0
  37. epub_translator/xml/firendly/decoder.py +75 -0
  38. epub_translator/xml/firendly/encoder.py +84 -0
  39. epub_translator/xml/firendly/parser.py +177 -0
  40. epub_translator/xml/firendly/tag.py +118 -0
  41. epub_translator/xml/firendly/transform.py +36 -0
  42. epub_translator/xml/xml.py +52 -0
  43. epub_translator/xml/xml_like.py +231 -0
  44. epub_translator/xml_translator/__init__.py +3 -0
  45. epub_translator/xml_translator/const.py +2 -0
  46. epub_translator/xml_translator/fill.py +128 -0
  47. epub_translator/xml_translator/format.py +282 -0
  48. epub_translator/xml_translator/fragmented.py +125 -0
  49. epub_translator/xml_translator/group.py +183 -0
  50. epub_translator/xml_translator/progressive_locking.py +256 -0
  51. epub_translator/xml_translator/submitter.py +102 -0
  52. epub_translator/xml_translator/text_segment.py +263 -0
  53. epub_translator/xml_translator/translator.py +179 -0
  54. epub_translator/xml_translator/utils.py +29 -0
  55. epub_translator-0.1.1.dist-info/METADATA +283 -0
  56. epub_translator-0.1.1.dist-info/RECORD +58 -0
  57. epub_translator/data/format.jinja +0 -33
  58. epub_translator/epub/content_parser.py +0 -162
  59. epub_translator/epub/html/__init__.py +0 -1
  60. epub_translator/epub/html/dom_operator.py +0 -68
  61. epub_translator/epub/html/empty_tags.py +0 -23
  62. epub_translator/epub/html/file.py +0 -80
  63. epub_translator/epub/html/texts_searcher.py +0 -46
  64. epub_translator/llm/node.py +0 -201
  65. epub_translator/translation/__init__.py +0 -2
  66. epub_translator/translation/chunk.py +0 -118
  67. epub_translator/translation/splitter.py +0 -78
  68. epub_translator/translation/store.py +0 -36
  69. epub_translator/translation/translation.py +0 -231
  70. epub_translator/translation/types.py +0 -45
  71. epub_translator/translation/utils.py +0 -11
  72. epub_translator/xml/decoder.py +0 -71
  73. epub_translator/xml/encoder.py +0 -95
  74. epub_translator/xml/parser.py +0 -172
  75. epub_translator/xml/tag.py +0 -93
  76. epub_translator/xml/transform.py +0 -34
  77. epub_translator/xml/utils.py +0 -12
  78. epub_translator/zip_context.py +0 -74
  79. epub_translator-0.0.7.dist-info/METADATA +0 -170
  80. epub_translator-0.0.7.dist-info/RECORD +0 -36
  81. {epub_translator-0.0.7.dist-info → epub_translator-0.1.1.dist-info}/LICENSE +0 -0
  82. {epub_translator-0.0.7.dist-info → epub_translator-0.1.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,130 @@
1
+ <?xml version='1.0' encoding="UTF-8"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
+ xmlns:m="http://www.w3.org/1998/Math/MathML"
4
+ version='1.0'>
5
+
6
+ <!-- ====================================================================== -->
7
+ <!-- $id: tables.xsl, 2002/17/05 Exp $
8
+ This file is part of the XSLT MathML Library distribution.
9
+ See ./README or http://www.raleigh.ru/MathML/mmltex for
10
+ copyright and other information -->
11
+ <!-- ====================================================================== -->
12
+
13
+ <xsl:template match="m:mtd[@columnspan]">
14
+ <xsl:text>\multicolumn{</xsl:text>
15
+ <xsl:value-of select="@columnspan"/>
16
+ <xsl:text>}{c}{</xsl:text>
17
+ <xsl:apply-templates/>
18
+ <xsl:text>}</xsl:text>
19
+ <xsl:if test="count(following-sibling::*)>0">
20
+ <xsl:text>&amp; </xsl:text>
21
+ </xsl:if>
22
+ </xsl:template>
23
+
24
+
25
+ <xsl:template match="m:mtd">
26
+ <xsl:if test="@columnalign='right' or @columnalign='center'">
27
+ <xsl:text>\hfill </xsl:text>
28
+ </xsl:if>
29
+ <xsl:apply-templates/>
30
+ <xsl:if test="@columnalign='left' or @columnalign='center'">
31
+ <xsl:text>\hfill </xsl:text>
32
+ </xsl:if>
33
+ <xsl:if test="count(following-sibling::*)>0">
34
+ <!-- this test valid for Sablotron, another form - test="not(position()=last())".
35
+ Also for m:mtd[@columnspan] and m:mtr -->
36
+ <xsl:text>&amp; </xsl:text>
37
+ </xsl:if>
38
+ </xsl:template>
39
+
40
+ <xsl:template match="m:mtr">
41
+ <xsl:apply-templates/>
42
+ <xsl:if test="count(following-sibling::*)>0">
43
+ <xsl:text>\\ </xsl:text>
44
+ </xsl:if>
45
+ </xsl:template>
46
+
47
+ <xsl:template match="m:mtable">
48
+ <xsl:text>\begin{array}{</xsl:text>
49
+ <xsl:if test="@frame='solid'">
50
+ <xsl:text>|</xsl:text>
51
+ </xsl:if>
52
+ <xsl:variable name="numbercols" select="count(./m:mtr[1]/m:mtd[not(@columnspan)])+sum(./m:mtr[1]/m:mtd/@columnspan)"/>
53
+ <xsl:choose>
54
+ <xsl:when test="@columnalign">
55
+ <xsl:variable name="colalign">
56
+ <xsl:call-template name="colalign">
57
+ <xsl:with-param name="colalign" select="@columnalign"/>
58
+ </xsl:call-template>
59
+ </xsl:variable>
60
+ <xsl:choose>
61
+ <xsl:when test="string-length($colalign) > $numbercols">
62
+ <xsl:value-of select="substring($colalign,1,$numbercols)"/>
63
+ </xsl:when>
64
+ <xsl:when test="string-length($colalign) &lt; $numbercols">
65
+ <xsl:value-of select="$colalign"/>
66
+ <xsl:call-template name="generate-string">
67
+ <xsl:with-param name="text" select="substring($colalign,string-length($colalign))"/>
68
+ <xsl:with-param name="count" select="$numbercols - string-length($colalign)"/>
69
+ </xsl:call-template>
70
+ </xsl:when>
71
+ <xsl:otherwise>
72
+ <xsl:value-of select="$colalign"/>
73
+ </xsl:otherwise>
74
+ </xsl:choose>
75
+ </xsl:when>
76
+ <xsl:otherwise>
77
+ <xsl:call-template name="generate-string">
78
+ <xsl:with-param name="text" select="'c'"/>
79
+ <xsl:with-param name="count" select="$numbercols"/>
80
+ </xsl:call-template>
81
+ </xsl:otherwise>
82
+ </xsl:choose>
83
+ <xsl:if test="@frame='solid'">
84
+ <xsl:text>|</xsl:text>
85
+ </xsl:if>
86
+ <xsl:text>}</xsl:text>
87
+ <xsl:if test="@frame='solid'">
88
+ <xsl:text>\hline </xsl:text>
89
+ </xsl:if>
90
+ <xsl:apply-templates/>
91
+ <xsl:if test="@frame='solid'">
92
+ <xsl:text>\\ \hline</xsl:text>
93
+ </xsl:if>
94
+ <xsl:text>\end{array}</xsl:text>
95
+ </xsl:template>
96
+
97
+ <xsl:template name="colalign">
98
+ <xsl:param name="colalign"/>
99
+ <xsl:choose>
100
+ <xsl:when test="contains($colalign,' ')">
101
+ <xsl:value-of select="substring($colalign,1,1)"/>
102
+ <xsl:call-template name="colalign">
103
+ <xsl:with-param name="colalign" select="substring-after($colalign,' ')"/>
104
+ </xsl:call-template>
105
+ </xsl:when>
106
+ <xsl:otherwise>
107
+ <xsl:value-of select="substring($colalign,1,1)"/>
108
+ </xsl:otherwise>
109
+ </xsl:choose>
110
+ </xsl:template>
111
+
112
+ <xsl:template name="generate-string">
113
+ <!-- template from XSLT Standard Library v1.1 -->
114
+ <xsl:param name="text"/>
115
+ <xsl:param name="count"/>
116
+
117
+ <xsl:choose>
118
+ <xsl:when test="string-length($text) = 0 or $count &lt;= 0"/>
119
+
120
+ <xsl:otherwise>
121
+ <xsl:value-of select="$text"/>
122
+ <xsl:call-template name="generate-string">
123
+ <xsl:with-param name="text" select="$text"/>
124
+ <xsl:with-param name="count" select="$count - 1"/>
125
+ </xsl:call-template>
126
+ </xsl:otherwise>
127
+ </xsl:choose>
128
+ </xsl:template>
129
+
130
+ </xsl:stylesheet>
@@ -0,0 +1,328 @@
1
+ <?xml version='1.0' encoding="UTF-8"?>
2
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
+ xmlns:m="http://www.w3.org/1998/Math/MathML"
4
+ version='1.0'>
5
+
6
+ <!-- ====================================================================== -->
7
+ <!-- $Id: tokens.xsl,v 1.7 2003/06/10 12:24:05 shade33 Exp $
8
+ This file is part of the XSLT MathML Library distribution.
9
+ See ./README or http://www.raleigh.ru/MathML/mmltex for
10
+ copyright and other information -->
11
+ <!-- ====================================================================== -->
12
+
13
+ <xsl:template match="m:mi|m:mn|m:mo|m:mtext|m:ms">
14
+ <xsl:call-template name="CommonTokenAtr"/>
15
+ </xsl:template>
16
+
17
+ <!-- 3.2.9 mglyph -->
18
+ <xsl:template match="m:mglyph">
19
+ <xsl:text>\textcolor{red}{</xsl:text>
20
+ <xsl:value-of select="@alt"/>
21
+ <xsl:text>}</xsl:text>
22
+ </xsl:template>
23
+
24
+ <xsl:template name="mi">
25
+ <xsl:choose>
26
+ <xsl:when test="string-length(normalize-space(.))>1 and not(@mathvariant)">
27
+ <xsl:text>\mathrm{</xsl:text>
28
+ <xsl:apply-templates/>
29
+ <xsl:text>}</xsl:text>
30
+ </xsl:when>
31
+ <xsl:otherwise>
32
+ <xsl:apply-templates/>
33
+ </xsl:otherwise>
34
+ </xsl:choose>
35
+ </xsl:template>
36
+
37
+ <xsl:template name="mn">
38
+ <xsl:choose>
39
+ <xsl:when test="string(number(.))='NaN' and not(@mathvariant)">
40
+ <xsl:text>\mathrm{</xsl:text>
41
+ <xsl:apply-templates/>
42
+ <xsl:text>}</xsl:text>
43
+ </xsl:when>
44
+ <xsl:otherwise>
45
+ <xsl:apply-templates/>
46
+ </xsl:otherwise>
47
+ </xsl:choose>
48
+ </xsl:template>
49
+
50
+ <!-- 3.2.5 Math Operator -->
51
+ <xsl:template name="mo">
52
+ <xsl:if test="translate(normalize-space(.),'()[]}|','{{{{{{')='{'">
53
+ <xsl:choose>
54
+ <xsl:when test="not(@stretchy='false') and count(preceding-sibling::m:mo[translate(normalize-space(.),'()[]}|','{{{{{{')='{'])mod 2=0 and following-sibling::m:mo[1][not(@stretchy='false')][translate(normalize-space(.),'()[]}|','{{{{{{')='{']">
55
+ <xsl:text>\left</xsl:text>
56
+ </xsl:when>
57
+ <xsl:when test="not(@stretchy='false') and count(preceding-sibling::m:mo[translate(normalize-space(.),'()[]}|','{{{{{{')='{'])mod 2=1 and preceding-sibling::m:mo[1][not(@stretchy='false')][translate(normalize-space(.),'()[]}|','{{{{{{')='{']">
58
+ <xsl:text>\right</xsl:text>
59
+ </xsl:when>
60
+ </xsl:choose>
61
+ </xsl:if>
62
+ <xsl:apply-templates/>
63
+ </xsl:template>
64
+
65
+ <xsl:template name="mtext">
66
+ <xsl:variable name="content">
67
+ <xsl:call-template name="replaceMtextEntities">
68
+ <xsl:with-param name="content" select="normalize-space(.)"/>
69
+ </xsl:call-template>
70
+ </xsl:variable>
71
+ <xsl:text>\text{</xsl:text>
72
+ <xsl:value-of select="$content"/>
73
+ <xsl:text>}</xsl:text>
74
+ </xsl:template>
75
+
76
+ <xsl:template match="m:mspace">
77
+ <xsl:text>\phantom{\rule</xsl:text>
78
+ <xsl:if test="@depth">
79
+ <xsl:text>[-</xsl:text>
80
+ <xsl:value-of select="@depth"/>
81
+ <xsl:text>]</xsl:text>
82
+ </xsl:if>
83
+ <xsl:text>{</xsl:text>
84
+ <xsl:if test="not(@width)">
85
+ <xsl:text>0ex</xsl:text>
86
+ </xsl:if>
87
+ <xsl:value-of select="@width"/>
88
+ <xsl:text>}{</xsl:text>
89
+ <xsl:if test="not(@height)">
90
+ <xsl:text>0ex</xsl:text>
91
+ </xsl:if>
92
+ <xsl:value-of select="@height"/>
93
+ <xsl:text>}}</xsl:text>
94
+ </xsl:template>
95
+
96
+ <xsl:template name="ms">
97
+ <xsl:choose>
98
+ <xsl:when test="@lquote"><xsl:value-of select="@lquote"/></xsl:when>
99
+ <xsl:otherwise><xsl:text>''</xsl:text></xsl:otherwise>
100
+ </xsl:choose><xsl:apply-templates/><xsl:choose>
101
+ <xsl:when test="@rquote"><xsl:value-of select="@rquote"/></xsl:when>
102
+ <xsl:otherwise><xsl:text>''</xsl:text></xsl:otherwise>
103
+ </xsl:choose>
104
+ </xsl:template>
105
+
106
+ <xsl:template name="CommonTokenAtr">
107
+ <xsl:if test="@mathbackground">
108
+ <xsl:text>\colorbox[rgb]{</xsl:text>
109
+ <xsl:call-template name="color">
110
+ <xsl:with-param name="color" select="@mathbackground"/>
111
+ </xsl:call-template>
112
+ <xsl:text>}{$</xsl:text>
113
+ </xsl:if>
114
+ <xsl:if test="@color[not(@mathcolor)] or @mathcolor"> <!-- Note: @color is deprecated in MathML 2.0 -->
115
+ <xsl:text>\textcolor[rgb]{</xsl:text>
116
+ <xsl:call-template name="color">
117
+ <xsl:with-param name="color" select="@color|@mathcolor"/>
118
+ </xsl:call-template>
119
+ <xsl:text>}{</xsl:text>
120
+ </xsl:if>
121
+ <xsl:if test="@mathvariant">
122
+ <xsl:choose>
123
+ <xsl:when test="@mathvariant='normal'">
124
+ <xsl:text>\mathrm{</xsl:text>
125
+ </xsl:when>
126
+ <xsl:when test="@mathvariant='bold'">
127
+ <xsl:text>\mathbf{</xsl:text>
128
+ </xsl:when>
129
+ <xsl:when test="@mathvariant='italic'">
130
+ <xsl:text>\mathit{</xsl:text>
131
+ </xsl:when>
132
+ <xsl:when test="@mathvariant='bold-italic'"> <!-- not supported -->
133
+ <xsl:text>\mathit{</xsl:text>
134
+ <xsl:message>The value bold-italic for mathvariant is not supported</xsl:message>
135
+ </xsl:when>
136
+ <xsl:when test="@mathvariant='double-struck'"> <!-- Required amsfonts -->
137
+ <xsl:text>\mathbb{</xsl:text>
138
+ </xsl:when>
139
+ <xsl:when test="@mathvariant='bold-fraktur'"> <!-- not supported -->
140
+ <xsl:text>\mathfrak{</xsl:text>
141
+ <xsl:message>The value bold-fraktur for mathvariant is not supported</xsl:message>
142
+ </xsl:when>
143
+ <xsl:when test="@mathvariant='script'">
144
+ <xsl:text>\mathcal{</xsl:text>
145
+ </xsl:when>
146
+ <xsl:when test="@mathvariant='bold-script'"> <!-- not supported -->
147
+ <xsl:text>\mathcal{</xsl:text>
148
+ <xsl:message>The value bold-script for mathvariant is not supported</xsl:message>
149
+ </xsl:when>
150
+ <xsl:when test="@mathvariant='fraktur'"> <!-- Required amsfonts -->
151
+ <xsl:text>\mathfrak{</xsl:text>
152
+ </xsl:when>
153
+ <xsl:when test="@mathvariant='sans-serif'">
154
+ <xsl:text>\mathsf{</xsl:text>
155
+ </xsl:when>
156
+ <xsl:when test="@mathvariant='bold-sans-serif'"> <!-- not supported -->
157
+ <xsl:text>\mathsf{</xsl:text>
158
+ <xsl:message>The value bold-sans-serif for mathvariant is not supported</xsl:message>
159
+ </xsl:when>
160
+ <xsl:when test="@mathvariant='sans-serif-italic'"> <!-- not supported -->
161
+ <xsl:text>\mathsf{</xsl:text>
162
+ <xsl:message>The value sans-serif-italic for mathvariant is not supported</xsl:message>
163
+ </xsl:when>
164
+ <xsl:when test="@mathvariant='sans-serif-bold-italic'"> <!-- not supported -->
165
+ <xsl:text>\mathsf{</xsl:text>
166
+ <xsl:message>The value sans-serif-bold-italic for mathvariant is not supported</xsl:message>
167
+ </xsl:when>
168
+ <xsl:when test="@mathvariant='monospace'">
169
+ <xsl:text>\mathtt{</xsl:text>
170
+ </xsl:when>
171
+ <xsl:otherwise>
172
+ <xsl:text>{</xsl:text>
173
+ <xsl:message>Error at mathvariant attribute</xsl:message>
174
+ </xsl:otherwise>
175
+ </xsl:choose>
176
+ </xsl:if>
177
+ <xsl:call-template name="selectTemplate"/>
178
+ <xsl:if test="@mathvariant">
179
+ <xsl:text>}</xsl:text>
180
+ </xsl:if>
181
+ <xsl:if test="@color or @mathcolor">
182
+ <xsl:text>}</xsl:text>
183
+ </xsl:if>
184
+ <xsl:if test="@mathbackground">
185
+ <xsl:text>$}</xsl:text>
186
+ </xsl:if>
187
+ </xsl:template>
188
+
189
+ <xsl:template name="selectTemplate">
190
+ <xsl:choose>
191
+ <xsl:when test="local-name(.)='mi'">
192
+ <xsl:call-template name="mi"/>
193
+ </xsl:when>
194
+ <xsl:when test="local-name(.)='mn'">
195
+ <xsl:call-template name="mn"/>
196
+ </xsl:when>
197
+ <xsl:when test="local-name(.)='mo'">
198
+ <xsl:call-template name="mo"/>
199
+ </xsl:when>
200
+ <xsl:when test="local-name(.)='mtext'">
201
+ <xsl:call-template name="mtext"/>
202
+ </xsl:when>
203
+ <xsl:when test="local-name(.)='ms'">
204
+ <xsl:call-template name="ms"/>
205
+ </xsl:when>
206
+ </xsl:choose>
207
+ </xsl:template>
208
+
209
+ <xsl:template name="color">
210
+ <!-- NB: Variables colora and valueColor{n} only for Sablotron -->
211
+ <xsl:param name="color"/>
212
+ <xsl:variable name="colora" select="translate($color,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
213
+ <xsl:choose>
214
+ <xsl:when test="starts-with($colora,'#') and string-length($colora)=4">
215
+ <xsl:variable name="valueColor">
216
+ <xsl:call-template name="Hex2Decimal">
217
+ <xsl:with-param name="arg" select="substring($colora,2,1)"/>
218
+ </xsl:call-template>
219
+ </xsl:variable>
220
+ <xsl:value-of select="$valueColor div 15"/><xsl:text>,</xsl:text>
221
+ <xsl:variable name="valueColor1">
222
+ <xsl:call-template name="Hex2Decimal">
223
+ <xsl:with-param name="arg" select="substring($colora,3,1)"/>
224
+ </xsl:call-template>
225
+ </xsl:variable>
226
+ <xsl:value-of select="$valueColor1 div 15"/><xsl:text>,</xsl:text>
227
+ <xsl:variable name="valueColor2">
228
+ <xsl:call-template name="Hex2Decimal">
229
+ <xsl:with-param name="arg" select="substring($colora,4,1)"/>
230
+ </xsl:call-template>
231
+ </xsl:variable>
232
+ <xsl:value-of select="$valueColor2 div 15"/>
233
+ </xsl:when>
234
+ <xsl:when test="starts-with($colora,'#') and string-length($colora)=7">
235
+ <xsl:variable name="valueColor1">
236
+ <xsl:call-template name="Hex2Decimal">
237
+ <xsl:with-param name="arg" select="substring($colora,2,1)"/>
238
+ </xsl:call-template>
239
+ </xsl:variable>
240
+ <xsl:variable name="valueColor2">
241
+ <xsl:call-template name="Hex2Decimal">
242
+ <xsl:with-param name="arg" select="substring($colora,3,1)"/>
243
+ </xsl:call-template>
244
+ </xsl:variable>
245
+ <xsl:value-of select="($valueColor1*16 + $valueColor2) div 255"/><xsl:text>,</xsl:text>
246
+ <xsl:variable name="valueColor1a">
247
+ <xsl:call-template name="Hex2Decimal">
248
+ <xsl:with-param name="arg" select="substring($colora,4,1)"/>
249
+ </xsl:call-template>
250
+ </xsl:variable>
251
+ <xsl:variable name="valueColor2a">
252
+ <xsl:call-template name="Hex2Decimal">
253
+ <xsl:with-param name="arg" select="substring($colora,5,1)"/>
254
+ </xsl:call-template>
255
+ </xsl:variable>
256
+ <xsl:value-of select="($valueColor1a*16 + $valueColor2a) div 255"/><xsl:text>,</xsl:text>
257
+ <xsl:variable name="valueColor1b">
258
+ <xsl:call-template name="Hex2Decimal">
259
+ <xsl:with-param name="arg" select="substring($colora,6,1)"/>
260
+ </xsl:call-template>
261
+ </xsl:variable>
262
+ <xsl:variable name="valueColor2b">
263
+ <xsl:call-template name="Hex2Decimal">
264
+ <xsl:with-param name="arg" select="substring($colora,7,1)"/>
265
+ </xsl:call-template>
266
+ </xsl:variable>
267
+ <xsl:value-of select="($valueColor1b*16 + $valueColor2b) div 255"/>
268
+ </xsl:when>
269
+ <!-- ======================= if color specifed as an html-color-name ========================================== -->
270
+ <xsl:when test="$colora='aqua'"><xsl:text>0,1,1</xsl:text></xsl:when>
271
+ <xsl:when test="$colora='black'"><xsl:text>0,0,0</xsl:text></xsl:when>
272
+ <xsl:when test="$colora='blue'"><xsl:text>0,0,1</xsl:text></xsl:when>
273
+ <xsl:when test="$colora='fuchsia'"><xsl:text>1,0,1</xsl:text></xsl:when>
274
+ <xsl:when test="$colora='gray'"><xsl:text>.5,.5,.5</xsl:text></xsl:when>
275
+ <xsl:when test="$colora='green'"><xsl:text>0,.5,0</xsl:text></xsl:when>
276
+ <xsl:when test="$colora='lime'"><xsl:text>0,1,0</xsl:text></xsl:when>
277
+ <xsl:when test="$colora='maroon'"><xsl:text>.5,0,0</xsl:text></xsl:when>
278
+ <xsl:when test="$colora='navy'"><xsl:text>0,0,.5</xsl:text></xsl:when>
279
+ <xsl:when test="$colora='olive'"><xsl:text>.5,.5,0</xsl:text></xsl:when>
280
+ <xsl:when test="$colora='purple'"><xsl:text>.5,0,.5</xsl:text></xsl:when>
281
+ <xsl:when test="$colora='red'"><xsl:text>1,0,0</xsl:text></xsl:when>
282
+ <xsl:when test="$colora='silver'"><xsl:text>.75,.75,.75</xsl:text></xsl:when>
283
+ <xsl:when test="$colora='teal'"><xsl:text>0,.5,.5</xsl:text></xsl:when>
284
+ <xsl:when test="$colora='white'"><xsl:text>1,1,1</xsl:text></xsl:when>
285
+ <xsl:when test="$colora='yellow'"><xsl:text>1,1,0</xsl:text></xsl:when>
286
+ <xsl:otherwise>
287
+ <xsl:message>Exception at color template</xsl:message>
288
+ </xsl:otherwise>
289
+ </xsl:choose>
290
+ </xsl:template>
291
+
292
+ <xsl:template name="Hex2Decimal">
293
+ <xsl:param name="arg"/>
294
+ <xsl:choose>
295
+ <xsl:when test="$arg='f'">
296
+ <xsl:value-of select="15"/>
297
+ </xsl:when>
298
+ <xsl:when test="$arg='e'">
299
+ <xsl:value-of select="14"/>
300
+ </xsl:when>
301
+ <xsl:when test="$arg='d'">
302
+ <xsl:value-of select="13"/>
303
+ </xsl:when>
304
+ <xsl:when test="$arg='c'">
305
+ <xsl:value-of select="12"/>
306
+ </xsl:when>
307
+ <xsl:when test="$arg='b'">
308
+ <xsl:value-of select="11"/>
309
+ </xsl:when>
310
+ <xsl:when test="$arg='a'">
311
+ <xsl:value-of select="10"/>
312
+ </xsl:when>
313
+ <xsl:when test="translate($arg, '0123456789', '9999999999')='9'"> <!-- if $arg is number -->
314
+ <xsl:value-of select="$arg"/>
315
+ </xsl:when>
316
+ <xsl:otherwise>
317
+ <xsl:message>Exception at Hex2Decimal template</xsl:message>
318
+ </xsl:otherwise>
319
+ </xsl:choose>
320
+ </xsl:template>
321
+
322
+ <xsl:template match="m:*/text()">
323
+ <xsl:call-template name="replaceEntities">
324
+ <xsl:with-param name="content" select="normalize-space()"/>
325
+ </xsl:call-template>
326
+ </xsl:template>
327
+
328
+ </xsl:stylesheet>
@@ -1,15 +1,18 @@
1
- 你是一位翻译家,用户接下来的发言会提交一段{% if user_prompt %}翻译要求和一段{% endif %}文本的原文。你要将原文翻译成{{ target_language }}
1
+ You are a translator. Translate the following text into {{ target_language }}.
2
2
 
3
- 翻译时,需遵守如下规则:
4
- - 译文必须忠实于原文,保持原意。不得修改、删除原文中的内容和情节,不得新增原文中不存在的内容和情节。
5
- - 保留原文细节,不得简略、缩写、总结原文的内容。
6
- - 不得衍生创作,续写原文中缺失、断裂、不协调的部分,你要忠实地保留他们。
7
- - 禁止改正原文的错误,你是翻译家,不是校对员或编辑。
8
- - 不得因为原文中包含歧视、暴力、性行为、敏感内容、儿童不宜等内容而进行删减或修改。你是翻译家,不是鉴黄师或审查员。
9
- - 不得在译文中写你的个人评论、总结或观点。
3
+ Translation rules:
4
+ - **Translate completely; do not omit any part of the source text**
5
+ - Maintain fidelity to the source; do not modify, add, or remove content
6
+ - Translate sentence by sentence, preserving paragraph structure
7
+ - Preserve all details; do not summarize or abbreviate
8
+ - Do not correct errors or inconsistencies in the source
9
+ - Do not censor sensitive content; translate as-is
10
+ - Do not add commentary or explanations
11
+ - Output plain text only; do not use markdown, HTML tags, or any formatting syntax
10
12
 
11
- {% if user_prompt %}
12
- 除了以上规则之外,你需要遵守用户的“翻译要求”。用户会把要求放在原文之前,并用<rules>标签包裹。特别的,当用户的翻译要求中某些规则条目与我之前提的规则冲突时,你要优先遵守我的规则。此外,用户可能在<rules>标签中补充一些额外信息以帮助你翻译,你需要认真阅读和参考,并在翻译中体现出来。而在<rules>标签之后,紧接着就是用户的原文,你要阅读并翻译。
13
- {% endif %}
13
+ {% if user_prompt -%}
14
+ User may provide additional requirements in <rules> tags before the source text. Follow them, but prioritize the rules above if conflicts arise.
14
15
 
15
- 最终,你要将译文以纯文本的方式提交。期间,根据你的理解将译文拆成多个自然段(用户提交的原文是不分段的整块文字)。你必须用 "```txt" 作为独立的第一行,"```"作为独立的最后一行,中间包裹译文。注意,译文中禁止插入你的说明性文字或思考过程,将这些移到"```" 之后。
16
+ {% endif -%}
17
+
18
+ Output only the translated text, nothing else.
@@ -1,2 +1,4 @@
1
- from .content_parser import Spine, EpubContent
2
- from .html import HTMLFile
1
+ from .placeholder import Placeholder, is_placeholder_tag
2
+ from .spines import search_spine_paths
3
+ from .toc import read_toc, write_toc
4
+ from .zip import Zip
@@ -0,0 +1,43 @@
1
+ from pathlib import Path
2
+ from xml.etree import ElementTree as ET
3
+ from xml.etree.ElementTree import Element
4
+
5
+ from .zip import Zip
6
+
7
+
8
+ def find_opf_path(zip: Zip) -> Path:
9
+ container_path = Path("META-INF", "container.xml")
10
+
11
+ with zip.read(container_path) as f:
12
+ content = f.read()
13
+ root = ET.fromstring(content)
14
+ ns = {"ns": "urn:oasis:names:tc:opendocument:xmlns:container"}
15
+ rootfile = root.find(".//ns:rootfile", ns)
16
+
17
+ if rootfile is None:
18
+ rootfile = root.find(".//rootfile")
19
+
20
+ if rootfile is None:
21
+ raise ValueError("Cannot find rootfile in container.xml")
22
+
23
+ full_path = rootfile.get("full-path")
24
+ if full_path is None:
25
+ raise ValueError("rootfile element has no full-path attribute")
26
+
27
+ return Path(full_path)
28
+
29
+
30
+ def strip_namespace(elem: Element) -> None:
31
+ if elem.tag.startswith("{"):
32
+ elem.tag = elem.tag.split("}", 1)[1]
33
+
34
+ for child in elem:
35
+ strip_namespace(child)
36
+
37
+
38
+ def extract_namespace(tag: str) -> str | None:
39
+ if tag.startswith("{"):
40
+ parts = tag.split("}", 1)
41
+ if len(parts) == 2:
42
+ return parts[0][1:]
43
+ return None