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 11:38:23 UTC
[lucene-jira-archive] branch main updated: insert linefeeds before/after a code block (#138)
This is an automated email from the ASF dual-hosted git repository.
tomoko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene-jira-archive.git
The following commit(s) were added to refs/heads/main by this push:
new 202be8e4 insert linefeeds before/after a code block (#138)
202be8e4 is described below
commit 202be8e466325236f3c0a2ee7e0907464c805cbd
Author: Tomoko Uchida <to...@gmail.com>
AuthorDate: Mon Aug 8 20:38:19 2022 +0900
insert linefeeds before/after a code block (#138)
---
migration/src/jira_util.py | 3 +++
migration/src/markup/advanced.py | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/migration/src/jira_util.py b/migration/src/jira_util.py
index 985ebfba..bdd07457 100644
--- a/migration/src/jira_util.py
+++ b/migration/src/jira_util.py
@@ -7,10 +7,12 @@ from typing import Optional
import jira2markdown
from jira2markdown.elements import MarkupElements
+from jira2markdown.markup.advanced import Code
from jira2markdown.markup.lists import UnorderedList, OrderedList
from jira2markdown.markup.text_effects import BlockQuote, Quote, Monospaced
from jira2markdown.markup.text_breaks import Ruler
+from markup.advanced import TweakedCode
from markup.lists import UnorderedTweakedList, OrderedTweakedList
from markup.text_effects import EscapeHtmlTag, TweakedBlockQuote, TweakedQuote, TweakedMonospaced
from markup.text_breaks import LongRuler
@@ -330,6 +332,7 @@ def convert_text(text: str, att_replace_map: dict[str, str] = {}, account_map: d
# convert Jira markup into Markdown with customization
elements = MarkupElements()
+ elements.replace(Code, TweakedCode)
elements.replace(UnorderedList, UnorderedTweakedList)
elements.replace(OrderedList, OrderedTweakedList)
elements.replace(BlockQuote, TweakedBlockQuote)
diff --git a/migration/src/markup/advanced.py b/migration/src/markup/advanced.py
new file mode 100644
index 00000000..20ec8478
--- /dev/null
+++ b/migration/src/markup/advanced.py
@@ -0,0 +1,34 @@
+from pyparsing import (
+ Combine,
+ FollowedBy,
+ Literal,
+ Optional,
+ ParserElement,
+ ParseResults,
+ SkipTo,
+ Word,
+ alphanums,
+)
+
+from jira2markdown.markup.base import AbstractMarkup
+
+
+class TweakedCode(AbstractMarkup):
+ def action(self, tokens: ParseResults) -> str:
+ lang = tokens.lang or "Java"
+ text = tokens.text.strip("\n")
+ # insert '\n' before and after the code block.
+ return f"\n```{lang}\n{text}\n```\n"
+
+ @property
+ def expr(self) -> ParserElement:
+ return Combine(
+ "{code"
+ + Optional(
+ ":" + Word(alphanums + "#+").setResultsName("lang") + FollowedBy(Literal("}") | Literal("|")),
+ )
+ + ...
+ + "}"
+ + SkipTo("{code}").setResultsName("text")
+ + "{code}",
+ ).setParseAction(self.action)