(self, dictionary, filename, mode = None, style = False)
| 205 | |
| 206 | # 导出 Mdx 源文件,然后可以用 MdxBuilder 转换成 .mdx词典 |
| 207 | def compile_mdx (self, dictionary, filename, mode = None, style = False): |
| 208 | words = stardict.tools.dump_map(dictionary, False) |
| 209 | fp = codecs.open(filename, 'w', 'utf-8') |
| 210 | text2html = self.text2html |
| 211 | pc = stardict.tools.progress(len(words)) |
| 212 | if mode is None: |
| 213 | mode = ('name', 'phonetic') |
| 214 | count = 0 |
| 215 | stripword = stardict.stripword |
| 216 | words = [ k for k in words ] |
| 217 | words.sort(key = lambda x: stripword(x)) |
| 218 | for word in words: |
| 219 | pc.next() |
| 220 | data = dictionary[word] |
| 221 | phonetic = data['phonetic'] |
| 222 | translation = data['translation'] |
| 223 | if not translation: |
| 224 | translation = data['definition'] |
| 225 | if not translation: |
| 226 | continue |
| 227 | # if pc.count >= 100000: |
| 228 | # break |
| 229 | head = self.word_level(data) |
| 230 | tag = self.word_tag(data) |
| 231 | fp.write(word.replace('\r', '').replace('\n', '') + '\r\n') |
| 232 | if 'name' in mode: |
| 233 | if not style: |
| 234 | fp.write('<b style="font-size:180%%;">%s'%text2html(word)) |
| 235 | fp.write('</b></br></br>\r\n') |
| 236 | else: |
| 237 | fp.write('`1`%s`2``2`\r\n'%text2html(word)) |
| 238 | if 'phonetic' in mode: |
| 239 | if phonetic or head: |
| 240 | if phonetic: |
| 241 | if not style: |
| 242 | fp.write('<font color=dodgerblue>') |
| 243 | fp.write(text2html(u'[%s]'%phonetic)) |
| 244 | fp.write('</font>') |
| 245 | else: |
| 246 | fp.write('`3`' + text2html(u'[%s]'%phonetic)) |
| 247 | if head: |
| 248 | if phonetic: |
| 249 | fp.write(' ') |
| 250 | if not style: |
| 251 | fp.write('<font color=gray>') |
| 252 | fp.write(text2html(u'-%s'%head)) |
| 253 | fp.write('</font>') |
| 254 | else: |
| 255 | fp.write('`4`' + text2html(u'-%s'%head)) |
| 256 | if not style: |
| 257 | fp.write('</br></br>\r\n') |
| 258 | else: |
| 259 | fp.write('`2``2`\r\n') |
| 260 | for line in translation.split('\n'): |
| 261 | line = line.rstrip('\r\n ') |
| 262 | fp.write(text2html(line) + ' </br>\r\n') |
| 263 | if (not 'phonetic' in mode) and head: |
| 264 | if tag: |
nothing calls this directly
no test coverage detected