Skip to content

Commit

Permalink
Don't wrap long links into multiple lines (#148)
Browse files Browse the repository at this point in the history
* Fix long links wrapping
  • Loading branch information
mondeja committed Jul 8, 2021
1 parent a82e66b commit 57a2790
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.53
current_version = 0.3.54

[bumpversion:file:mdpo/__init__.py]

Expand Down
6 changes: 2 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ repos:
rev: v4.0.1
hooks:
- id: trailing-whitespace
name: trailing-whitespace
- id: end-of-file-fixer
name: end-of-file-fixer
- id: double-quote-string-fixer
name: double-quote-string-fixer
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
hooks:
- id: add-trailing-comma
name: add-trailing-comma
args:
- --py36-plus
- repo: https://github.com/asottile/setup-cfg-fmt
Expand Down Expand Up @@ -95,3 +91,5 @@ repos:
rev: 2.3.5
hooks:
- id: editorconfig-checker
args:
- -exclude=docs/.+\.bat
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.53'
__version__ = '0.3.54'
__title__ = 'mdpo'
__description__ = ('Markdown file translation utilities using PO files')
__all__ = (
Expand Down
10 changes: 9 additions & 1 deletion mdpo/po2md/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Po2Md:
'_codespan_start_index',
'_codespan_backticks',
'_codespan_inside_current_msgid',
'_aspan_inside_current_msgid',
'_inside_quoteblock',
'_current_aspan_target',
'_current_aspan_href',
Expand Down Expand Up @@ -213,6 +214,7 @@ def __init__(self, pofiles, ignore=[], po_encoding=None, **kwargs):
self._current_aspan_href = None
self._link_references = None
self._current_imgspan = {}
self._aspan_inside_current_msgid = False

# current table head alignments
self._current_thead_aligns = []
Expand Down Expand Up @@ -341,7 +343,10 @@ def _save_current_msgid(self):
translation = '\n'.join(lines)
elif self._inside_pblock:
# wrap paragraphs fitting with markdownlint
if self._codespan_inside_current_msgid:
if (
self._codespan_inside_current_msgid
or self._aspan_inside_current_msgid
):
# fix codespans wrapping
lines = fixwrap_codespans(
translation.split('\n'),
Expand All @@ -365,6 +370,7 @@ def _save_current_msgid(self):

self._codespan_inside_current_msgid = False
self._aimg_title_inside_current_msgid = False
self._aspan_inside_current_msgid = False

def _save_current_line(self):
# strip all spaces according to unicodedata database ignoring newlines,
Expand Down Expand Up @@ -614,6 +620,8 @@ def enter_span(self, span, details):
pass

if span is md4c.SpanType.A:
self._aspan_inside_current_msgid = True

if self._link_references is None:
self._link_references = parse_link_references(self.content)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = mdpo
version = 0.3.53
version = 0.3.54
description = Markdown file translation utilities using PO files.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
2 changes: 2 additions & 0 deletions test/test_po2md/translate-examples/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Visit <https://www.github.com/mondeja/mdpo>

Write an email to <fake@example.com> if you want help.

A [link](https://so-long-long-long-long-long-long-long-long-that-should-not-be-wrapped-in-multiple.lines).

[Reference A][1]

[Reference B][2]
Expand Down
3 changes: 3 additions & 0 deletions test/test_po2md/translate-examples/links.md.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Visita <https://www.github.com/mondeja/mdpo>
Escribe un correo electrónico a [fake@example.com](mailto:fake@example.com) si
quieres ayuda.

Un
[enlace](https://tan-tan-tan-tan-tan-tan-tan-tan-largo-que-no-debe-ser-envuelto-en-multiples.lineas).

[Referencia A][1]

[Referencia B][2]
Expand Down
7 changes: 7 additions & 0 deletions test/test_po2md/translate-examples/links.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ msgstr ""
"Escribe un correo electrónico a [fake@example.com](mailto:fake@example.com) "
"si quieres ayuda."

msgid ""
"A [link](https://so-long-long-long-long-long-long-long-long-that-should-not-"
"be-wrapped-in-multiple.lines)."
msgstr ""
"Un [enlace](https://tan-tan-tan-tan-tan-tan-tan-tan-largo-que-no-debe-ser-"
"envuelto-en-multiples.lineas)."

msgid "[Reference A][1]"
msgstr "[Referencia A][1]"

Expand Down

0 comments on commit 57a2790

Please sign in to comment.