Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rst header incorrectly transformed - issues with Windows line endings #18

Closed
epogrebnyak opened this issue Aug 3, 2021 · 8 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@epogrebnyak
Copy link

epogrebnyak commented Aug 3, 2021

Main
====

become

Main ====

after running style-doc and not longer recognised as header. I think this is not intended behaviour.

@PhilipMay
Copy link
Member

Hey @epogrebnyak
many thanks for reporting this. I will investigate it.

@PhilipMay PhilipMay self-assigned this Aug 3, 2021
@PhilipMay PhilipMay added the bug Something isn't working label Aug 3, 2021
@epogrebnyak
Copy link
Author

Maybe not tested on Windows and \r\n not appreciated?

@PhilipMay
Copy link
Member

PhilipMay commented Aug 4, 2021

I can confirm it. It is a windows \r\n newline issue.
I added a test for linux encoding:

def test_linux_line_separators(tmpdir):
tmp_file_name = os.path.join(tmpdir, "file.rst")
with open(tmp_file_name, "w") as f:
f.write("Main\n====\n")
os.system(f"style-doc --max_len 99 {tmpdir}")
with open(tmp_file_name, "r") as f:
content = f.readlines()
assert content[0] == "Main\n"
assert content[1] == "=" * 99 + "\n"

If you see a way how to fix it - feel free for a PR.

@PhilipMay
Copy link
Member

It should be possible to read the file and convert all newlines to \n while reading it:
https://docs.python.org/3/library/functions.html#open

@PhilipMay PhilipMay changed the title rst header incorrectly transformed rst header incorrectly transformed - issues with Windows line endings Aug 4, 2021
@epogrebnyak
Copy link
Author

Similarly to the test code, when new line is not specified, open() transforms any newlines to \n (universal newline), so for the PR I'll just try skipping the new line parameter in open().

PhilipMay added a commit that referenced this issue Aug 6, 2021
@PhilipMay
Copy link
Member

@epogrebnyak this is fixed - see fbf9974

@PhilipMay
Copy link
Member

@epogrebnyak I made a new release on pypi. Can you please update the package and try it on your side?

@epogrebnyak
Copy link
Author

Great, thanks, looks fixed. As a side comment the newlines after formatting the newlines are just \n, not \r\n\ but I think one can live with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants