Skip to content

Commit e517a8d

Browse files
authored
Merge pull request #23 from nschloe/percentage
don't match escaped comment signs
2 parents 4be1761 + 665c3ae commit e517a8d

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
[![GitHub stars](https://img.shields.io/github/stars/nschloe/blacktex.svg?style=flat-square&logo=github&label=Stars&logoColor=white)](https://github.com/nschloe/blacktex)
99
[![PyPi downloads](https://img.shields.io/pypi/dm/blacktex.svg?style=flat-square)](https://pypistats.org/packages/blacktex)
1010

11-
[![Discord](https://img.shields.io/static/v1?logo=discord&label=chat&message=on%20discord&color=7289da&style=flat-square)](https://discord.gg/hnTJ5MRX2Y)
12-
1311
[![gh-actions](https://img.shields.io/github/workflow/status/nschloe/blacktex/ci?style=flat-square)](https://github.com/nschloe/blacktex/actions?query=workflow%3Aci)
1412
[![codecov](https://img.shields.io/codecov/c/github/nschloe/blacktex.svg?style=flat-square)](https://codecov.io/gh/nschloe/blacktex)
1513
[![LGTM](https://img.shields.io/lgtm/grade/python/github/nschloe/blacktex.svg?style=flat-square)](https://lgtm.com/projects/g/nschloe/blacktex)

blacktex/main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ def _remove_comments(string):
1616
string = "\n".join([lines[k] for k in range(len(lines)) if k not in comment_lines])
1717

1818
# https://stackoverflow.com/a/2319116/353337
19-
string = re.sub("[ \t]*%.+\n", "\n", string)
19+
# https://stackoverflow.com/a/24209736/353337
20+
string = re.sub("[ \t]*(?<!\\\\)%.+\n", "\n", string)
2021
# same with EOF
21-
string = re.sub("[ \t]*%.+$", "", string)
22+
string = re.sub("[ \t]*(?<!\\\\)%.+$", "", string)
2223
return string
2324

2425

setup.cfg

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = blacktex
3-
version = 0.3.3
3+
version = 0.3.4
44
author = Nico Schlömer
55
author_email = [email protected]
66
description = Cleans up your LaTeX files
@@ -12,7 +12,6 @@ project_urls =
1212
long_description = file: README.md
1313
long_description_content_type = text/markdown
1414
license = GPL-3.0-or-later
15-
license_file = LICENSE
1615
classifiers =
1716
Development Status :: 4 - Beta
1817
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)

test/test_blacktex.py

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def test_comments():
4040
out = blacktex.clean(input_string)
4141
assert out == "A\n sit amet"
4242

43+
input_string = "{equation}%comment"
44+
out = blacktex.clean(input_string)
45+
assert out == "{equation}"
46+
4347

4448
def test_multiple_comment_lines():
4549
input_string = "A\n%\n%\nB"
@@ -54,6 +58,12 @@ def test_comment_last():
5458
assert out == ref, f"{repr(out)} != {repr(ref)}"
5559

5660

61+
def test_escapted_percentage_sign():
62+
input_string = "25\\% gain"
63+
out = blacktex.clean(input_string)
64+
assert out == "25\\% gain"
65+
66+
5767
def test_trailing_whitespace():
5868
input_string = "lorem \n sit amet"
5969
out = blacktex.clean(input_string)

0 commit comments

Comments
 (0)