diff --git a/server/aap/macros/remove_anchors.py b/server/aap/macros/remove_anchors.py index a962fa28d..4e4d18446 100644 --- a/server/aap/macros/remove_anchors.py +++ b/server/aap/macros/remove_anchors.py @@ -24,26 +24,27 @@ def remove_anchors(item, **kwargs): """ def clean_html(html): - cleaner = lxml.html.clean.Cleaner(remove_tags=['a']) + cleaner = lxml.html.clean.Cleaner(remove_tags=["a"]) + cleaner.comments = False root = lxml.html.fromstring(html) for elem in root.iter(): elem.attrib.pop("id", None) elem.attrib.pop("class", None) - if elem.tag in ('hl2', 'pre', 'note'): - elem.tag = 'p' + if elem.tag in ("hl2", "pre", "note"): + elem.tag = "p" root = cleaner.clean_html(root) return sd_etree.to_string(root, method="html") - if item.get('body_html'): - item['body_html'] = clean_html(item.get('body_html', '')) + if item.get("body_html"): + item["body_html"] = clean_html(item.get("body_html", "")) return item -name = 'Remove Anchors' -label = 'Remove Links from text' +name = "Remove Anchors" +label = "Remove Links from text" callback = remove_anchors -access_type = 'frontend' -action_type = 'direct' +access_type = "frontend" +action_type = "direct" diff --git a/server/aap/macros/remove_anchors_test.py b/server/aap/macros/remove_anchors_test.py index 35f57695f..9ddfc0e00 100644 --- a/server/aap/macros/remove_anchors_test.py +++ b/server/aap/macros/remove_anchors_test.py @@ -22,76 +22,73 @@ def test_ap_story_with_anchor(self): "_id": "tag:localhost:2017:77b03a97-df04-446e-a112-94941f1bb12c", "firstcreated": firstcreated, "subject": [ - { - "name": "lifestyle and leisure", - "qcode": "10000000" - }, - { - "name": "politics", - "qcode": "11000000" - }, - { - "name": "diplomacy", - "qcode": "11002000" - } + {"name": "lifestyle and leisure", "qcode": "10000000"}, + {"name": "politics", "qcode": "11000000"}, + {"name": "diplomacy", "qcode": "11002000"}, ], - "place": [ - { - "name": "United States" - } - ], - 'body_html': "\n

UNITED NATIONS (AP) — Days after kicking out seven U.N. " - "officials, Ethiopia accused them without providing evidence Wednesday of inflating the " - "magnitude of humanitarian crisis and taking sides in the war in its Tigray region, while " - "U.N. Secretary-General Antonio Guterres pressed the country’s ambassador for documentation " - "of the allegations.

\n

The unexpected exchange came at a Security " - "Council meeting called to discuss the officials' expulsion amid what the U.N. sees as an " - "escalating humanitarian catastrophe in the Horn of Africa nation. To some council members, " - "the ejection of the officials — most of them with the U.N.'s humanitarian agency — will " - "complicate already difficult aid operations.

\n

Ethiopian " - "Ambassador Taye Atske Selassie laid out newly detailed claims about the officials. He " - "alleged they inflated the number of needy people by 1 million, cheered the Tigrayan " - "forces who are fighting the government, invented a dozen deaths in a camp for displaced " - "people, and helped channel Ethiopian migrants from Saudi Arabia to another African nation " - "“for training and preparation” to fight with the Tigrayans, among other a" - "ccusations.

\n

“Ethiopia deeply resents this experience,\" " - "the ambassador said, adding that the government had written to the U.N. about staff conduct " - "in July.

\n

A surprised Guterres responded that he had known " - "nothing of these allegations and that he had twice asked Prime Minister Abiy Ahmed to " - "send him details on any concerns about the impartiality of U.N. staffers.

\n " - "

Guterres, who " - "maintains Ethiopia had no right under the U.N. charter to expel the officials, took a " - "rare step for a secretary-general by responding directly in the council chamber. He asked " - "the ambassador to provide any written documents that the government may have about any " - "alleged wrongdoing by any of the seven officials.

\n

“It is my " - "duty to defend the honor of the United Nations,” Guterres told reporters afterward. He said " - "if such documents are provided, the U.N. will investigate why he wasn't alerted " - "about the matter.

\n

Ethiopia announced " - "the expulsions last Thursday, accusing the U.N. officials of meddling in the country’s i" - "nternal business.

\n

The country’s foreign ministry later added " - "some more specific claims of “grave violations,” such as violating security agreements, " - "transferring communications equipment to be used by Tigray forces, spreading misinformation " - "and “politicization of humanitarian assistance.”

\n

But much of" - " what the ambassador said Wednesday had not been raised publicly before.

\n " - "

The expulsions came as the U.N. was increasingly outspoken about what it " - "calls the Ethiopian government’s de facto blockade of the Tigray region, where local forces" - " have been fighting government soldiers and allied troops since November.

\n " - "

The conflict began as a political dispute after Prime Minister Abiy Ahmed " - "sidelined the Tigrayan regional party that had dominated Ethiopia’s government for " - "decades. The clash spiraled into a war that has killed thousands of people and a " - "hunger crisis that threatens still more.

\n

Up to 7 million " - "people need food and other aid in Tigray and nearby regions where the fighting has sprea" - "d, and an estimated 400,000 people are living in “famine-like conditions,” Guterres said. " - "

\n

“The people of Ethiopia are suffering. We have no other " - "interest but to help stop that suffering,” he said.

\n

U.N. " - "humanitarian chief Martin Griffiths told The Associated " - "Press last week that only 10% of needed humanitarian supplies have been reaching " - "Tigray in recent weeks,

\n

Five of the officials expelled work " - "with the U.N. humanitarian agency, another is with the U.N. human rights office and the " - "seventh is with UNICEF, the U.N. children’s agency.

" + "place": [{"name": "United States"}], + "body_html": "\n

UNITED NATIONS (AP) — Days after kicking out seven U.N. " + "officials, Ethiopia accused them without providing evidence Wednesday of inflating the " + "magnitude of humanitarian crisis and taking sides in the war in its Tigray region, while " + "U.N. Secretary-General Antonio Guterres pressed the country’s ambassador for documentation " + "of the allegations.

\n

The unexpected exchange came at a Security " + "Council meeting called to discuss the officials' expulsion amid what the U.N. sees as an " + "escalating humanitarian catastrophe in the Horn of Africa nation. To some council members, " + "the ejection of the officials — most of them with the U.N.'s humanitarian agency — will " + "complicate already difficult aid operations.

\n

Ethiopian " + "Ambassador Taye Atske Selassie laid out newly detailed claims about the officials. He " + "alleged they inflated the number of needy people by 1 million, cheered the Tigrayan " + "forces who are fighting the government, invented a dozen deaths in a camp for displaced " + "people, and helped channel Ethiopian migrants from Saudi Arabia to another African nation " + "“for training and preparation” to fight with the Tigrayans, among other a" + 'ccusations.

\n

“Ethiopia deeply resents this experience," ' + "the ambassador said, adding that the government had written to the U.N. about staff conduct " + "in July.

\n

A surprised Guterres responded that he had known " + "nothing of these allegations and that he had twice asked Prime Minister Abiy Ahmed to " + "send him details on any concerns about the impartiality of U.N. staffers.

\n " + '

Guterres, who ' + "maintains Ethiopia had no right under the U.N. charter to expel the officials, took a " + "rare step for a secretary-general by responding directly in the council chamber. He asked " + "the ambassador to provide any written documents that the government may have about any " + "alleged wrongdoing by any of the seven officials.

\n

“It is my " + "duty to defend the honor of the United Nations,” Guterres told reporters afterward. He said " + "if such documents are provided, the U.N. will investigate why he wasn't alerted " + 'about the matter.

\n

Ethiopia announced ' + "the expulsions last Thursday, accusing the U.N. officials of meddling in the country’s i" + "nternal business.

\n

The country’s foreign ministry later added " + "some more specific claims of “grave violations,” such as violating security agreements, " + "transferring communications equipment to be used by Tigray forces, spreading misinformation " + "and “politicization of humanitarian assistance.”

\n

But much of" + " what the ambassador said Wednesday had not been raised publicly before.

\n " + "

The expulsions came as the U.N. was increasingly outspoken about what it " + "calls the Ethiopian government’s de facto blockade of the Tigray region, where local forces" + " have been fighting government soldiers and allied troops since November.

\n " + "

The conflict began as a political dispute after Prime Minister Abiy Ahmed " + "sidelined the Tigrayan regional party that had dominated Ethiopia’s government for " + "decades. The clash spiraled into a war that has killed thousands of people and a " + "hunger crisis that threatens still more.

\n

Up to 7 million " + "people need food and other aid in Tigray and nearby regions where the fighting has sprea" + "d, and an estimated 400,000 people are living in “famine-like conditions,” Guterres said. " + "

\n

“The people of Ethiopia are suffering. We have no other " + "interest but to help stop that suffering,” he said.

\n

U.N. " + 'humanitarian chief Martin Griffiths told The Associated ' + "Press last week that only 10% of needed humanitarian supplies have been reaching " + "Tigray in recent weeks,

\n

Five of the officials expelled work " + "with the U.N. humanitarian agency, another is with the U.N. human rights office and the " + "seventh is with UNICEF, the U.N. children’s agency.

", + } + + remove_anchors(item) + self.assertNotIn("http", item.get("body_html")) + + def test_story_with_embeds(self): + item = { + "body_html": '

one

\n

two

\n\n
\n ' + '\n
EDITORIAL USE ONLY
' + '
\n\n' } remove_anchors(item) - self.assertNotIn('http', item.get('body_html')) + self.assertIn("EMBED START", item.get("body_html"))