You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2022/08/08 14:46:11 UTC

[lucene-jira-archive] branch list-item-with-tab created (now 2d7a2035)

This is an automated email from the ASF dual-hosted git repository.

tomoko pushed a change to branch list-item-with-tab
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git


      at 2d7a2035 support tab for list item separator

This branch includes the following new commits:

     new 2d7a2035 support tab for list item separator

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[lucene-jira-archive] 01/01: support tab for list item separator

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tomoko pushed a commit to branch list-item-with-tab
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git

commit 2d7a20350523ba8b21a173c198296cf369c1d740
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Mon Aug 8 23:46:03 2022 +0900

    support tab for list item separator
---
 migration/src/markup/lists.py | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/migration/src/markup/lists.py b/migration/src/markup/lists.py
index 3ce03ca9..eafafa0f 100644
--- a/migration/src/markup/lists.py
+++ b/migration/src/markup/lists.py
@@ -6,7 +6,6 @@ from pyparsing import (
     Literal,
     MatchFirst,
     OneOrMore,
-    ZeroOrMore,
     Optional,
     ParserElement,
     ParseResults,
@@ -18,7 +17,28 @@ from pyparsing import (
 from jira2markdown.markup.advanced import Panel
 from jira2markdown.markup.base import AbstractMarkup
 from jira2markdown.markup.text_effects import BlockQuote, Color
-from jira2markdown.markup.lists import ListIndentState, ListIndent
+from jira2markdown.markup.lists import ListIndentState
+
+
+class ListIndentTabSupport(ParserElement):
+    def __init__(self, indent_state: ListIndentState, tokens: str, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        self.name = "ListIndent"
+        self.indent_state = indent_state
+        self.tokens = tokens
+
+    def parseImpl(self, instring, loc, doActions=True):
+        exprs = []
+        for token in self.tokens:
+            for indent in range(self.indent_state.indent + 1, max(0, self.indent_state.indent - 2), -1):
+                # occasionally, the separator can be a tab (commitbot's comment)
+                # https://github.com/apache/lucene-jira-archive/issues/112
+                exprs.append(Literal(token * indent + " ") | Literal(token * indent + "\t"))
+
+        loc, result = MatchFirst(exprs).parseImpl(instring, loc, doActions)
+        self.indent_state.indent = len(result[0]) - 1
+        return loc, result
 
 
 class TweakedList(AbstractMarkup):
@@ -45,7 +65,16 @@ class TweakedList(AbstractMarkup):
                 if len(result) == 0:
                     result.append("")
                 continue
-            bullets, text = line.split(" ", maxsplit=1)
+            cols = line.split(" ", maxsplit=1)
+            if len(cols) > 1:
+                bullets, text = cols[0], cols[1]
+            else:
+                # occasionally, the separator can be a tab (commitbot's comment)
+                cols = line.split("\t", maxsplit=1)
+                if len(cols) > 1:
+                    bullets, text = cols[0], cols[1]
+                else:
+                    continue
 
             nested_indent = 0
             while bullets[0] == self.nested_token:
@@ -74,7 +103,7 @@ class TweakedList(AbstractMarkup):
         ROW = (LineStart() ^ LineEnd()) + Combine(
             Optional(NL)
             + Optional(self.nested_token, default="")
-            + ListIndent(self.indent_state, self.tokens)
+            + ListIndentTabSupport(self.indent_state, self.tokens)
             + SkipTo(NL + Optional(White(" \t")) + Char(self.nested_token + self.tokens) | LIST_BREAK, ignore=IGNORE)
         )