From 432bac4a4f2134fa054e434abb7879bc2e445355 Mon Sep 17 00:00:00 2001 From: rajat singla Date: Tue, 3 Jun 2025 15:44:01 +0530 Subject: [PATCH 1/6] added support for string type src in image --- tests/data/html/image-src_string.html | 1 + tests/data/json/image-src_string.json | 15 +++++++++++++++ tests/test_transform.py | 1 + tiptapy/macros.py | 6 +++++- tiptapy/templates/image.html | 4 ++-- 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/data/html/image-src_string.html create mode 100644 tests/data/json/image-src_string.json 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/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 -%} From 9e23d413176ee750e6783e9b6c8ab80973ef1cfb Mon Sep 17 00:00:00 2001 From: rajat singla Date: Tue, 3 Jun 2025 15:45:35 +0530 Subject: [PATCH 2/6] fix pipeline --- .github/workflows/tiptapy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tiptapy.yml b/.github/workflows/tiptapy.yml index 4245742..4f79f6e 100644 --- a/.github/workflows/tiptapy.yml +++ b/.github/workflows/tiptapy.yml @@ -19,9 +19,9 @@ jobs: python-version: [ 3.7, 3.8, 3.9] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 86f53d7c5c8c7615b66d727593ca2c3b7508fd3a Mon Sep 17 00:00:00 2001 From: rajat singla Date: Tue, 3 Jun 2025 15:48:13 +0530 Subject: [PATCH 3/6] fix pipeline --- .github/workflows/tiptapy.yml | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tiptapy.yml b/.github/workflows/tiptapy.yml index 4f79f6e..ca68c3c 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.7, 3.8, 3.9, 3.10] steps: - - 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 + - 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 From aaa0a680d679018e217337f4d52e18bb64d07eb6 Mon Sep 17 00:00:00 2001 From: rajat singla Date: Tue, 3 Jun 2025 15:49:21 +0530 Subject: [PATCH 4/6] fix pipeline --- .github/workflows/tiptapy.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tiptapy.yml b/.github/workflows/tiptapy.yml index ca68c3c..4678d6e 100644 --- a/.github/workflows/tiptapy.yml +++ b/.github/workflows/tiptapy.yml @@ -15,14 +15,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, 3.10] + python-version: [3.7, 3.8, 3.9] steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python 3.8 uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python-version }} + python-version: 3.8 - name: Install dependencies run: | python -m pip install --upgrade pip jinja2 From 2d5687d30438ce082c70fa0fdf0ec689fb1792bb Mon Sep 17 00:00:00 2001 From: rajat singla Date: Tue, 3 Jun 2025 15:50:48 +0530 Subject: [PATCH 5/6] fix pipeline --- .github/workflows/tiptapy.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tiptapy.yml b/.github/workflows/tiptapy.yml index 4678d6e..7e7be0d 100644 --- a/.github/workflows/tiptapy.yml +++ b/.github/workflows/tiptapy.yml @@ -15,14 +15,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: [3.8, 3.9] steps: - uses: actions/checkout@v4 - - name: Set up Python 3.8 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip jinja2 From eb6bb1c95fbf2b8cc7f8ba83df462a23c535ee10 Mon Sep 17 00:00:00 2001 From: rajat singla Date: Tue, 3 Jun 2025 15:52:58 +0530 Subject: [PATCH 6/6] =?UTF-8?q?Bump=20version:=200.20.0=20=E2=86=92=200.21?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.cfg | 2 +- setup.py | 2 +- tiptapy/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/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 = {}