Skip to content

Commit

Permalink
Fix markdown translation file compiling error.
Browse files Browse the repository at this point in the history
Will affect both markdown v1 & v2. The problem that solves is the mismatch
of hashes (template replacement) during parsing step and compiling step, due
to inconsistency of handling.
  • Loading branch information
fathineos committed Oct 3, 2017
1 parent 2dcac28 commit 6be048c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions openformats/formats/github_markdown.py
Expand Up @@ -182,6 +182,12 @@ def parse(self, content, **kwargs):
if newline_type == 'DOS':
content = force_newline_type(content, 'UNIX')

# mistune expands tabs to 4 spaces and trims trailing spaces, so we
# need to do the same in order to be able to match the substrings
template = content.expandtabs(4)
pattern = re.compile(r'^ +$', re.M)
content = pattern.sub('', template)

template = content
stringset = []

Expand Down
2 changes: 1 addition & 1 deletion openformats/formats/github_markdown_v2.py
Expand Up @@ -80,7 +80,7 @@ def parse(self, content, **kwargs):
# need to do the same in order to be able to match the substrings
template = content.expandtabs(4)
pattern = re.compile(r'^ +$', re.M)
template = pattern.sub('', template)
content = pattern.sub('', template)

stringset = []

Expand Down
Expand Up @@ -7,3 +7,10 @@
class GithubMarkdownTestCase(CommonFormatTestMixin, unittest.TestCase):
HANDLER_CLASS = GithubMarkdownHandler
TESTFILE_BASE = "openformats/tests/formats/github_markdown/files"

def test_parse(self):
"""Test parse converts tabs to spaces"""

content_with_tab = self.handler.parse(content=u"# foo bar")
content_with_spaces = self.handler.parse(content=u"# foo bar")
self.assertEqual(content_with_tab[0], content_with_spaces[0])
Expand Up @@ -23,3 +23,9 @@ def test_compile(self):
"""Test that import-export is the same as the original file."""
remade_orig_content = self.handler.compile(self.tmpl, self.strset)
self.assertEquals(remade_orig_content, self.data["1_en_export"])

def test_parse(self):
"""Test parse converts tabs to spaces"""
content_with_tab = self.handler.parse(content=u"# foo bar")
content_with_spaces = self.handler.parse(content=u"# foo bar")
self.assertEqual(content_with_tab[0], content_with_spaces[0])

0 comments on commit 6be048c

Please sign in to comment.