Skip to content

Use LXML for html_to_vdom #795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Aug 14, 2022
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
43dec3b
LXML based html_to_vdom
Archmonger Aug 4, 2022
f0a3220
better interface for html_to_vdom
Archmonger Aug 4, 2022
c6ad8bf
cleanup typehints and exceptions
Archmonger Aug 4, 2022
a2d995a
variable and function name cleanup
Archmonger Aug 4, 2022
4dfde93
fix tests
Archmonger Aug 4, 2022
e5fdfc3
fix more tests
Archmonger Aug 4, 2022
f3925cb
fix transform logic
Archmonger Aug 4, 2022
8156e28
fix test warnings
Archmonger Aug 4, 2022
4600af4
rename to _prune_vdom_fields
Archmonger Aug 4, 2022
88c14c5
make safe assumption in _vdom_mutations
Archmonger Aug 4, 2022
32c5db7
docstrings
Archmonger Aug 4, 2022
55d5d13
switch back to function based approach
Archmonger Aug 4, 2022
13c7f8a
better function names
Archmonger Aug 4, 2022
e56523c
perform _generate_vdom_children in a single pass
Archmonger Aug 5, 2022
0924c5f
add changelog entry
Archmonger Aug 5, 2022
f9f169a
add null tag test
Archmonger Aug 5, 2022
4c40afc
more robust style string parser
Archmonger Aug 5, 2022
e5ca858
fix tests
Archmonger Aug 5, 2022
37b2019
remove uneeded strip
Archmonger Aug 5, 2022
64c6515
root_node position cleanup
Archmonger Aug 5, 2022
c7bc8ed
user API only accepts str
Archmonger Aug 5, 2022
4d0c03c
etree_to_vdom
Archmonger Aug 6, 2022
3f7b78e
Try to use existing root node
Archmonger Aug 7, 2022
d448102
test_html_to_vdom_with_no_parent_node
Archmonger Aug 7, 2022
2813de1
more compact formatting for tests
Archmonger Aug 7, 2022
bedab56
remove non-html from VDOM tree
Archmonger Aug 7, 2022
dcb3789
Allow for customizing whether the parser is strict
Archmonger Aug 7, 2022
e464277
make etree to vdom private
Archmonger Aug 8, 2022
0ddf937
Remove recover parameter
Archmonger Aug 8, 2022
f70cfc5
Update src/idom/utils.py
Archmonger Aug 9, 2022
e46e1fc
Update src/idom/utils.py
Archmonger Aug 9, 2022
2396169
Update src/idom/utils.py
Archmonger Aug 9, 2022
873a048
hasattr(idom.html, tagName)
Archmonger Aug 9, 2022
3bb5df0
fix tests
Archmonger Aug 9, 2022
9c69569
avoid unneeded list unpacking
Archmonger Aug 9, 2022
63acce6
more comments
Archmonger Aug 13, 2022
86fd44d
better _hypen_to_camel_case
Archmonger Aug 13, 2022
43998bd
Revert "better _hypen_to_camel_case"
Archmonger Aug 13, 2022
501e14c
use `TEMP` instead of `div` for root node
Archmonger Aug 13, 2022
40e073e
ignore coverage on type checks
Archmonger Aug 13, 2022
bde14c1
Merge branch 'fix-html-to-vdom' of https://github.com/Archmonger/idom…
Archmonger Aug 13, 2022
dd23e88
Update src/idom/utils.py
Archmonger Aug 13, 2022
5aefd37
remove prune vdom fields
Archmonger Aug 13, 2022
bf37464
type hints
Archmonger Aug 13, 2022
40116c7
_hypen_to_camel_case using string partition
Archmonger Aug 13, 2022
3999aad
fix _ModelTransform def
Archmonger Aug 13, 2022
c52791a
TypeError string update
Archmonger Aug 13, 2022
4ca1f11
Convince type checker that it's safe to mutate attributes
Archmonger Aug 14, 2022
cf532f9
test non html element behavior
rmorshea Aug 14, 2022
9262c15
remove recover=False
Archmonger Aug 14, 2022
1a23a01
Add strict parameter
Archmonger Aug 14, 2022
07b3470
add type hint
rmorshea Aug 14, 2022
fef1844
Update src/idom/utils.py
Archmonger Aug 14, 2022
66846ec
clearer verbiage
Archmonger Aug 14, 2022
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
Prev Previous commit
Next Next commit
type hints
  • Loading branch information
Archmonger committed Aug 13, 2022
commit bf374641cc0a205ddca286c42b85fbe51f0ee3cb
11 changes: 7 additions & 4 deletions src/idom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from lxml.html import fragments_fromstring

import idom
from idom.core.vdom import VdomDict


_RefValue = TypeVar("_RefValue")
Expand Down Expand Up @@ -55,7 +56,7 @@ def __repr__(self) -> str:
return f"{type(self).__name__}({current})"


def html_to_vdom(html: str, *transforms: _ModelTransform) -> Dict:
def html_to_vdom(html: str, *transforms: _ModelTransform) -> VdomDict:
"""Transform HTML into a DOM model. Unique keys can be provided to HTML elements
using a ``key=...`` attribute within your HTML tag.

Expand Down Expand Up @@ -99,7 +100,9 @@ def html_to_vdom(html: str, *transforms: _ModelTransform) -> Dict:
return vdom


def _etree_to_vdom(node: etree._Element, transforms: Iterable[_ModelTransform]) -> Dict:
def _etree_to_vdom(
node: etree._Element, transforms: Iterable[_ModelTransform]
) -> VdomDict:
"""Recusively transform an lxml etree node into a DOM model

Parameters:
Expand Down Expand Up @@ -141,7 +144,7 @@ def _etree_to_vdom(node: etree._Element, transforms: Iterable[_ModelTransform])
return vdom


def _mutate_vdom(vdom: Dict):
def _mutate_vdom(vdom: VdomDict):
"""Performs any necessary mutations on the VDOM attributes to meet VDOM spec.

Currently, this function only transforms the ``style`` attribute into a dictionary whose keys are
Expand All @@ -168,7 +171,7 @@ def _mutate_vdom(vdom: Dict):

def _generate_vdom_children(
node: etree._Element, transforms: Iterable[_ModelTransform]
) -> List[Union[Dict, str]]:
) -> List[Union[VdomDict, str]]:
"""Generates a list of VDOM children from an lxml node.

Inserts inner text and/or tail text inbetween VDOM children, if necessary.
Expand Down