diff --git a/.github/workflows/tiptapy.yml b/.github/workflows/tiptapy.yml index 4245742..7e7be0d 100644 --- a/.github/workflows/tiptapy.yml +++ b/.github/workflows/tiptapy.yml @@ -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 diff --git a/setup.cfg b/setup.cfg index b26989b..d503428 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.20.0 +current_version = 0.21.0 commit = True tag = True diff --git a/setup.py b/setup.py index c0c4696..6c09426 100644 --- a/setup.py +++ b/setup.py @@ -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(), diff --git a/tests/data/html/image-src_string.html b/tests/data/html/image-src_string.html new file mode 100644 index 0000000..8c7d3a1 --- /dev/null +++ b/tests/data/html/image-src_string.html @@ -0,0 +1 @@ +
Sleepy Kitten
Cute Kitty
\ No newline at end of file diff --git a/tests/data/json/image-src_string.json b/tests/data/json/image-src_string.json new file mode 100644 index 0000000..2f8f564 --- /dev/null +++ b/tests/data/json/image-src_string.json @@ -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 + } + } + ] +} diff --git a/tests/test_transform.py b/tests/test_transform.py index 1decf32..19f3cca 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -21,6 +21,7 @@ "image-no_caption", "image-mime_type", "image-height_width", + "image-src_string", "featuredimage", "featuredimage-is_renderable", "featuredimage-missing_caption", diff --git a/tiptapy/__init__.py b/tiptapy/__init__.py index e10dfb0..5a41ec4 100644 --- a/tiptapy/__init__.py +++ b/tiptapy/__init__.py @@ -15,7 +15,7 @@ extract_tag_attrs, ) -__version__ = "0.20.0" +__version__ = "0.21.0" renderers: Dict = {} diff --git a/tiptapy/macros.py b/tiptapy/macros.py index 124afe6..0577fa9 100644 --- a/tiptapy/macros.py +++ b/tiptapy/macros.py @@ -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}"' diff --git a/tiptapy/templates/image.html b/tiptapy/templates/image.html index 1e210b0..6b6d3c9 100644 --- a/tiptapy/templates/image.html +++ b/tiptapy/templates/image.html @@ -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 -%}