Skip to content

Commit

Permalink
Use youtrack format to render image with properties (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
catcombo authored Nov 23, 2024
2 parents 5971ced + 662ad7c commit 644d6cf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.7

Expand All @@ -23,7 +23,7 @@ jobs:
- name: Restore virtualenv from cache
id: cache
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('poetry.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ convert("[Winston Smith|~accountid:internal-id] woke up with the word 'Shakespea
<td>

```
<img src="image.jpg" width="300" height="200" />
![image.jpg](image.jpg){width=300 height=200}
```
</td>
</tr>
Expand Down
7 changes: 3 additions & 4 deletions jira2markdown/markup/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ def _parse_attrs(self, attrs: List[List[str]]) -> Dict:

def action(self, tokens: ParseResults) -> str:
attrs_str = " ".join(
f'{name}="{value}"'
f"{name}={value}"
for name, value in self._parse_attrs(tokens.attrs or []).items()
if name in self.ALLOWED_ATTRS
)
if attrs_str:
return f'<img src="{tokens.url}" {attrs_str} />'
else:
return f"![{tokens.url}]({tokens.url})"
attrs_str = f"{{{attrs_str}}}"
return f"![{tokens.url}]({tokens.url}){attrs_str}"

@property
def expr(self) -> ParserElement:
Expand Down
4 changes: 2 additions & 2 deletions tests/markup/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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!") == '<img src="image.jpg" width="300" />'
assert convert("!image.jpg| WIDTH = 300 , HEIGHT=200!") == '<img src="image.jpg" width="300" height="200" />'
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|align=right, vspace=4!") == "![image.jpg](image.jpg)"
4 changes: 2 additions & 2 deletions tests/markup/test_mixed_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_basic_markup(self):
)

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

def test_cell_link(self):
assert convert("|[link|http://example.com]|") == "|[link](http://example.com)|\n|---|\n"
Expand All @@ -285,7 +285,7 @@ def test_text_formatting(self):
== """
> **My Title**
> a block of text surrounded with a **panel**
> line with <img src="image.png" width="300" />
> line with ![image.png](image.png){width=300}
"""
)

Expand Down

0 comments on commit 644d6cf

Please sign in to comment.