Example #1
0
    def style(self):
        styles = {
            'body': {
                'margin': '0px auto',
            },
            'img': {
                'width': '100%',
                'height': 'auto'
            }
        }

        if self.page_width:
            width = self.page_width / constants.POINTS_PER_EM
            styles['body']['width'] = '%.2fem' % width

        result = []
        for name, definition in sorted(constants.PYDOCX_STYLES.items()):
            result.append('.pydocx-%s {%s}' % (
                name,
                convert_dictionary_to_style_fragment(definition),
            ))

        for name, definition in sorted(styles.items()):
            result.append('%s {%s}' % (
                name,
                convert_dictionary_to_style_fragment(definition),
            ))

        tag = HtmlTag('style')
        return tag.apply(''.join(result))
Example #2
0
    def export_document(self, document):
        tag = HtmlTag('document')
        if not 'footnotes' in dir(
                self
        ):  #plik parsowany jest dwukrotnie (parz first_pass w base.py)
            self.footnotes = {
            }  #przed drugim przejściem nie chcemy stracić wyników

        if not 'endnotes' in dir(self):
            self.endnotes = {}

        results = super(PyDocXHTMLExporter, self).export_document(document)
        sequence = []
        #head = self.head()
        #if head is not None:
        #  sequence.append(head)
        if len(self.footnotes) > 0:
            sequence.append(self.export_footnote_texts())

        if len(self.endnotes) > 0:
            sequence.append(self.export_endnote_texts())

        if results is not None:
            sequence.append(results)

        return tag.apply(chain(*sequence))
Example #3
0
 def export_footnote_texts(self):
     yield HtmlTag('footnotes', closed=False)
     for footnote_id, tokens in self.footnotes.items():
         yield HtmlTag('footnote', closed=False, id=footnote_id)
         for token in tokens:
             yield token
         yield HtmlTag('footnote', closed=True)
     yield HtmlTag('footnotes', closed=True)
Example #4
0
 def export_endnote_texts(self):
     yield HtmlTag('endnotes', closed=False)
     for endnote_id, tokens in self.endnotes.items():
         yield HtmlTag('endnote', closed=False, id=endnote_id)
         for token in tokens:
             yield token
         yield HtmlTag('endnote', closed=True)
     yield HtmlTag('endnotes', closed=True)
Example #5
0
 def export_numbering_span(self, numbering_span):
     results = super(PyDocXHTMLExporter,
                     self).export_numbering_span(numbering_span)
     attrs = {}
     tag_name = 'ul'
     if not numbering_span.numbering_level.is_bullet_format():
         attrs[
             'list-style-type'] = numbering_span.numbering_level.num_format
         tag_name = 'ol'
     tag = HtmlTag(tag_name, **attrs)
     return tag.apply(results)
Example #6
0
 def export_run_property_vertical_align_superscript(self, run, results):
     if results is not None:
         results = list(results)
         if len(results) == 1 and isinstance(
                 results[0],
                 HtmlTag) and (results[0].tag == "footnotemark"
                               or results[0].tag == "endnotemark"):
             yield results[0]
         elif len(results) > 0:
             yield HtmlTag(tag='sup', closed=False)
             for token in results:
                 yield token
             yield HtmlTag(tag='sup', closed=True)
Example #7
0
    def export_bookmark(self, bookmark):
        # Check if this method is implement in parent classes
        results = getattr(super, 'export_bookmark', None)

        attrs = {}

        bookmark_name = self.get_bookmark_name(bookmark)

        if bookmark_name:
            attrs['id'] = bookmark_name

            tag = HtmlTag('a', **attrs)

            return tag.apply(results, allow_empty=True)
Example #8
0
 def export_endnote_reference(self, endnote_reference):
     ftokens = chain(
         *(list(self.node_type_to_export_func_map[type(child)](child))
           for child in endnote_reference.endnote.children))
     self.endnotes[endnote_reference.endnote_id] = [
         token for token in ftokens if token != '\t'
     ]
     yield HtmlTag(tag="endnotemark",
                   id=endnote_reference.endnote_id,
                   allow_self_closing=True)
Example #9
0
def tokens_without_nested_paras(stream):
    opened_para = False

    for token in stream:
        if isinstance(token, HtmlTag) and token.tag == "p":
            if token.closed:
                if opened_para:  #zamykaj tag tylko wtedy, gdy jest otwarty
                    yield token
                opened_para = False
            else:  #napotykam otwarcie paragrafu
                if opened_para:
                    yield HtmlTag(tag="p", closed=True)
                opened_para = True
                yield token
        else:
            yield token
Example #10
0
def ct(tagname):
    return HtmlTag(tag=tagname, closed=True)
Example #11
0
def ot(tagname):
    return HtmlTag(tag=tagname)
Example #12
0
    def export_textbox(self, textbox):
        results = super(PyDocXHTMLExporterNotesMixin, self).export_textbox(textbox)

        tag = HtmlTag(self.NOTES_WRAPPER_TAG_NAME, **self.get_textbox_attributes(textbox))

        return tag.apply(results)
Example #13
0
 def export_run_property_strike(self, run, results):
     tag = HtmlTag('strike')
     return self.export_run_property(tag, run, results)
Example #14
0
 def export_run_property_underline(self, run, results):
     tag = HtmlTag('underline')
     return self.export_run_property(tag, run, results)