blob: 20ec8478352e8c13a905fd0b7998805480a74fe2 [file] [log] [blame]
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)