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

Commit ce9ecbb

Browse filesBrowse files
authored
Merge pull request #44 from otovo/espenra/custom-serializer-after-list-bug
Custom serializer + list bug
2 parents 31718a7 + 8e895e3 commit ce9ecbb
Copy full SHA for ce9ecbb

File tree

Expand file treeCollapse file tree

4 files changed

+37
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+37
-2
lines changed

‎portabletext_html/renderer.py

Copy file name to clipboardExpand all lines: portabletext_html/renderer.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def render(self) -> str:
6666

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

7272
if is_list(node):

‎pyproject.toml

Copy file name to clipboardExpand all lines: pyproject.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = 'portabletext-html'
3-
version = '1.1.2'
3+
version = '1.1.3'
44
description = "HTML renderer for Sanity's Portable Text format"
55
homepage = 'https://github.com/otovo/python-sanity-html'
66
repository = 'https://github.com/otovo/python-sanity-html'
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"_key": "e5b6e416e6e9",
4+
"_type": "block",
5+
"children": [
6+
{ "_key": "3bbbff0f158b", "_type": "span", "marks": [], "text": "resers" }
7+
],
8+
"level": 1,
9+
"listItem": "bullet",
10+
"markDefs": [],
11+
"style": "normal"
12+
},
13+
{
14+
"_key": "73405dda68e0",
15+
"_type": "extraInfoBlock",
16+
"extraInfo": "This informations is not supported by Block",
17+
"markDefs": [],
18+
"style": "normal"
19+
}
20+
]

‎tests/test_rendering.py

Copy file name to clipboardExpand all lines: tests/test_rendering.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import html
22
import json
33
from pathlib import Path
4+
from typing import Optional
45

56
import pytest
67

78
from portabletext_html.renderer import MissingSerializerError, UnhandledNodeError, render
9+
from portabletext_html.types import Block
10+
11+
12+
def extraInfoSerializer(node: dict, context: Optional[Block], list_item: bool) -> str:
13+
extraInfo = node.get('extraInfo')
14+
15+
return f'<p>{extraInfo}</p>'
816

917

1018
def load_fixture(fixture_name) -> dict:
@@ -59,3 +67,10 @@ def test_invalid_node():
5967
fixture = load_fixture('invalid_node.json')
6068
with pytest.raises(UnhandledNodeError):
6169
render(fixture)
70+
71+
72+
def test_custom_serializer_node_after_list():
73+
fixture = load_fixture('custom_serializer_node_after_list.json')
74+
output = render(fixture, custom_serializers={'extraInfoBlock': extraInfoSerializer})
75+
76+
assert output == '<div><ul><li>resers</li></ul><p>This informations is not supported by Block</p></div>'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.