From e3d7a19690ad3460b31a20a464cb1de76dad8c3c Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 12:07:18 -0400 Subject: [PATCH 1/8] refs #28: update all the tests --- pydocx/tests/test_docx.py | 12 ++++++------ pydocx/tests/test_xml.py | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pydocx/tests/test_docx.py b/pydocx/tests/test_docx.py index ab00db5d..cc2094af 100644 --- a/pydocx/tests/test_docx.py +++ b/pydocx/tests/test_docx.py @@ -144,7 +144,7 @@ def test_inline_tags(): ) actual_html = convert(file_path) assert_html_equal(actual_html, ''' -

This sentence has some bold, some italics and some underline, as well as a hyperlink.

''') # noqa +

This sentence has some bold, some italics and some underline, as well as a hyperlink.

''') # noqa def test_unicode(): @@ -639,16 +639,16 @@ def test_shift_enter(): actual_html = convert(file_path) assert_html_equal(actual_html, ''' -

AAA
BBB

+

AAA
BBB

CCC

    -
  1. DDD
    EEE
  2. +
  3. DDD
    EEE
  4. FFF
- - + + @@ -767,7 +767,7 @@ def test_simple_table(): assert_html_equal(actual_html, '''
GGG
HHH
III
JJJ
GGG
HHH
III
JJJ
KKK
-
Cell1
Cell3
Cell2
+
Cell1
Cell3
Cell2
And I am writing in the table
Cell4
diff --git a/pydocx/tests/test_xml.py b/pydocx/tests/test_xml.py index c1a5bf8a..cbb4a9a3 100644 --- a/pydocx/tests/test_xml.py +++ b/pydocx/tests/test_xml.py @@ -16,7 +16,7 @@ class BoldTestCase(_TranslationTestCase): expected_output = """ -

AAA

+

AAA

BBB

""" @@ -121,7 +121,7 @@ class HyperlinkWithBreakTestCase(_TranslationTestCase): expected_output = ''' -

link

+

link

''' @@ -382,7 +382,7 @@ class TableWithListAndParagraph(_TranslationTestCase):
  • AAA
  • BBB
  • - CCC
    + CCC
    DDD @@ -478,7 +478,7 @@ class ListWithContinuationTestCase(_TranslationTestCase): expected_output = '''
      -
    1. AAA
      BBB
    2. +
    3. AAA
      BBB
    4. CCC @@ -775,7 +775,7 @@ class MissingIlvl(_TranslationTestCase): expected_output = '''
        -
      1. AAA
        +
      2. AAA
        BBB
      3. CCC
      4. From e4fafa52852016c5a7121b431dc59a09b10af607 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 12:07:27 -0400 Subject: [PATCH 2/8] refs #28: update the parser --- pydocx/parsers/Docx2Html.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pydocx/parsers/Docx2Html.py b/pydocx/parsers/Docx2Html.py index f97e39be..db438937 100644 --- a/pydocx/parsers/Docx2Html.py +++ b/pydocx/parsers/Docx2Html.py @@ -109,13 +109,13 @@ def unordered_list(self, text): } def bold(self, text): - return '' + text + '' + return '' + text + '' def italics(self, text): - return '' + text + '' + return '' + text + '' def underline(self, text): - return '' + text + '' + return '' + text + '' def tab(self): # Insert before the text right?? So got the text and just do an insert @@ -142,7 +142,7 @@ def table_cell(self, text, col='', row=''): } def page_break(self): - return '
        ' + return '
        ' def indent(self, text, just='', firstLine='', left='', right=''): slug = '' + return '
        ' From 404b39533cd508253d1caab3c541fbde6b3d876f Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 12:32:15 -0400 Subject: [PATCH 3/8] refs #28: removed pre-processing, maybe travis will run this time? --- pydocx/parsers/Docx2Html.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pydocx/parsers/Docx2Html.py b/pydocx/parsers/Docx2Html.py index db438937..e342a04d 100644 --- a/pydocx/parsers/Docx2Html.py +++ b/pydocx/parsers/Docx2Html.py @@ -9,9 +9,6 @@ class Docx2Html(DocxParser): @property def parsed(self): content = self._parsed - content = content.replace('

        ', '
        ') - content = content.replace('


        ', '

        ') - content = content.replace('


          ', '

            ') content = "%(head)s%(content)s" % { 'head': self.head(), 'content': content, From 8f387f39892ef0e9d2981447a4228f077293f6af Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 14:09:34 -0400 Subject: [PATCH 4/8] refs #28: updated test based on merged master --- pydocx/tests/test_xml.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pydocx/tests/test_xml.py b/pydocx/tests/test_xml.py index 0b09a84f..c0703c45 100644 --- a/pydocx/tests/test_xml.py +++ b/pydocx/tests/test_xml.py @@ -722,7 +722,7 @@ class DeleteTagInList(_TranslationTestCase): expected_output = '''
              -
            1. AAA
              +
            2. AAA
              BBB
            3. CCC
            4. @@ -746,7 +746,7 @@ class InsertTagInList(_TranslationTestCase): expected_output = '''
                -
              1. AAA
                +
              2. AAA
                BBB
              3. CCC
              4. @@ -771,7 +771,7 @@ class SmartTagInList(_TranslationTestCase): expected_output = '''
                  -
                1. AAA
                  +
                2. AAA
                  BBB
                3. CCC
                4. From 1c72947f4370d779822d175d9ba825411b4fc333 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 14:12:33 -0400 Subject: [PATCH 5/8] refs #28: updated tests based on merged master --- pydocx/tests/test_xml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydocx/tests/test_xml.py b/pydocx/tests/test_xml.py index 48c16cbd..fb1a47fe 100644 --- a/pydocx/tests/test_xml.py +++ b/pydocx/tests/test_xml.py @@ -923,7 +923,7 @@ class SDTTestCase(_TranslationTestCase): expected_output = '''
                    -
                  1. AAA
                    +
                  2. AAA
                    BBB
                  3. CCC
                  4. From e254e81b5fbd2fcef8117d752d9bf2411d762fbb Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 14:20:29 -0400 Subject: [PATCH 6/8] refs #28: split up a line into multiple lines --- pydocx/tests/test_docx.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pydocx/tests/test_docx.py b/pydocx/tests/test_docx.py index cc2094af..9db462d0 100644 --- a/pydocx/tests/test_docx.py +++ b/pydocx/tests/test_docx.py @@ -143,8 +143,13 @@ def test_inline_tags(): 'inline_tags.docx', ) actual_html = convert(file_path) - assert_html_equal(actual_html, ''' -

                    This sentence has some bold, some italics and some underline, as well as a hyperlink.

                    ''') # noqa + assert_html_equal(actual_html, ( + '

                    This sentence has some bold, ' + 'some italics and some ' + 'underline, ' + 'as well as a hyperlink' + '.

                    ' + )) def test_unicode(): From 04c407dc913595010779477d92fa8795e44c9690 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 14:22:13 -0400 Subject: [PATCH 7/8] refs #28: updated how we are doing underline --- pydocx/parsers/Docx2Html.py | 3 ++- pydocx/tests/test_docx.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pydocx/parsers/Docx2Html.py b/pydocx/parsers/Docx2Html.py index e342a04d..9aa78354 100644 --- a/pydocx/parsers/Docx2Html.py +++ b/pydocx/parsers/Docx2Html.py @@ -25,6 +25,7 @@ def style(self): {{color:red; text-decoration:line-through}}.center {{text-align:center}}.right{{text-align:right}} .left{{text-align:left}} .comment{{color:blue}} + .pydocx-underline {text-decoration: underline;} body{{width:%(width)spx; margin:0px auto; }}''') % { 'width': (self.page_width * (4 / 3)), @@ -112,7 +113,7 @@ def italics(self, text): return '' + text + '' def underline(self, text): - return '' + text + '' + return '' + text + '' def tab(self): # Insert before the text right?? So got the text and just do an insert diff --git a/pydocx/tests/test_docx.py b/pydocx/tests/test_docx.py index 9db462d0..815d2ef2 100644 --- a/pydocx/tests/test_docx.py +++ b/pydocx/tests/test_docx.py @@ -146,7 +146,7 @@ def test_inline_tags(): assert_html_equal(actual_html, ( '

                    This sentence has some bold, ' 'some italics and some ' - 'underline, ' + 'underline, ' 'as well as a hyperlink' '.

                    ' )) From 8c5b39ccf694a02831916d13d45322e2c8e5d4bc Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 14:26:49 -0400 Subject: [PATCH 8/8] refs #28: Added css stuff to the README --- README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4453cf8..91bd33e3 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,7 @@ DocxParser includes abstracts methods that each parser overwrites to satsify its @abstractmethod def table(self, text): - return text - + return text @abstractmethod def table_row(self, text): return text @@ -161,4 +160,16 @@ OR, let's say FOO is your new favorite markup language. Simply customize your ow def linebreak(self): return '!!!!!!!!!!!!' # because linebreaks in are denoted by '!!!!!!!!!!!!' - # with the FOO markup langauge :) \ No newline at end of file + # with the FOO markup langauge :) + +#Styles + +The base parser `Docx2Html` relies on certain css class being set for certain behaviour to occur. Currently these include: + +* class `insert` -> Turns the text green. +* class `delete` -> Turns the text red and draws a line through the text. +* class `center` -> Aligns the text to the center. +* class `right` -> Aligns the text to the right. +* class `left` -> Aligns the text to the left. +* class `comment` -> Turns the text blue. +* class `pydocx-underline` -> Underlines the text.