Text converter updated.
[librarian.git] / src / librarian / elements / styles / mat.py
1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 from copy import copy
5 from ..base import WLElement
6
7
8 class Mat(WLElement):
9     STRIP = True
10
11     def html_build(self, builder):
12         e = copy(self)
13         e.tag = 'math'
14         e.attrib['xmlns'] = 'http://www.w3.org/1998/Math/MathML'
15         builder.cursor.append(e)
16
17     def epub_build(self, builder):
18         builder.start_element('img', {"src": builder.mathml(self)})
19         builder.end_element()
20
21
22 class M(WLElement):
23     STRIP = True
24
25
26 class MRow(M):
27     pass
28
29
30 class MFenced(M):
31     TXT_PREFIX = '('
32     TXT_SUFFIX = ')'
33
34
35 class MFrac(M):
36     TXT_PREFIX = '('
37     TXT_SUFFIX = ')'
38
39     def txt_after_child(self, builder, child_count):
40         if child_count:
41             builder.push_text(') / (')
42
43
44 class MSup(M):
45     def txt_after_child(self, builder, child_count):
46         if child_count:
47             builder.push_text(' ^ ')