From 74ea5136da109ddcb9c3ce45847b5dea524defe3 Mon Sep 17 00:00:00 2001 From: Angelo Gladding Date: Sun, 10 Dec 2023 19:13:05 -0800 Subject: [PATCH] Skip implied name for nested backcompat `geo` --- mf2py/parser.py | 6 ++++-- .../implied_nested_backcompat.html | 4 ++++ test/test_parser.py | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/examples/implied_properties/implied_nested_backcompat.html diff --git a/mf2py/parser.py b/mf2py/parser.py index f099c69..ce9fb52 100644 --- a/mf2py/parser.py +++ b/mf2py/parser.py @@ -241,8 +241,10 @@ def handle_microformat( # if some properties not already found find in implied ways unless in backcompat mode if not backcompat_mode: # stop implied name if any p-*, e-*, h-* is already found - if "name" not in properties and parsed_types_aggregation.isdisjoint( - "peh" + if ( + "name" not in properties + and parsed_types_aggregation.isdisjoint("peh") + and "h-geo" not in el.attrs["class"] # skip nested backcompat geo ): properties["name"] = [ implied_properties.name(el, self.__url__, self.filtered_roots) diff --git a/test/examples/implied_properties/implied_nested_backcompat.html b/test/examples/implied_properties/implied_nested_backcompat.html new file mode 100644 index 0000000..83be50d --- /dev/null +++ b/test/examples/implied_properties/implied_nested_backcompat.html @@ -0,0 +1,4 @@ +
+
John Doe
+
Location: Brighton
+
diff --git a/test/test_parser.py b/test/test_parser.py index 767d369..1a411ee 100644 --- a/test/test_parser.py +++ b/test/test_parser.py @@ -540,6 +540,25 @@ def test_implied_nested_photo_alt_name(): assert result["items"][3]["properties"]["name"][0] == "Tom Morris" +def test_implied_nested_backcompat(): + result = parse_fixture("implied_properties/implied_nested_backcompat.html") + hcard = result["items"][0] + + assert { + "type": ["h-card"], + "properties": { + "name": ["John Doe"], + "geo": [ + { + "type": ["h-geo"], + "properties": {"url": ["https://brighton.co.uk"]}, + "value": "30.267991;-97.739568", + } + ], + }, + } == hcard + + def test_implied_image(): result = parse_fixture("implied_properties/implied_properties.html") assert result["items"][4]["properties"]["photo"][0] == {