Keep a description's headings, bullets and paragraphs, and draw them in the reader
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>
This commit is contained in:
1 parent
17e7615599
commit
c497fe965d
44 files changed
+300
-147
No files matched your search
@@ -16,15 +16,13 @@ so `posted` stays None rather than costing a request a role for it.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import html
|
||||
import json
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from desk.sources import strip_html
|
||||
|
||||
from ._contract import Ask, Fields, Reads
|
||||
from ._shared import Row, is_web_url, label_slug_ok, num, only, pay_line, yearly_amount
|
||||
from ._shared import HEADING, Row, html_text, is_web_url, label_slug_ok, num, only, pay_line, yearly_amount
|
||||
|
||||
NAME = "pinpoint"
|
||||
LABEL = "Pinpoint"
|
||||
@@ -70,22 +68,17 @@ def feed_url(slug: str, ask: Ask = Ask()) -> str:
|
||||
return f"https://{host(slug)}/postings.json"
|
||||
|
||||
|
||||
def _plain(markup: Any) -> str:
|
||||
"""HTML as one line of plain text: the tags out, the entities read (Pinpoint
|
||||
writes `&` and ` `), the whitespace, non-breaking included, collapsed."""
|
||||
return " ".join(html.unescape(strip_html(str(markup or ""))).split())
|
||||
|
||||
|
||||
def _text(j: dict[str, Any]) -> str:
|
||||
"""The description and the sections after it, each section under its own
|
||||
heading, as plain text with a blank line between them."""
|
||||
parts = [_plain(j.get("description"))]
|
||||
heading, as `html_text` lines."""
|
||||
parts = [html_text(j.get("description"))]
|
||||
for field in _SECTIONS:
|
||||
body = _plain(j.get(field))
|
||||
body = html_text(j.get(field))
|
||||
if body:
|
||||
heading = str(j.get(f"{field}_header") or "").strip()
|
||||
parts.append(f"{heading}: {body}" if heading else body)
|
||||
return "\n\n".join(p for p in parts if p)
|
||||
if heading := " ".join(str(j.get(f"{field}_header") or "").split()):
|
||||
parts.append(HEADING + heading)
|
||||
parts.append(body)
|
||||
return "\n".join(p for p in parts if p)
|
||||
|
||||
|
||||
def _place(location: dict[str, Any]) -> str:
|
||||
|
||||
Reference in new issue
Block a user