Skip to content

Commit

Permalink
feat(lists): add optional space indentation for list items (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
catcombo authored Dec 10, 2022
2 parents 8146051 + 0b90199 commit 2b46327
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 48 deletions.
26 changes: 18 additions & 8 deletions jira2markdown/markup/lists.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from pyparsing import (
Char,
Combine,
Expand All @@ -9,10 +11,10 @@
Optional,
ParserElement,
ParseResults,
Regex,
SkipTo,
StringEnd,
Token,
White,
)

from jira2markdown.markup.advanced import Panel
Expand Down Expand Up @@ -87,14 +89,22 @@ def action(self, tokens: ParseResults) -> str:

@property
def expr(self) -> ParserElement:
NL = LineEnd()
LIST_BREAK = NL + Optional(White(" \t")) + NL | StringEnd()
WHITESPACE = Regex(r"[ \t]+", flags=re.UNICODE)
EOL = LineEnd()
LIST_BREAK = EOL + Optional(WHITESPACE) + EOL | StringEnd()
IGNORE = BlockQuote(**self.init_kwargs).expr | Panel(**self.init_kwargs).expr | Color(**self.init_kwargs).expr
ROW = LineStart() + Combine(
Optional(self.nested_token, default="")
+ ListIndent(self.indent_state, self.tokens)
+ SkipTo(NL + Char(self.nested_token + self.tokens) | LIST_BREAK, ignore=IGNORE)
+ Optional(NL),
ROW = (
LineStart()
+ Optional(WHITESPACE).suppress()
+ Combine(
Optional(self.nested_token, default="")
+ ListIndent(self.indent_state, self.tokens)
+ SkipTo(
EOL + Optional(WHITESPACE) + Char(self.nested_token + self.tokens) | LIST_BREAK,
ignore=IGNORE,
)
+ Optional(EOL),
)
)

return OneOrMore(ROW, stop_on=LIST_BREAK).set_parse_action(self.action)
Expand Down
64 changes: 26 additions & 38 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jira2markdown"
version = "0.3"
version = "0.3.1"
description = "Convert text from JIRA markup to Markdown using parsing expression grammars"
authors = ["Evgeniy Krysanov <evgeniy.krysanov@gmail.com>"]
readme = "README.md"
Expand Down
34 changes: 33 additions & 1 deletion tests/markup/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_mixed_bullets(self):
def test_match_start_conditions(self):
assert convert("* Item") == "- Item"
assert convert("\n* Item") == "\n- Item"
assert convert(" * Item") == r" \* Item"
assert convert(" * Item") == r"- Item"

def test_multiline(self):
assert (
Expand Down Expand Up @@ -169,6 +169,22 @@ def test_text_indent(self):
"""
)

def test_list_indent(self):
assert (
convert(
"""
* One
** Two
** Three
"""
)
== """
- One
- Two
- Three
"""
)


class TestOrderedList:
def test_bullets(self):
Expand Down Expand Up @@ -282,3 +298,19 @@ def test_empty_list(self):
1.
"""
)

def test_list_indent(self):
assert (
convert(
"""
# One
## Two
## Three
"""
)
== """
1. One
1. Two
1. Three
"""
)

0 comments on commit 2b46327

Please sign in to comment.