Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions .github/workflows/tiptapy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,28 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9]
python-version: [3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip jinja2
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pytest -xv
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip jinja2
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pytest -xv
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.20.0
current_version = 0.21.0
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="tiptapy",
version="0.20.0",
version="0.21.0",
url="https://github.com/scrolltech/tiptapy",
description="Library that generates HTML output from JSON export of tiptap editor",
long_description=open("README.md").read(),
Expand Down
1 change: 1 addition & 0 deletions tests/data/html/image-src_string.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<figure><picture><source srcset="https://placekitten.com/200/301" type="image"/><source srcset="https://placekitten.com/200/301" type="image"/><img src="https://placekitten.com/200/301" alt="Sleepy Kitten" width="300" height="400"/></picture><figcaption>Cute Kitty</figcaption></figure>
15 changes: 15 additions & 0 deletions tests/data/json/image-src_string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "doc",
"content": [
{
"type": "image",
"attrs": {
"src": "https://placekitten.com/200/301",
"alt": "Sleepy Kitten",
"caption": "Cute Kitty",
"height": 400,
"width": 300
}
}
]
}
1 change: 1 addition & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"image-no_caption",
"image-mime_type",
"image-height_width",
"image-src_string",
"featuredimage",
"featuredimage-is_renderable",
"featuredimage-missing_caption",
Expand Down
2 changes: 1 addition & 1 deletion tiptapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
extract_tag_attrs,
)

__version__ = "0.20.0"
__version__ = "0.21.0"

renderers: Dict = {}

Expand Down
6 changes: 5 additions & 1 deletion tiptapy/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def make_img_src(attrs):
alt = attrs.get("alt", "").strip()
height = attrs.get("height", "")
width = attrs.get("width", "")
fallback_url = attrs["src"]["fallback"].strip()
if isinstance(attrs["src"], dict):
fallback_url = attrs["src"]["fallback"].strip()
else:
fallback_url = attrs["src"].strip()

img = f'img src="{fallback_url}"'
if alt:
img += f' alt="{alt}"'
Expand Down
4 changes: 2 additions & 2 deletions tiptapy/templates/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{%- set alt = node.attrs.alt|trim -%}
{%- set height = node.attrs.height -%}
{%- set width = node.attrs.width -%}
{%- set image_url = node.attrs.src.image|trim -%}
{%- set image_url = (node.attrs.src.image if node.attrs.src is mapping else node.attrs.src)|trim -%}
{%- set image_type = url2mime(image_url) -%}
{%- set fallback_url = node.attrs.src.fallback|trim -%}
{%- set fallback_url = (node.attrs.src.fallback if node.attrs.src is mapping else node.attrs.src)|trim -%}
{%- set fallback_type = url2mime(fallback_url) -%}

{%- if image_url or fallback_url -%}
Expand Down