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/07/09 05:45:03 UTC
[lucene-jira-archive] branch fix-quote-indent created (now 91233542)
This is an automated email from the ASF dual-hosted git repository.
tomoko pushed a change to branch fix-quote-indent
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git
at 91233542 fix indentation error after quotes
This branch includes the following new commits:
new 91233542 fix indentation error after quotes
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: fix indentation error after quotes
Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tomoko pushed a commit to branch fix-quote-indent
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git
commit 9123354244c8c79030df77c24136a8f5fa1be31a
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Sat Jul 9 14:44:49 2022 +0900
fix indentation error after quotes
---
migration/src/jira_util.py | 4 +++
migration/src/markup/text_effects.py | 51 ++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/migration/src/jira_util.py b/migration/src/jira_util.py
index 7dcecdec..157803f9 100644
--- a/migration/src/jira_util.py
+++ b/migration/src/jira_util.py
@@ -6,8 +6,10 @@ from typing import Optional
import jira2markdown
from jira2markdown.elements import MarkupElements
from jira2markdown.markup.lists import UnorderedList, OrderedList
+from jira2markdown.markup.text_effects import BlockQuote, Quote
from markup.lists import UnorderedTweakedList, OrderedTweakedList
+from markup.text_effects import TweakedBlockQuote, TweakedQuote
@dataclass
class Attachment(object):
@@ -203,6 +205,8 @@ def convert_text(text: str, att_replace_map: dict[str, str] = {}) -> str:
elements = MarkupElements()
elements.replace(UnorderedList, UnorderedTweakedList)
elements.replace(OrderedList, OrderedTweakedList)
+ elements.replace(BlockQuote, TweakedBlockQuote)
+ elements.replace(Quote, TweakedQuote)
text = jira2markdown.convert(text, elements=elements)
# markup @ mentions with ``
diff --git a/migration/src/markup/text_effects.py b/migration/src/markup/text_effects.py
new file mode 100644
index 00000000..61f541d7
--- /dev/null
+++ b/migration/src/markup/text_effects.py
@@ -0,0 +1,51 @@
+import re
+
+from pyparsing import (
+ ParserElement,
+ ParseResults,
+ QuotedString,
+ StringEnd,
+ StringStart,
+ SkipTo,
+ Literal,
+ LineEnd,
+ Optional,
+ Combine,
+ White,
+ OneOrMore,
+ nums,
+ replaceWith,
+
+)
+
+from jira2markdown.markup.base import AbstractMarkup
+
+class TweakedBlockQuote(AbstractMarkup):
+ def action(self, tokens: ParseResults) -> str:
+ text = self.markup.transformString("\n".join([line.lstrip() for line in tokens[0].strip().splitlines()]))
+ # escape numbered list in quotes.
+ # e.g.,
+ # {quote}
+ # 2. foo
+ # 5. bar
+ # {quote}
+ # should be
+ # > 2\\. foo
+ # > 5\\. bar
+ pat_ordered_list = re.compile(r"((?<=^\d)||(?<=^\d\d))\.")
+ return "\n".join(["> " + re.sub(pat_ordered_list, '\.', line) for line in text.splitlines()]) + "\n" # needs additional line feed at the end of quotation to preserve indentation
+
+ @property
+ def expr(self) -> ParserElement:
+ return QuotedString("{quote}", multiline=True).setParseAction(self.action)
+
+
+class TweakedQuote(AbstractMarkup):
+ is_inline_element = False
+
+ @property
+ def expr(self) -> ParserElement:
+ return ("\n" | StringStart()) + Combine(
+ Literal("bq. ").setParseAction(replaceWith("> "))
+ + SkipTo(LineEnd()) + LineEnd().setParseAction(replaceWith("\n\n")) # needs additional line feed at the end of quotation to preserve indentation
+ )