Skip to content

Commit

Permalink
Fix bug in mdpo2html implementation with non-markdown attributes of l…
Browse files Browse the repository at this point in the history
…inks. Optimize a bit.
  • Loading branch information
mondeja committed Nov 5, 2020
1 parent 69ab852 commit 9d6aba9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mdpo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from mdpo.po2md import pofile_to_markdown


__version__ = '0.3.1'
__version__ = '0.3.2'
__version_info__ = tuple([int(i) for i in __version__.split('.')])
__title__ = 'mdpo'
__description__ = ('Markdown file translation utilities using pofiles')
Expand Down
6 changes: 3 additions & 3 deletions mdpo/md2po/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ def text(self, block, text):
self._current_msgid[self._codespan_start_index:])
elif text == self.italic_start_string:
text = self.italic_start_string_escaped
elif text == self.italic_end_string:
text = self.italic_end_string_escaped
elif text == self.code_start_string:
text = self.code_start_string_escaped
elif text == self.code_end_string:
elif text == self.italic_end_string: # pragma: no cover
text = self.italic_end_string_escaped
elif text == self.code_end_string: # pragma: no cover
text = self.code_end_string_escaped
if self._inside_pblock:
text = text.replace("\n", " ")
Expand Down
19 changes: 10 additions & 9 deletions mdpo/mdpo2html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,18 @@ def _process_replacer(self):

raw_html_template += '<%s' % handled

attrs_except_href_title = []
# attrs_except_href_title = []
for attr, value in attrs:
if attr in ['title', 'href']:
raw_html_template += ' %s="{}"' % attr
else:
attrs_except_href_title.append(attr)
raw_html_template += html_attrs_tuple_to_string(
attrs_except_href_title) + '>'
# else:
# These attributes are not included in output
# attrs_except_href_title.append((attr, value))
# if attrs_except_href_title:
# raw_html_template += ' '
# raw_html_template += html_attrs_tuple_to_string(
# attrs_except_href_title) + '>'
raw_html_template += '>'
else:
raw_html_template += '<%s%s>' % (
handled,
Expand All @@ -161,10 +165,7 @@ def _process_replacer(self):

if all((ch in ALIGNMENT_CHARS) for ch in handled):
raw_html_template += handled
if _last_start_tag in self.markup_tags:
_current_replacement += handled
else:
_current_replacement += handled
_current_replacement += handled
else:
raw_html_template += '{}'
if _current_link_target:
Expand Down
6 changes: 3 additions & 3 deletions mdpo/po2md/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,12 @@ def text(self, block, text):
self._current_msgid[self._codespan_start_index:])
elif text == self.italic_start_string:
text = self.italic_start_string_escaped
elif text == self.italic_end_string:
text = self.italic_end_string_escaped
elif text == self.code_start_string:
text = self.code_start_string_escaped
elif text == self.code_end_string:
elif text == self.code_end_string: # pragma: no cover
text = self.code_end_string_escaped
elif text == self.italic_end_string: # pragma: no cover
text = self.italic_end_string_escaped

if self._inside_pblock:
text = text.replace("\n", " ")
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[bumpversion]
current_version = 0.3.1
current_version = 0.3.2

[bumpversion:file:mdpo/__init__.py]

[coverage:report]
exclude_lines =
pragma: no cover
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
except ImportError:
if '-h' in args or '--help' in args:
Expand Down
2 changes: 2 additions & 0 deletions test/test_mdpo2html/translate-examples/markuptext/a.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<p>Some text followed by <a href="https://fake.fake">a link</a>.</p>

<p><a href="some/place" title="a title">When the link</a> starts the text.</p>

<p><a class="hello" href="https://fake.fake">Link with class</a>.</p>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<p>Algo de texto seguido de <a href="https://falso.falsa">un enlace</a>.</p>

<p><a href="algun/lugar" title="un título">Cuando el enlace</a> comienza el texto.</p>

<p><a href="https://falso.falsa">Link con clase</a>.</p>
3 changes: 3 additions & 0 deletions test/test_mdpo2html/translate-examples/markuptext/a.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ msgstr "Algo de texto seguido de [un enlace](https://falso.falsa)."

msgid "[When the link](some/place \"a title\") starts the text."
msgstr "[Cuando el enlace](algun/lugar \"un título\") comienza el texto."

msgid "[Link with class](https://fake.fake)."
msgstr "[Link con clase](https://falso.falsa)."

0 comments on commit 9d6aba9

Please sign in to comment.