Skip to content

Commit c407dea

Browse files
Benjamin TBenjamin-T
authored andcommitted
no message
1 parent 1871043 commit c407dea

6 files changed

Lines changed: 59 additions & 1 deletion

File tree

docx/oxml/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def register_element_cls(tag, cls):
3737
"""
3838
nspfx, tagroot = tag.split(':')
3939
namespace = element_class_lookup.get_namespace(nsmap[nspfx])
40+
4041
namespace[tagroot] = cls
4142

4243

@@ -66,6 +67,9 @@ def OxmlElement(nsptag_str, attrs=None, nsdecls=None):
6667

6768
from .shared import CT_DecimalNumber, CT_OnOff, CT_String
6869

70+
from .math import CT_OMath, CT_OMathPara
71+
register_element_cls('m:oMath', CT_OMath)
72+
register_element_cls('m:oMathPara', CT_OMathPara)
6973

7074
from .coreprops import CT_CoreProperties
7175
register_element_cls('cp:coreProperties', CT_CoreProperties)
@@ -203,3 +207,7 @@ def OxmlElement(nsptag_str, attrs=None, nsdecls=None):
203207
register_element_cls('w:br', CT_Br)
204208
register_element_cls('w:r', CT_R)
205209
register_element_cls('w:t', CT_Text)
210+
211+
212+
213+

docx/oxml/math.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Custom element classes related to paragraphs (CT_P).
5+
"""
6+
7+
8+
from docx.oxml.xmlchemy import BaseOxmlElement
9+
10+
11+
class CT_OMath(BaseOxmlElement):
12+
"""
13+
``<m:oMath>`` element, containing math contents.
14+
"""
15+
16+
class CT_OMathPara(BaseOxmlElement):
17+
"""
18+
``<m:oMathPara>`` element, containing math contents.
19+
"""
20+

docx/oxml/ns.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'dcmitype': ('http://purl.org/dc/dcmitype/'),
1717
'dcterms': ('http://purl.org/dc/terms/'),
1818
'dgm': ('http://schemas.openxmlformats.org/drawingml/2006/diagram'),
19+
'm': ('http://schemas.openxmlformats.org/officeDocument/2006/math'),
1920
'pic': ('http://schemas.openxmlformats.org/drawingml/2006/picture'),
2021
'r': ('http://schemas.openxmlformats.org/officeDocument/2006/relations'
2122
'hips'),

docx/oxml/text/paragraph.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class CT_P(BaseOxmlElement):
1414
"""
1515
pPr = ZeroOrOne('w:pPr')
1616
r = ZeroOrMore('w:r')
17+
oMath = ZeroOrMore('m:oMath')
18+
oMathPara = ZeroOrMore('m:oMathPara')
1719

1820
def _insert_pPr(self, pPr):
1921
self.insert(0, pPr)

docx/text/math.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Run-related proxy objects for python-docx, Run in particular.
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
from ..shared import Parented
10+
11+
class Equation(Parented):
12+
"""
13+
"""
14+
def __init__(self, eq, parent):
15+
super(Equation, self).__init__(parent)
16+
self._eq = self._element = self.element = eq
17+
18+
@property
19+
def raw_xml(self):
20+
return self._eq.xml
21+

docx/text/paragraph.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .parfmt import ParagraphFormat
1313
from .run import Run
1414
from ..shared import Parented
15-
15+
from .math import Equation
1616

1717
class Paragraph(Parented):
1818
"""
@@ -92,6 +92,12 @@ def runs(self):
9292
"""
9393
return [Run(r, self) for r in self._p.r_lst]
9494

95+
@property
96+
def equations(self):
97+
"""
98+
"""
99+
return [Equation(eq, self) for eq in self._p.oMathPara_lst]
100+
95101
@property
96102
def style(self):
97103
"""

0 commit comments

Comments
 (0)