diff --git a/docs/pre-commit-hooks.rst b/docs/pre-commit-hooks.rst index 65ad63f..350ebfe 100644 --- a/docs/pre-commit-hooks.rst +++ b/docs/pre-commit-hooks.rst @@ -19,7 +19,7 @@ so you don't need to specify them. .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.2 + rev: v1.1.3 hooks: - id: md2po args: @@ -32,7 +32,7 @@ so you don't need to specify them. .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.2 + rev: v1.1.3 hooks: - id: md2po files: ^README\.md @@ -53,7 +53,7 @@ po2md .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.2 + rev: v1.1.3 hooks: - id: po2md args: @@ -68,7 +68,7 @@ po2md .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.2 + rev: v1.1.3 hooks: - id: po2md files: ^README\.md @@ -91,7 +91,7 @@ md2po2md .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.2 + rev: v1.1.3 hooks: - id: md2po2md args: @@ -107,7 +107,7 @@ md2po2md .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.2 + rev: v1.1.3 hooks: - id: md2po2md files: ^README\.md @@ -126,7 +126,7 @@ mdpo2html .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.2 + rev: v1.1.3 hooks: - id: mdpo2html args: @@ -141,7 +141,7 @@ mdpo2html .. code-block:: yaml - repo: https://github.com/mondeja/mdpo - rev: v1.1.2 + rev: v1.1.3 hooks: - id: mdpo2html files: ^README\.html diff --git a/pyproject.toml b/pyproject.toml index efc6904..f26834f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mdpo" -version = "1.1.2" +version = "1.1.3" description = "Markdown files translation using PO files." readme = "README.md" license = "BSD-3-Clause" diff --git a/src/mdpo/po2md/__init__.py b/src/mdpo/po2md/__init__.py index cd77213..9065014 100644 --- a/src/mdpo/po2md/__init__.py +++ b/src/mdpo/po2md/__init__.py @@ -17,7 +17,11 @@ po_escaped_string, pofiles_to_unique_translations_dicts, ) -from mdpo.text import min_not_max_chars_in_a_row, parse_wrapwidth_argument +from mdpo.text import ( + INFINITE_WRAPWIDTH, + min_not_max_chars_in_a_row, + parse_wrapwidth_argument, +) class Po2Md: @@ -184,11 +188,8 @@ def __init__(self, pofiles, ignore=frozenset(), po_encoding=None, **kwargs): ) self.wrapwidth = ( - # infinite would be 2 ** 24 because the underlying library - # for wrapping (md-ulb-pwrap) doesn't accept the infinite - # Python object ( - 2 ** 24 if kwargs['wrapwidth'] in [float('inf'), 0] + INFINITE_WRAPWIDTH if kwargs['wrapwidth'] in [float('inf'), 0] else parse_wrapwidth_argument(kwargs['wrapwidth']) ) if 'wrapwidth' in kwargs else 80 ) diff --git a/src/mdpo/text.py b/src/mdpo/text.py index 0cb6746..8ef8a76 100644 --- a/src/mdpo/text.py +++ b/src/mdpo/text.py @@ -4,6 +4,9 @@ import sys +INFINITE_WRAPWIDTH = 65535 + + def and_join(values): """Comma and space join using "and" between the last and penultimate items. @@ -127,9 +130,9 @@ def parse_strint_0_inf(value): num = float(value) try: - return int(num) if num > 0 else float('inf') + return int(num) if num > 0 else INFINITE_WRAPWIDTH except OverflowError: # cannot convert float infinity to integer - return float('inf') + return INFINITE_WRAPWIDTH def parse_wrapwidth_argument(value): diff --git a/tests/test_unit/test_po2md/test_po2md_wrapwidth.py b/tests/test_unit/test_po2md/test_po2md_wrapwidth.py index 7f147b6..eacf8fa 100644 --- a/tests/test_unit/test_po2md/test_po2md_wrapwidth.py +++ b/tests/test_unit/test_po2md/test_po2md_wrapwidth.py @@ -1,6 +1,7 @@ """Wrapping rendering tests for ``po2md`` CLI.""" import glob +import math import os import pytest @@ -17,11 +18,13 @@ ) -@pytest.mark.parametrize('wrapwidth', (10, 40, 80, 2000)) +@pytest.mark.parametrize('wrapwidth', (10, 40, 80, 2000, 0, math.inf)) @pytest.mark.parametrize('filename', EXAMPLES) def test_wrapwidth(filename, wrapwidth): filepath_in = os.path.join(EXAMPLES_DIR, filename) + wrapwidth = wrapwidth if wrapwidth != math.inf else 'inf' filepath_out = f'{filepath_in}.{wrapwidth}.expect.md' + po_filepath = os.path.join( os.path.dirname(filepath_in), os.path.splitext(os.path.basename(filepath_in))[0] + '.po', diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/blockquote.md.0.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/blockquote.md.0.expect.md new file mode 100644 index 0000000..734327b --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/blockquote.md.0.expect.md @@ -0,0 +1,5 @@ +> Un bloque de cita que debe ser envuelto si el parámetro de ancho de envoltura es menor a su largo. + +> 345 7 9 1 cita rota +> +> 34 6 8 0 cita rota diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/blockquote.md.inf.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/blockquote.md.inf.expect.md new file mode 100644 index 0000000..734327b --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/blockquote.md.inf.expect.md @@ -0,0 +1,5 @@ +> Un bloque de cita que debe ser envuelto si el parámetro de ancho de envoltura es menor a su largo. + +> 345 7 9 1 cita rota +> +> 34 6 8 0 cita rota diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/ol.md.0.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/ol.md.0.expect.md new file mode 100644 index 0000000..346a82f --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/ol.md.0.expect.md @@ -0,0 +1,5 @@ +1. 4567 +1. 45 7 9 1 broken text +1. 4 6 8 0 1 broken text +1. Un elemento de lista que debe envolverse ignorando el ancho del delimitador +1. Otro elemento de lista que debe envolverse ignorando el ancho del delimitador diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/ol.md.inf.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/ol.md.inf.expect.md new file mode 100644 index 0000000..346a82f --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/ol.md.inf.expect.md @@ -0,0 +1,5 @@ +1. 4567 +1. 45 7 9 1 broken text +1. 4 6 8 0 1 broken text +1. Un elemento de lista que debe envolverse ignorando el ancho del delimitador +1. Otro elemento de lista que debe envolverse ignorando el ancho del delimitador diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/paragraphs.md.0.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/paragraphs.md.0.expect.md new file mode 100644 index 0000000..2e6b42c --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/paragraphs.md.0.expect.md @@ -0,0 +1,3 @@ +Algo de texto largo que debería envolverse si el parámetro de envoltura de ancho es menor que su largo. + +Algo 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). diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/paragraphs.md.inf.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/paragraphs.md.inf.expect.md new file mode 100644 index 0000000..2e6b42c --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/paragraphs.md.inf.expect.md @@ -0,0 +1,3 @@ +Algo de texto largo que debería envolverse si el parámetro de envoltura de ancho es menor que su largo. + +Algo 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). diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-continua.md.0.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-continua.md.0.expect.md new file mode 100644 index 0000000..bd4c9f5 --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-continua.md.0.expect.md @@ -0,0 +1 @@ +* 支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。 diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-continua.md.inf.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-continua.md.inf.expect.md new file mode 100644 index 0000000..bd4c9f5 --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-continua.md.inf.expect.md @@ -0,0 +1 @@ +* 支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。 diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-mixed.md.0.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-mixed.md.0.expect.md new file mode 100644 index 0000000..e88bb20 --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-mixed.md.0.expect.md @@ -0,0 +1 @@ +* 同类项目中最佳的性能。Klipper能够在新旧微控制器上实现高步进速率。即使是旧的8 位微控制器也可以发超过每秒175K步的速率。在较新的微控制器上,每秒数百万步也可以实现。更高的步进速率可以实现更高的打印速度。步进事件计时即使在高速下也能保持精确,提高了整体稳定性。 diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-mixed.md.inf.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-mixed.md.inf.expect.md new file mode 100644 index 0000000..e88bb20 --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/scriptio-mixed.md.inf.expect.md @@ -0,0 +1 @@ +* 同类项目中最佳的性能。Klipper能够在新旧微控制器上实现高步进速率。即使是旧的8 位微控制器也可以发超过每秒175K步的速率。在较新的微控制器上,每秒数百万步也可以实现。更高的步进速率可以实现更高的打印速度。步进事件计时即使在高速下也能保持精确,提高了整体稳定性。 diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/tasklist.md.0.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/tasklist.md.0.expect.md new file mode 100644 index 0000000..8c3dd51 --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/tasklist.md.0.expect.md @@ -0,0 +1,5 @@ +- [ ] 7890 +- [ ] 78 0 2 4 texto roto +- [x] 7 9 1 3 5 texto roto +- [ ] Un elemento de lista de tareas que debe envolverse ignorando el ancho del checkbox +- [X] Otro elemento de lista de tareas que debe envolverse ignorando el ancho del checkbox diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/tasklist.md.inf.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/tasklist.md.inf.expect.md new file mode 100644 index 0000000..8c3dd51 --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/tasklist.md.inf.expect.md @@ -0,0 +1,5 @@ +- [ ] 7890 +- [ ] 78 0 2 4 texto roto +- [x] 7 9 1 3 5 texto roto +- [ ] Un elemento de lista de tareas que debe envolverse ignorando el ancho del checkbox +- [X] Otro elemento de lista de tareas que debe envolverse ignorando el ancho del checkbox diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/ul.md.0.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/ul.md.0.expect.md new file mode 100644 index 0000000..30fa1b5 --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/ul.md.0.expect.md @@ -0,0 +1,6 @@ +- 3456 +- 345 7 9 1 texto roto +- 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) diff --git a/tests/test_unit/test_po2md/wrapwidth-examples/ul.md.inf.expect.md b/tests/test_unit/test_po2md/wrapwidth-examples/ul.md.inf.expect.md new file mode 100644 index 0000000..30fa1b5 --- /dev/null +++ b/tests/test_unit/test_po2md/wrapwidth-examples/ul.md.inf.expect.md @@ -0,0 +1,6 @@ +- 3456 +- 345 7 9 1 texto roto +- 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) diff --git a/tests/test_unit/test_text.py b/tests/test_unit/test_text.py index a4b3b47..24df3b0 100644 --- a/tests/test_unit/test_text.py +++ b/tests/test_unit/test_text.py @@ -1,10 +1,10 @@ """Tests for mdpo text utilities.""" -import math import pytest from mdpo.text import ( + INFINITE_WRAPWIDTH, min_not_max_chars_in_a_row, parse_escaped_pair, parse_strint_0_inf, @@ -61,20 +61,20 @@ def test_parse_escaped_pair(text, expected_result, maybe_raises): ( ('1', 1), ('1.1', 1), - (-1, math.inf), - (-1.1, math.inf), - ('-1', math.inf), - ('-1.1', math.inf), - (0, math.inf), - (-0, math.inf), + (-1, INFINITE_WRAPWIDTH), + (-1.1, INFINITE_WRAPWIDTH), + ('-1', INFINITE_WRAPWIDTH), + ('-1.1', INFINITE_WRAPWIDTH), + (0, INFINITE_WRAPWIDTH), + (-0, INFINITE_WRAPWIDTH), ('a', ValueError), ('nan', ValueError), ('NotANumber', ValueError), - ('inf', math.inf), - ('InF', math.inf), - ('-inf', math.inf), - ('-iNf', math.inf), - ('iNfInItY', math.inf), + ('inf', INFINITE_WRAPWIDTH), + ('InF', INFINITE_WRAPWIDTH), + ('-inf', INFINITE_WRAPWIDTH), + ('-iNf', INFINITE_WRAPWIDTH), + ('iNfInItY', INFINITE_WRAPWIDTH), ('+1E6', 1000000), ), ) @@ -92,6 +92,9 @@ def test_parse_wrapwidth_argument(value): with pytest.raises(ValueError, match=expected_msg): parse_wrapwidth_argument(value) else: + assert parse_wrapwidth_argument(value) == ( - float('inf') if float(value) == 0 else float(value) + INFINITE_WRAPWIDTH if 'inf' in value or value == '0' else int( + value, + ) )