-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
902 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from typing import Iterable, Type | ||
|
||
from pyparsing import Forward, MatchFirst, ParseExpression | ||
|
||
from jira2markdown.markup.advanced import Code, Noformat, Panel | ||
from jira2markdown.markup.base import AbstractMarkup | ||
from jira2markdown.markup.headings import Headings | ||
from jira2markdown.markup.images import Image | ||
from jira2markdown.markup.links import Attachment, Link, MailTo, Mention | ||
from jira2markdown.markup.lists import OrderedList, UnorderedList | ||
from jira2markdown.markup.tables import Table | ||
from jira2markdown.markup.text_breaks import LineBreak, Mdash, Ndash, Ruler | ||
from jira2markdown.markup.text_effects import BlockQuote, Bold, Color, EscSpecialChars, InlineQuote, Monospaced, \ | ||
Quote, Strikethrough, Subscript, Superscript, Underline | ||
|
||
|
||
class MarkupElements(list): | ||
def __init__(self, seq: Iterable = ()): | ||
super().__init__(seq or [ | ||
UnorderedList, | ||
OrderedList, | ||
Code, | ||
Noformat, | ||
Monospaced, | ||
Mention, | ||
MailTo, | ||
Attachment, | ||
Link, | ||
Image, | ||
Table, | ||
Headings, | ||
Quote, | ||
BlockQuote, | ||
Panel, | ||
Bold, | ||
Ndash, | ||
Mdash, | ||
Ruler, | ||
Strikethrough, | ||
Underline, | ||
InlineQuote, | ||
Superscript, | ||
Subscript, | ||
Color, | ||
LineBreak, | ||
EscSpecialChars, | ||
]) | ||
|
||
def insert_after(self, element: Type[AbstractMarkup], new_element: Type[AbstractMarkup]): | ||
index = self.index(element) | ||
self.insert(index + 1, new_element) | ||
|
||
def replace(self, old_element: Type[AbstractMarkup], new_element: Type[AbstractMarkup]): | ||
index = self.index(old_element) | ||
self[index] = new_element | ||
|
||
def expr( | ||
self, | ||
inline_markup: Forward, | ||
markup: Forward, | ||
usernames: dict, | ||
elements: Iterable[Type[AbstractMarkup]], | ||
) -> ParseExpression: | ||
return MatchFirst([ | ||
element(inline_markup=inline_markup, markup=markup, usernames=usernames).expr | ||
for element in elements | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pyparsing import Forward, ParserElement | ||
|
||
|
||
class AbstractMarkup: | ||
is_inline_element: bool = True | ||
|
||
def __init__(self, inline_markup: Forward, markup: Forward, usernames: dict): | ||
self.inline_markup = inline_markup | ||
self.markup = markup | ||
self.usernames = usernames | ||
self.init_kwargs = dict(inline_markup=inline_markup, markup=markup, usernames=usernames) | ||
|
||
@property | ||
def expr(self) -> ParserElement: | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
from pyparsing import Combine, ParseResults, ParserElement, StringStart, Word | ||
from pyparsing import Combine, LineEnd, ParseResults, ParserElement, SkipTo, StringEnd, StringStart, Word | ||
|
||
from jira2markdown.markup.base import AbstractMarkup | ||
|
||
|
||
class Headings(AbstractMarkup): | ||
is_inline_element = False | ||
|
||
class Headings: | ||
def action(self, tokens: ParseResults) -> str: | ||
return "#" * int(tokens[0][1]) + " " | ||
return "#" * int(tokens.level[1]) + " " + self.inline_markup.transformString(tokens.text) | ||
|
||
@property | ||
def expr(self) -> ParserElement: | ||
return ("\n" | StringStart()) \ | ||
+ Combine(Word("h", "123456", exact=2) + ". ").setParseAction(self.action) | ||
return ("\n" | StringStart()) + Combine( | ||
Word("h", "123456", exact=2).setResultsName("level") | ||
+ ". " | ||
+ SkipTo(LineEnd() | StringEnd()).setResultsName("text"), | ||
).setParseAction(self.action) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.