The readers flattened a posting's HTML into one line with strip_html, so sections and bullets ran together. _shared.html_text gives a line per paragraph, '• ' before a list item and '## ' before a heading; every reader's description goes through it, sections read per role get their own headings, and the reader pane draws the lines as h3, ul and p. Excerpts leave the marks out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
"""`html_text`: a host's description HTML as lines that keep its headings,
|
|
bullets and paragraphs, and `excerpt` leaving those marks out of a row."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from app.models import excerpt # noqa: E402
|
|
from plugins.readers._shared import html_text # noqa: E402
|
|
|
|
|
|
def test_blocks_become_lines_lists_bullets_and_headings_marks() -> None:
|
|
markup = ("<h2>About</h2><p>We are <b>great</b>.</p>"
|
|
"<p><strong>What you will do:</strong></p>"
|
|
"<ul><li><p>Build & ship</p></li><li>Lead<ul><li>nested</li></ul></li></ul>"
|
|
"<p>Line one<br>Line two</p><script>x = 1</script>")
|
|
assert html_text(markup) == ("## About\nWe are great.\n## What you will do:\n"
|
|
"• Build & ship\n• Lead\n• nested\n"
|
|
"Line one\nLine two")
|
|
|
|
|
|
def test_a_long_bold_paragraph_is_not_a_heading() -> None:
|
|
loud = "<p><b>" + "Apply now " * 10 + "</b></p>"
|
|
assert not html_text(loud).startswith("## ")
|
|
|
|
|
|
def test_markup_escaped_once_more_is_read_as_markup() -> None:
|
|
assert html_text("<p>Hello &amp; bye</p><ul><li>a</li></ul>") \
|
|
== "Hello & bye\n• a"
|
|
|
|
|
|
def test_plain_text_keeps_its_lines_and_typed_bullets_become_bullets() -> None:
|
|
assert html_text("plain text\n\n* one\n- two\nR&D < 5") == \
|
|
"plain text\n• one\n• two\nR&D < 5"
|
|
|
|
|
|
def test_nothing_gives_nothing() -> None:
|
|
assert html_text(None) == html_text("") == html_text("<p> </p>") == ""
|
|
|
|
|
|
def test_the_row_excerpt_leaves_the_marks_out() -> None:
|
|
assert excerpt("## About the role\n• Build & run care.") == "About the role Build & run care."
|