Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
catcombo committed Feb 22, 2021
2 parents 6a78269 + 53e7bae commit 5d22525
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,28 @@ convert("[Winston Smith|~accountid:internal-id] woke up with the word 'Shakespea

## Images

| Jira | Markdown |
|------|----------|
|`!image.jpg!`|`![image.jpg](image.jpg)`|
|`!image.jpg\|thumbnail!`|`![image.jpg](image.jpg)`|
|`!image.jpg\|width=300,height=200!`|`![image.jpg](image.jpg){width=300}{height=200}`|
<table>
<tr>
<th>Jira</th>
<th>Markdown</th>
</tr>
<tr>
<td>

Only `width` and `height` attributes are supported.
```
!image.jpg!
!image.jpg|thumbnail!
!image.gif|align=right, vspace=4!
```
</td>
<td>

```
![image.jpg](image.jpg)
```
</td>
</tr>
</table>

## Tables

Expand Down
21 changes: 4 additions & 17 deletions jira2markdown/markup/images.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
from pyparsing import Combine, Optional, ParseResults, ParserElement, Word, nums, printables
from pyparsing import Combine, Optional, ParseResults, ParserElement, SkipTo, Word, printables

from jira2markdown.tokens import NotUnicodeAlphaNum


class Image:
def action(self, tokens: ParseResults) -> str:
res = f"![{tokens.url}]({tokens.url})"
if tokens.width:
res += f"{{width={tokens.width}}}"
if tokens.height:
res += f"{{height={tokens.height}}}"
return res
return f"![{tokens.url}]({tokens.url})"

@property
def expr(self) -> ParserElement:
return NotUnicodeAlphaNum() + Combine(
"!"
+ Word(printables + " ", min=3, excludeChars="|!").setResultsName("url")
+ Optional(
"|" + (
Optional("thumbnail")
^ Optional(
"width=" + Word(nums).setResultsName("width")
+ Optional(",height=" + Word(nums).setResultsName("height")),
)
),
)
+ "!",
+ Optional("|")
+ SkipTo("!", failOn="\n") + "!",
).setParseAction(self.action)
2 changes: 2 additions & 0 deletions jira2markdown/markup/text_breaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def expr(self) -> ParserElement:
class Ruler:
@property
def expr(self) -> ParserElement:
# Text with dashed below it turns into a heading. To prevent this
# add a line break before the dashes.
return ("\n" | StringStart() | LineBreak().expr) \
+ Keyword("----", identChars="-").setParseAction(replaceWith("\n----")) \
+ LineEnd()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jira2markdown"
version = "0.1.6"
version = "0.1.7"
description = "Convert text from JIRA markup to Markdown using parsing expression grammars"
authors = ["Evgeniy Krysanov <[email protected]>"]
readme = "README.md"
Expand Down
5 changes: 3 additions & 2 deletions tests/markup/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ def test_url_line_break(self):
assert convert("!http://example.\ncom/image.png!") == "!http://example.\ncom/image.png!"

def test_image_attributes(self):
assert convert("!image.jpg|width=300!") == "![image.jpg](image.jpg){width=300}"
assert convert("!image.jpg|width=300,height=200!") == "![image.jpg](image.jpg){width=300}{height=200}"
assert convert("!image.jpg|width=300!") == "![image.jpg](image.jpg)"
assert convert("!image.jpg|width=300,height=200!") == "![image.jpg](image.jpg)"
assert convert("!image.jpg|align=right, vspace=4!") == "![image.jpg](image.jpg)"
2 changes: 1 addition & 1 deletion tests/markup/test_mixed_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_basic_markup(self):
'\n\n|Table **bold header** and <font color="red">colored title</font>|\n|-|\n\n'

def test_cell_image(self):
assert convert("|!image.png|width=300!") == "\n\n|![image.png](image.png){width=300}|\n|-|\n\n"
assert convert("|!image.png|width=300!") == "\n\n|![image.png](image.png)|\n|-|\n\n"

def test_cell_link(self):
assert convert("|[link|http://example.com]|") == "\n\n|[link](http://example.com)|\n|-|\n\n"
Expand Down

0 comments on commit 5d22525

Please sign in to comment.