Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/assets/protocolith/concept_d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/assets/protocolith/logo-mark-v2-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/assets/protocolith/logo-mark-v2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/assets/protocolith/logo-v2-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/assets/protocolith/logo-v2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions scripts/protocolith_run_esa_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def _write_json(path: Path, data: object) -> bytes:

def _normalize_html(payload: bytes) -> str:
text = payload.decode("utf-8", errors="replace")
text = re.sub(r"<script\b[^>]*>.*?</script>", " ", text, flags=re.I | re.S)
text = re.sub(r"<style\b[^>]*>.*?</style>", " ", text, flags=re.I | re.S)
text = re.sub(r"<script\b[^>]*>.*?</script[^>]*>", " ", text, flags=re.I | re.S)
text = re.sub(r"<style\b[^>]*>.*?</style[^>]*>", " ", text, flags=re.I | re.S)
text = re.sub(r"<[^>]+>", " ", text)
text = html.unescape(text)
for before, after in {
Expand Down
2 changes: 1 addition & 1 deletion scripts/protocolith_run_leqembi_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def sha(data: bytes) -> str:

def normalized(data: bytes) -> str:
text = data.decode("utf-8", "replace")
text = re.sub(r"<script\b[^>]*>.*?</script>|<style\b[^>]*>.*?</style>", " ", text, flags=re.I | re.S)
text = re.sub(r"<script\b[^>]*>.*?</script[^>]*>|<style\b[^>]*>.*?</style[^>]*>", " ", text, flags=re.I | re.S)
text = html.unescape(re.sub(r"<[^>]+>", " ", text))
return re.sub(r"\s+", " ", text).strip()

Expand Down
4 changes: 2 additions & 2 deletions scripts/protocolith_run_nasa_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def _write_json(path: Path, data: object) -> bytes:

def _normalize_html(payload: bytes) -> str:
text = payload.decode("utf-8", errors="replace")
text = re.sub(r"<script\b[^>]*>.*?</script>", " ", text, flags=re.I | re.S)
text = re.sub(r"<style\b[^>]*>.*?</style>", " ", text, flags=re.I | re.S)
text = re.sub(r"<script\b[^>]*>.*?</script[^>]*>", " ", text, flags=re.I | re.S)
text = re.sub(r"<style\b[^>]*>.*?</style[^>]*>", " ", text, flags=re.I | re.S)
text = re.sub(r"<[^>]+>", " ", text)
text = html.unescape(text)
for before, after in {
Expand Down
10 changes: 8 additions & 2 deletions src/protocolith/core/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

_MISSING_RE = re.compile(r"^missing (?:required |forecast |public claim )?field: (\w+)$")
_MUST_INCLUDE_RE = re.compile(r"must include (\w+)$")
_XML_INVALID = re.compile("[\x00-\x08\x0b\x0c\x0e-\x1f\ufffe\uffff]") # not allowed in XML 1.0 documents
# Characters that are not allowed in XML 1.0 documents (listed as code points, not as a regular expression range).
_XML_INVALID = frozenset(map(chr, (*range(0x00, 0x09), 0x0B, 0x0C, *range(0x0E, 0x20), 0xFFFE, 0xFFFF)))


def _xml_safe(text: str) -> str:
"""Replace the characters XML 1.0 cannot carry with U+FFFD."""
return "".join("\ufffd" if ch in _XML_INVALID else ch for ch in text)


def _missing_names(violations: list[str]) -> list[str]:
Expand Down Expand Up @@ -94,5 +100,5 @@ def write_card_files(card: dict[str, Any], out_dir: Path) -> tuple[Path, Path]:
raise InputError("CARD_EXISTS", f"{json_path.name} already exists with different content; use another --out")
_atomic_write(json_path, payload)
# Card text is user data and may hold characters XML 1.0 forbids; the JSON card keeps them verbatim.
_atomic_write(svg_path, _XML_INVALID.sub("\ufffd", render_svg(json_path)).encode("utf-8"))
_atomic_write(svg_path, _xml_safe(render_svg(json_path)).encode("utf-8"))
return json_path, svg_path
Loading