def WriteSingleline(self, parent, data): ls = len(data) cnt = 0 textstart = 0 i = -1 for i in xrange(ls): if data[i] == ' ': if cnt == 0: # We found the first space. Now print the text before parent.addText(data[textstart:i]) cnt = 0 textstart = i cnt = cnt + 1 else: # We didn't see a space # If there are unprinted spaces, print them now, if there are, then we're at text-start if cnt > 0: parent.addText(' ') if cnt > 1: parent.addElement(S(c=cnt - 1)) if cnt > 0: cnt = 0 textstart = i if cnt > 0: parent.addText(' ') if cnt > 1: parent.addElement(S(c=cnt - 1)) elif i != -1: parent.addText(data[textstart:i + 1])
def _get_cell_string_value(self, cell) -> str: """ Find and decode OpenDocument text:s tags that represent a run length encoded sequence of space characters. """ from odf.element import Element from odf.namespaces import TEXTNS from odf.text import S text_s = S().qname value = [] for fragment in cell.childNodes: if isinstance(fragment, Element): if fragment.qname == text_s: spaces = int(fragment.attributes.get((TEXTNS, "c"), 1)) value.append(" " * spaces) else: # recursive impl needed in case of nested fragments # with multiple spaces # https://github.com/pandas-dev/pandas/pull/36175#discussion_r484639704 value.append(self._get_cell_string_value(fragment)) else: value.append(str(fragment)) return "".join(value)
def _emitSpaces(self, odfElement): """ Creates a <text:s> element for the current spaceCount. Side effect: sets spaceCount back to zero """ if self.spaceCount > 0: spaceElement = S(c=self.spaceCount) odfElement.addElement(spaceElement) self.spaceCount = 0
def _code_line(self, line): """Add a code line.""" assert self._containers container = self._containers[-1] # Handle extra spaces. text = line while text: if text.startswith(' '): r = re.match(r'(^ +)', text) n = len(r.group(1)) container.addElement(S(c=n)) text = text[n:] elif ' ' in text: assert not text.startswith(' ') i = text.index(' ') container.addElement(Span(text=text[:i])) text = text[i:] else: container.addElement(Span(text=text)) text = ''
def _get_cell_string_value(self, cell) -> str: """ Find and decode OpenDocument text:s tags that represent a run length encoded sequence of space characters. """ from odf.element import Element, Text from odf.namespaces import TEXTNS from odf.text import P, S text_p = P().qname text_s = S().qname p = cell.childNodes[0] value = [] if p.qname == text_p: for k, fragment in enumerate(p.childNodes): if isinstance(fragment, Text): value.append(fragment.data) elif isinstance(fragment, Element): if fragment.qname == text_s: spaces = int(fragment.attributes.get((TEXTNS, "c"), 1)) value.append(" " * spaces) return "".join(value)
</text:note-body> </text:note> <text:s text:c="2"/>Where does the text after a footnote go?</text:p> """ textdoc.text.addElement(H(outlinelevel=1,text='Footnotes (Heading 1)')) p = P() textdoc.text.addElement(p) p.addText("This sentence has an accompanying footnote.") note = Note(id="ftn0", noteclass="footnote") p.addElement(note) note.addElement(NoteCitation(text='1')) notebody = NoteBody() note.addElement(notebody) notebody.addElement(P(stylename="Footnote", text="You are reading a footnote.")) p.addElement(S(c=2)) p.addText("Where does the text after a footnote go?") # Insert the photo """ <text:h text:outline-level="1">An Image</text:h> <text:p> <draw:frame draw:name="graphics1" text:anchor-type="paragraph" svg:width="5in" svg:height="6.6665in" draw:z-index="0"> <draw:image xlink:href="Pictures/campanile_fog.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> </draw:frame> </text:p>