Skip to content

Stop overriding the handlers in the test cases #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 22, 2013
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ OR, let's say FOO is your new favorite markup language. Simply customize your ow

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-insert` -> Turns the text green.
* class `pydocx-delete` -> Turns the text red and draws a line through the text.
* class `pydocx-center` -> Aligns the text to the center.
* class `pydocx-right` -> Aligns the text to the right.
* class `pydocx-left` -> Aligns the text to the left.
* class `pydocx-comment` -> Turns the text blue.
* class `pydocx-underline` -> Underlines the text.
34 changes: 20 additions & 14 deletions pydocx/parsers/Docx2Html.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pydocx.DocxParser import DocxParser

import xml.sax.saxutils
import textwrap


class Docx2Html(DocxParser):
Expand All @@ -21,16 +20,22 @@ def head(self):
}

def style(self):
return textwrap.dedent('''<style>.insert{{color:red}}.delete
{{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;
}}</style>''') % {
result = (
'<style>'
'.pydocx-insert {color:green;}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that in #30 we're going to fix the indentation and spacing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, what's wrong with the indentation here? This is the fix.
On May 21, 2013 3:06 PM, "Wes Winham" [email protected] wrote:

In pydocx/parsers/Docx2Html.py:

@@ -21,16 +20,22 @@ def head(self):
}

 def style(self):
  •    return textwrap.dedent('''<style>.insert{{color:red}}.delete
    
  •    {{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;
    
  •    }}</style>''') % {
    
  •    result = (
    
  •        '<style>'
    
  •        '.pydocx-insert {color:green;}'
    

I'm assuming that in #30https://github.com/OpenScienceFramework/pydocx/issues/30we're going to fix the indentation and spacing here.


Reply to this email directly or view it on GitHubhttps://github.com//pull/29/files#r4324013
.

'.pydocx-delete {color:red;text-decoration:line-through;}'
'.pydocx-center {text-align:center;}'
'.pydocx-right {text-align:right;}'
'.pydocx-left {text-align:left;}'
'.pydocx-comment {color:blue;}'
'.pydocx-underline {text-decoration: underline;}'
'body {width:%(width)spx;margin:0px auto;}'
'</style>'
) % {
#multiple by (4/3) to get to px
'width': (self.page_width * (4 / 3)),
}
#multiple by (4/3) to get to px
return result

def escape(self, text):
return xml.sax.saxutils.quoteattr(text)[1:-1]
Expand All @@ -49,7 +54,7 @@ def heading(self, text, heading_value):

def insertion(self, text, author, date):
return (
"<span class='insert' author='%(author)s' "
"<span class='pydocx-insert' author='%(author)s' "
"date='%(date)s'>%(text)s</span>"
) % {
'author': author,
Expand Down Expand Up @@ -83,7 +88,7 @@ def image(self, path, x, y):

def deletion(self, text, author, date):
return (
"<span class='delete' author='%(author)s' "
"<span class='pydocx-delete' author='%(author)s' "
"date='%(date)s'>%(text)s</span>"
) % {
'author': author,
Expand All @@ -97,8 +102,9 @@ def list_element(self, text):
}

def ordered_list(self, text, list_style):
return "<ol>%(text)s</ol>" % {
return '<ol list-style-type="%(list_style)s">%(text)s</ol>' % {
'text': text,
'list_style': list_style,
}

def unordered_list(self, text):
Expand All @@ -121,7 +127,7 @@ def tab(self):
return '&nbsp&nbsp&nbsp&nbsp'

def table(self, text):
return '<table border=1>' + text + '</table>'
return '<table border="1">' + text + '</table>'

def table_row(self, text):
return '<tr>' + text + '</tr>'
Expand All @@ -145,7 +151,7 @@ def page_break(self):
def indent(self, text, just='', firstLine='', left='', right=''):
slug = '<div'
if just:
slug += " class='%(just)s'"
slug += " class='pydocx-%(just)s'"
if firstLine or left or right:
slug += " style='"
if firstLine:
Expand Down
55 changes: 29 additions & 26 deletions pydocx/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
)
from unittest import TestCase

STYLE = (
'<style>'
'.pydocx-insert {color:green;}'
'.pydocx-delete {color:red;text-decoration:line-through;}'
'.pydocx-center {text-align:center;}'
'.pydocx-right {text-align:right;}'
'.pydocx-left {text-align:left;}'
'.pydocx-comment {color:blue;}'
'.pydocx-underline {text-decoration: underline;}'
'body {width:612px;margin:0px auto;}'
'</style>'
)

BASE_HTML = '''
<html>
<head>
%s
</head>
<body>%%s</body>
</html>
''' % STYLE


def assert_html_equal(actual_html, expected_html):
assert collapse_html(
Expand Down Expand Up @@ -78,6 +100,10 @@ def _build_data(
remove_namespaces(document_xml),
)

# This is the standard page width for a word document, Also the page
# width that we are looking for in the test.
self.page_width = 612

def _parse_rels_root(self, *args, **kwargs):
if self._test_rels_dict is None:
return {}
Expand All @@ -92,38 +118,15 @@ def get_list_style(self, num_id, ilvl):
def _parse_styles(self):
return {}

def head(self):
return ''

def table(self, text):
return '<table>' + text + '</table>'

def ordered_list(self, text, list_style):
list_type_conversions = {
'decimal': 'decimal',
'decimalZero': 'decimal-leading-zero',
'upperRoman': 'upper-roman',
'lowerRoman': 'lower-roman',
'upperLetter': 'upper-alpha',
'lowerLetter': 'lower-alpha',
'ordinal': 'decimal',
'cardinalText': 'decimal',
'ordinalText': 'decimal',
}
return '<ol data-list-type="{list_style}">{text}</ol>'.format(
list_style=list_type_conversions.get(list_style, 'decimal'),
text=text,
)


DEFAULT_NUMBERING_DICT = {
'1': {
'0': 'decimal',
'1': 'decimal',
},
'2': {
'0': 'none',
'1': 'none',
'0': 'lowerLetter',
'1': 'lowerLetter',
},
}

Expand Down Expand Up @@ -159,4 +162,4 @@ def test_expected_output(self):
numbering_dict=self.numbering_dict,
).parsed

assert_html_equal(html, self.expected_output)
assert_html_equal(html, BASE_HTML % self.expected_output)
Loading