Skip to content

Commit

Permalink
Avoids unwanted line breaks on inline code
Browse files Browse the repository at this point in the history
  • Loading branch information
steineggerroland committed Jan 13, 2025
1 parent a48f637 commit 959560e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions trafilatura/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@

CONTROL_PARSER = XMLParser(remove_blank_text=True)

NEWLINE_ELEMS = {'code', 'graphic', 'head', 'lb', 'list', 'p', 'quote', 'row', 'table'}
SPECIAL_FORMATTING = {'del', 'head', 'hi', 'ref'}
NEWLINE_ELEMS = {'graphic', 'head', 'lb', 'list', 'p', 'quote', 'row', 'table'}
WITH_ATTRIBUTES = {'cell', 'row', 'del', 'graphic', 'head', 'hi', 'item', 'list', 'ref'}
NESTING_WHITELIST = {"cell", "figure", "item", "note", "quote"}

Expand Down Expand Up @@ -269,7 +268,7 @@ def replace_element_text(element: _Element, include_formatting: bool) -> str:
elem_text = f"{HI_FORMATTING[rend]}{elem_text}{HI_FORMATTING[rend]}"
elif element.tag == "code":
if "\n" in element.text:
elem_text = f"```\n{elem_text}\n```"
elem_text = f"```\n{elem_text}\n```\n"
else:
elem_text = f"`{elem_text}`"
# handle links
Expand Down

0 comments on commit 959560e

Please sign in to comment.