Skip to content

Commit

Permalink
Fix wrapping errors in po2md
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Jul 14, 2021
1 parent c183614 commit 3798ccc
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 7 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.60
current_version = 0.3.61

[bumpversion:file:mdpo/__init__.py]

Expand Down
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.60'
__version__ = '0.3.61'
__title__ = 'mdpo'
__description__ = ('Markdown file translation utilities using PO files')
__all__ = (
Expand Down
14 changes: 10 additions & 4 deletions mdpo/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,22 @@ def _chars_num_until_next_codespan_exit(text):

return n

# Response
response = []
_width = first_line_width

# State
_curr_line = ''

_entering_codespan, _exiting_codespan, _inside_codespan = (
False, False, False,
)
_codespan_n_backticks_wrapper, _n_backticks_to_exit_codespan = (0, None)
_entering_codespan = False
_exiting_codespan = False
_inside_codespan = False

_codespan_n_backticks_wrapper = 0
_n_backticks_to_exit_codespan = None

prev_char = None

for li, line in enumerate(lines):
for ci, ch in enumerate(line):
if not _inside_codespan:
Expand Down
3 changes: 3 additions & 0 deletions mdpo/po2md/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def _save_current_msgid(self):
width=self.wrapwidth,
first_line_width_diff=first_line_width_diff,
break_long_words=False,
break_on_hyphens=False,
)
translation = '\n'.join(lines)
elif self._inside_pblock:
Expand All @@ -385,12 +386,14 @@ def _save_current_msgid(self):
lines = fixwrap_codespans(
translation.split('\n'),
width=self.wrapwidth,
first_line_width=self.wrapwidth,
)
else:
lines = textwrap.wrap(
translation,
width=self.wrapwidth,
break_long_words=False,
break_on_hyphens=False,
)
translation = '\n'.join(lines) + '\n'
self._current_line += translation
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.60
version = 0.3.61
description = Markdown files translation 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/wrapwidth-examples/paragraphs.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Some long text that could wrap if the wrap width parameter is lower than its length.

Some more long text that contains `a code span` and a [long long long long long link whose target shouldn't be wrapped-in-multiple-lines](#123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789).
21 changes: 21 additions & 0 deletions test/test_po2md/wrapwidth-examples/paragraphs.md.10.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@ de ancho
es menor
que su
largo.

Also más
de texto
largo que
contiene
`un código en línea`
y un
[largo
largo
largo
largo
largo
enlace
cuyo
objetivo
no debería
ser
envuelto
en
múltiples
líneas](#123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789).
6 changes: 6 additions & 0 deletions test/test_po2md/wrapwidth-examples/paragraphs.md.40.expect.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Algo de texto largo que debería
envolverse si el parámetro de envoltura
de ancho es menor que su largo.

Also más de texto largo que contiene
`un código en línea` y un [largo largo
largo largo largo enlace cuyo objetivo
no debería ser envuelto en múltiples
líneas](#123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789).
4 changes: 4 additions & 0 deletions test/test_po2md/wrapwidth-examples/paragraphs.md.80.expect.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
Algo de texto largo que debería envolverse si el parámetro de envoltura de ancho
es menor que su largo.

Also más de texto largo que contiene `un código en línea` y un [largo largo
largo largo largo enlace cuyo objetivo no debería ser envuelto en múltiples
líneas](#123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789).
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Algo de texto largo que debería envolverse si el parámetro de envoltura de ancho es menor que su largo.

Also más de texto largo que contiene `un código en línea` y un [largo largo largo largo largo enlace cuyo objetivo no debería ser envuelto en múltiples líneas](#123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789).
9 changes: 9 additions & 0 deletions test/test_po2md/wrapwidth-examples/paragraphs.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ msgid ""
msgstr ""
"Algo de texto largo que debería envolverse si el parámetro de envoltura de"
" ancho es menor que su largo."

msgid ""
"Some more long text that contains `a code span` and a [long long long long "
"long link whose target shouldn't be wrapped-in-multiple-"
"lines](#123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789)."
msgstr ""
"Also más de texto largo que contiene `un código en línea` y un [largo largo "
"largo largo largo enlace cuyo objetivo no debería ser envuelto en múltiples "
"líneas](#123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789)."
1 change: 1 addition & 0 deletions test/test_po2md/wrapwidth-examples/ul.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- 34 6 8 0 broken text
- A list item that should wrap ignoring the mark width
- Another list item that should wrap ignoring the mark width
- [Can I run multiple instances of MyApp on the same host machine?](#can-i-run-multiple-instances-of-myapp-on-the-same-host-machine)
10 changes: 10 additions & 0 deletions test/test_po2md/wrapwidth-examples/ul.md.10.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ ignorando
el ancho
de la
marca
- [¿Puedo
ejecutar
múltiples
instancias
de MyApp
en la
misma
máquina
del
host?](#puedo-ejecutar-multiples-instancias-de-myapp-en-la-misma-maquina-de-host)
3 changes: 3 additions & 0 deletions test/test_po2md/wrapwidth-examples/ul.md.40.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ marca
- Otro elemento de lista que debe
envolverse ignorando el ancho de la
marca
- [¿Puedo ejecutar múltiples instancias
de MyApp en la misma máquina del
host?](#puedo-ejecutar-multiples-instancias-de-myapp-en-la-misma-maquina-de-host)
2 changes: 2 additions & 0 deletions test/test_po2md/wrapwidth-examples/ul.md.80.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
- 34 6 8 0 texto roto
- Un elemento de lista que debe envolverse ignorando el ancho de la marca
- Otro elemento de lista que debe envolverse ignorando el ancho de la marca
- [¿Puedo ejecutar múltiples instancias de MyApp en la misma máquina del
host?](#puedo-ejecutar-multiples-instancias-de-myapp-en-la-misma-maquina-de-host)
1 change: 1 addition & 0 deletions test/test_po2md/wrapwidth-examples/ul.md.9999.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- 34 6 8 0 texto roto
- Un elemento de lista que debe envolverse ignorando el ancho de la marca
- Otro elemento de lista que debe envolverse ignorando el ancho de la marca
- [¿Puedo ejecutar múltiples instancias de MyApp en la misma máquina del host?](#puedo-ejecutar-multiples-instancias-de-myapp-en-la-misma-maquina-de-host)
7 changes: 7 additions & 0 deletions test/test_po2md/wrapwidth-examples/ul.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ msgstr "Un elemento de lista que debe envolverse ignorando el ancho de la marca"

msgid "Another list item that should wrap ignoring the mark width"
msgstr "Otro elemento de lista que debe envolverse ignorando el ancho de la marca"

msgid ""
"[Can I run multiple instances of MyApp on the same host machine?](#can-i-"
"run-multiple-instances-of-myapp-on-the-same-host-machine)"
msgstr ""
"[¿Puedo ejecutar múltiples instancias de MyApp en la misma máquina del host?]("
"#puedo-ejecutar-multiples-instancias-de-myapp-en-la-misma-maquina-de-host)"

0 comments on commit 3798ccc

Please sign in to comment.