Help page /help/faq/editing renders orphaned markdown reference-link definitions as visible junk (literal `<br />`, escaped chars)
Problem
The bottom of https://openlibrary.org/help/faq/editing (just below the "What is a web book?" section, immediately above the History panel) renders a block of broken text. It is a leftover set of markdown footnote / reference-link definitions — [23]: through [32]: — that are printed as visible raw text and links instead of being collapsed into invisible reference definitions. Inline markup inside the block also leaks through as literal text.
What renders incorrectly
All of these are localized to that one trailing block (the rest of the page is fine):
| Issue | Count | Example (as shown to users) |
|---|---|---|
Literal <br /> shown as text |
9 | …Red_Pony_Tortilla<br /> [24]: — the renderer HTML-escapes it to <br /> |
Visible [n]: reference markers |
10 | [23]:, [24]: … [32]: |
| Backslash-escaped chars shown literally | — | Tales_from_Shakespeare\_(20) |
| URL-encoded backslash leaking through | 1 | %5C_(20) |
| Links whose visible text is a raw URL | 10 | the openlibrary.org/works/… citation links |
Steps to reproduce
- Visit https://openlibrary.org/help/faq/editing
- Scroll to the bottom of the article, after the "What is a web book?" section and just above the History panel.
- Observe the block of
[23]: <url> <br /> [24]: <url> …rendered as visible junk.
Likely cause
This help page is an Infogami wiki page (history shows it as "Copy from /help/faq/editing"). Its source contains an orphaned block of markdown reference-link / footnote definitions — citation cruft, likely from a copy/import. Open Library's markdown renderer is not treating these as invisible link reference definitions, so they print as visible text, and embedded <br /> separators are HTML-escaped and shown literally.
Suggested fix
- Remove the orphaned reference-definition / footnote block from the page source.
- Investigate why these markdown reference definitions render visibly as text rather than being parsed as link reference definitions.
Environment: openlibrary.org production · observed 2026-06-30
⚠️ Contributors, this issue will be ready to work on once:
- [ ] Triage — maintainers will add
Priority: *andLead: @*to replaceNeeds: TriageandNeeds: Lead - [ ] Needs: Breakdown — a suggested breakdown is proposed below for staff to confirm
- [ ] Needs: Investigation — the
.jsoncaching discrepancy (see Context) needs root-cause investigation before a fix can be scoped
Context
- Root cause of the visible junk is identified. The reference-link parser lives in the
vendor/infogamisubmodule:ReferencePreprocessor.run()and the'reference-def'regex (vendor/infogami/infogami/utils/markdown/markdown.py:583-604,1020). For a[N]: urlline to be hidden from output, everything after the URL must be empty or wrapped in matching quotes/parens. Lines[23]–[32]end in a literal<br />(which contains a space betweenbrand/>), so the URL-matching group stops at that space and leaves/>as a leftover "title" — that fails the quote/paren check, so the entire line falls through and is rendered as visible text instead of being absorbed as a hidden reference definition. Reproduced this directly against the regex with the actual[23]line from the page source — confirms the mechanism exactly. - The block is not orphaned/dead — every one of
[1]–[32]is actually used elsewhere on the page via[text][N]reference-style links (verified by fetching/help/faq/editing.jsonand checking each][N]usage).[1]–[22]render fine because those lines don't end in<br />. Deleting the[23]–[32]block outright (as suggested in the issue) would break the "this example" / "wiki" links elsewhere on the page that depend on it — the fix needs to repair the malformed lines (or the parser), not remove them. - Prior fix attempts on this exact page didn't fully resolve it. Page history (
/help/faq/editing?m=history) shows two recent edits by lokeshd — "remove visible br tags" (rev 30) and "stray forward slashes removal" (rev 31, made shortly before this issue was filed) — but the live page still renders the same escaped junk for most of[23]–[32], consistent with those edits not fully clearing the characters that break the regex above. - The
.jsoncaching suspicion checks out, but only for the API path./help/faq/editing.jsonconsistently returnsrevision: 102,last_modified: 2021-06-14across repeated fetches (x-ol-statsheader shows a memcache hit), while the live HTML page correctly reflects revision 31 (edited recently per page history). So the.jsonendpoint is serving a stale cached snapshot that doesn't match the rendered page — confirmed, not just suspected. A previously closed issue, #2040 ("WIKI EDITS ARE BROKEN!! Users being shown & editing OUTDATED cached versions of documents"), reported the same class of symptom years ago; worth checking whether this is a regression of that or a different cache path. - The markdown renderer is in a git submodule (
vendor/infogami,github.com/internetarchive/infogami) — a parser-level fix needs to land upstream in infogami first, then get pulled into this repo via the submodule pointer bump, not edited directly here.
Issue Assessment
Open questions:
- Should the parser bug be fixed upstream in infogami, or is a content-only workaround (rewriting the
[23]–[32]lines to avoid trailing<br />/unbalanced text) sufficient for now? - Is the
.jsonstaleness specific to this page, or does it affect other wiki/help pages broadly? Worth spot-checking another/help/*page's.jsonvs. its rendered HTML.
Action items:
- [ ] Confirm scope of the
.jsonstaleness issue against at least one other help/wiki page - [ ] Decide whether the parser fix should be tracked as a separate issue against
internetarchive/infogamidirectly
Suggested breakdown:
- [ ] Fix the malformed reference-definition lines for
[23]–[32]on the live/help/faq/editingpage content (remove the trailing<br />/backslash escaping so each line matches the reference-def regex cleanly) — content-only edit, doable without code changes, though it requires understanding which exact characters break the regex (see Context) - [ ] Fix
ReferencePreprocessor/thereference-defregex invendor/infogami/infogami/utils/markdown/markdown.pyso trailing literal HTML or unbalanced text after a reference URL doesn't cause the whole line to fall through as visible text — scoped, reproducible with a unit test, Good First Issue candidate once filed against infogami - [ ] Investigate why
/help/faq/editing.jsonserves a stale memcached revision (102, dated 2021) while the rendered HTML page reflects the current revision (31) — infrastructure/caching task, not a Good First Issue
Full triage checklist (maintainers / Richy)
- [x] Triage — labels applied:
Needs: Triage,Needs: Lead,Needs: Breakdown,Needs: Investigation - [x] Problem / opportunity — problem is clear, audience identified (page viewers), actionable
- [x] Scope — well-scoped to one page's rendering, though it surfaces a sitewide parser bug and a separate caching bug
- [ ] Justification — impact stated qualitatively (broken-looking help page) but not quantified (traffic to this page, frequency)
- [x] Success & testing criteria — clear: block renders as working links, no visible
[N]:/<br />junk - [x] Proposal & breakdown — concrete plan now present (see Suggested breakdown above)
- [ ] If bug: environment & repro steps — repro steps given; browser/version not stated (likely irrelevant — server-rendered HTML)
- [x] Risks, concerns, open questions — surfaced above; no security/privacy implications
- [x] Richy context — root cause identified in vendor/infogami markdown parser; no duplicate open issue found; related prior issue #2040 noted
- [ ] References — no screenshot attached; repro steps are sufficient to verify without one
[!NOTE] This comment was automatically generated by Richy, via PAM, Open Library's Project AI Manager, on behalf of @mekarpeles. Richy is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.
Root cause (it's in the renderer, not just the content)
Tracing through OLMarkdown (openlibrary/core/olmarkdown.py, a subclass of the vendored Python-Markdown 1.6b at vendor/infogami/infogami/utils/markdown/markdown.py), the breakage is two renderer-side defects that the malformed footnote block triggers:
1. LineBreaksPreprocessor injects literal <br /> before reference defs are parsed.
OL's "newlines = line breaks" feature (olmarkdown.py:64) string-appends <br /> to every non-blank line followed by another non-blank line. It guards against link-reference lines via LINK_REFERENCE_RE (olmarkdown.py:22), but that guard only matches a line that itself starts with [id]: — not the continuation line of a wrapped reference value, nor loose text adjacent to a reference block. Critically, this preprocessor runs before REFERENCE_PREPROCESSOR (markdown.py:1072 vs 1075), so the <br /> is baked in before reference handling ever sees the line.
Minimal repro against the vendored engine — a footnote whose value wraps onto the next line:
intro
[23]: https://openlibrary.org/works/OL23185W/Short_Novels
(Cannery_Row_Of_Mice_and_Men_Tortilla
[24]: https://openlibrary.org/works/OL14876179W/Adventures
→ the continuation line renders as (Cannery_Row_Of_Mice_and_Men_Tortilla<br />, exactly the Tortilla<br /> seen live.
2. Malformed reference defs leak as visible text.
ReferencePreprocessor (markdown.py:587-602) only strips a [id]: url line when the trailing "title" is empty or a clean quoted/(...) string. The FAQ defs have unbalanced trailing parens, so the title check fails and the whole line is kept as visible text — which is why [23]: … [32]: show as raw markers with raw-URL link text.
So a stricter (CommonMark) renderer would still render the malformed defs as text, but it would never emit a literal <br /> — that part is squarely OL's LineBreaksPreprocessor. Same class of bug previously fixed for fenced code blocks (see the FencedCodePreprocessor docstring at olmarkdown.py:28, added for the identical <br />-leak symptom).
Test coverage gap
openlibrary/tests/core/test_olmarkdown.py covers bold, raw-HTML passthrough, autolinking, the basic line-break, and an extensive fenced-code suite — but has no coverage for link/reference-style definitions or the LineBreaks × Reference interaction, which is exactly where this lives. Adding a regression test there.
Correction + actual root cause: editor ↔ renderer dialect mismatch
My earlier comment pinned this on LineBreaksPreprocessor alone, but that's only half the story. The literal <br /> is escaped (<br />) on the page, which a plain <br/> injection wouldn't produce. The real cause is a markdown-dialect mismatch between the two engines:
- Display uses
OLMarkdown(vendored Python-Markdown): every newline → injected<br/>, no escape syntax for hard breaks. - Editing uses the Tiptap WYSIWYG component (
tiptap-markdown/ markdown-it), which serializes a hard break as CommonMark\+ newline (tiptap-markdown.es.js:357).
When editor-saved content is displayed, OLMarkdown appends its <br/> right after the editor's trailing \, the backslash escapes the <, and readers see the literal text <br />. Verified through the real renderer:
editor saves: 'first line\\\nsecond line'
OLMarkdown → 'first line<br />\n second line' # literal <br /> shown to reader
This is also why the page history has a "stray forward slashes removal" edit — those backslashes are the same hard-break markers. So every multi-line paragraph edited via the WYSIWYG editor accumulates this corruption, not just the orphaned footnote block.
Fix (editor + renderer)
- Editor (
openlibrary/components/lit/hard-break.js, wired intoeditor-core.js): anOLHardBreaknode that serializes hard breaks as a bare newline instead of CommonMark\. Re-saving a page through the editor now also cleans up legacy backslash/<br>cruft. - Renderer (
openlibrary/core/olmarkdown.py):LineBreaksPreprocessornow strips a lone trailing\before injecting<br/>, so already-corrupted pages display correctly without needing a re-save. (Also added a guard so a<br/>is never glued onto the line above a link-reference definition.) - Tests: JS round-trip tests (
tests/unit/js/OLMarkdownEditor.test.js) asserting hard breaks serialize without backslashes/<br>, and Python tests (openlibrary/tests/core/test_olmarkdown.py) for the hard-break and reference-block cases. Both verified to fail without the fix.
The orphaned footnote block on the FAQ page is still worth deleting from the wiki source, but the renderer now degrades gracefully instead of emitting literal markup.
A full convergence on a single markdown engine (e.g. markdown-it-py server-side to match the editor) would remove the dialect mismatch entirely and is the better long-term fix; filing that separately is reasonable.