Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
2 changes: 1 addition & 1 deletion 2 portabletext_html/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def render(self) -> str:

if list_nodes and not is_list(node):
tree = self._normalize_list_tree(list_nodes)
result += ''.join([self._render_node(n, Block(**node), list_item=True) for n in tree])
result += ''.join([self._render_node(n, list_item=True) for n in tree])
list_nodes = [] # reset list_nodes

if is_list(node):
Expand Down
2 changes: 1 addition & 1 deletion 2 pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = 'portabletext-html'
version = '1.1.2'
version = '1.1.3'
description = "HTML renderer for Sanity's Portable Text format"
homepage = 'https://github.com/otovo/python-sanity-html'
repository = 'https://github.com/otovo/python-sanity-html'
Expand Down
20 changes: 20 additions & 0 deletions 20 tests/fixtures/custom_serializer_node_after_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"_key": "e5b6e416e6e9",
"_type": "block",
"children": [
{ "_key": "3bbbff0f158b", "_type": "span", "marks": [], "text": "resers" }
],
"level": 1,
"listItem": "bullet",
"markDefs": [],
"style": "normal"
},
{
"_key": "73405dda68e0",
"_type": "extraInfoBlock",
"extraInfo": "This informations is not supported by Block",
"markDefs": [],
"style": "normal"
}
]
15 changes: 15 additions & 0 deletions 15 tests/test_rendering.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import html
import json
from pathlib import Path
from typing import Optional

import pytest

from portabletext_html.renderer import MissingSerializerError, UnhandledNodeError, render
from portabletext_html.types import Block


def extraInfoSerializer(node: dict, context: Optional[Block], list_item: bool) -> str:
extraInfo = node.get('extraInfo')

return f'<p>{extraInfo}</p>'


def load_fixture(fixture_name) -> dict:
Expand Down Expand Up @@ -59,3 +67,10 @@ def test_invalid_node():
fixture = load_fixture('invalid_node.json')
with pytest.raises(UnhandledNodeError):
render(fixture)


def test_custom_serializer_node_after_list():
fixture = load_fixture('custom_serializer_node_after_list.json')
output = render(fixture, custom_serializers={'extraInfoBlock': extraInfoSerializer})

assert output == '<div><ul><li>resers</li></ul><p>This informations is not supported by Block</p></div>'
Morty Proxy This is a proxified and sanitized view of the page, visit original site.