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

fix(jira2markdown): process windows line breaks as a Unix line breaks #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jira2markdown/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ def convert(text: str, usernames: Optional[dict] = None, elements: Optional[Mark
inline_markup << elements.expr(inline_markup, markup, usernames, filter(lambda e: e.is_inline_element, elements))
markup << elements.expr(inline_markup, markup, usernames, elements)

text = text.replace("\r\n", "\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@catcombo: This currently works for me in my production workflow, however I would consider accounting for individual Carriage Returns (CR) )\r). It is not an edge case that currently breaks something in my workflow but could for someone else since it was a valid new-line on legacy Mac's.

    text = text.replace("\r\n", "\n").replace("\r", "\n")

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I afraid of. I so not sure about these replacements. Probably this week I'll have more time to investigate how to do it with pyparsing. Lets wait until the end of the week.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed another version with a custom token for line endings. It works but now output contains mixed line endings. This is because converter doesn't change all characters in the string, but only ones that match predefined elements. Probably, it's not very good idea, but at least it works on the tokens level, not on the entire string without taking into account the string markup. What do you think?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I found how to keep existing line breaks and reuse them if possible. Now in most of the cases line breaks in the converted string will be consistent. @arctus-io can you test it on your side?

return markup.transform_string(text)
6 changes: 6 additions & 0 deletions tests/markup/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,9 @@ def test_list_indent(self):
1. Three
"""
)

def test_windows_line_breaks(self):
assert (
convert("Line before list\r\n * Bulleted item 1\r\n * Bulleted item 2\r\n\r\nLine after list")
== "Line before list\n- Bulleted item 1\n- Bulleted item 2\n\nLine after list"
)
16 changes: 16 additions & 0 deletions tests/markup/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,19 @@ def test_empty_start_lines(self):
assert convert(" \n|header") == " \n|header|\n|---|\n"
assert convert(" \n \t \n|header") == " \n \t \n|header|\n|---|\n"
assert convert(" \n text \n|header") == " \n text \n\n|header|\n|---|\n"

def test_windows_line_breaks(self):
assert convert(
"text before table:\r\n\r\n"
"||header 1||header 2||header 3||\r\n"
"|cell 1-1|cell 1-2|cell 1-3|\r\n"
"|cell 2-1|cell 2-2|cell 2-3|\r\n\r\n"
"text after table"
) == (
"text before table:\n\n"
"|header 1|header 2|header 3|\n"
"|---|---|---|\n"
"|cell 1-1|cell 1-2|cell 1-3|\n"
"|cell 2-1|cell 2-2|cell 2-3|\n\n"
"text after table"
)
Loading