Skip to content

feat: paragraph links - #91

Open
holloway wants to merge 2 commits into
mainfrom
paragraph-links
Open

holloway wants to merge 2 commits into
mainfrom
paragraph-links

Conversation

@holloway

Copy link
Copy Markdown

Add opt-in paragraph links (paragraph_links)

Adds an opt-in feature that puts a link target at the start of every paragraph and a pilcrow link at the end, using the same ids as the HTML for RFCs published as XML (RFC 8650 onwards, e.g. rfc9000.html). This lets text-only documents be deep-linked the same way.

   <a id="section-1-1"></a>Paragraph text...<a href="#section-1-1" class="pilcrow"></a>

Usage

  • Python: markup(text, paragraph_links=True)
  • CLI: rfc2html -p / --paragraph-links
  • Off by default. With the flag off, output is unchanged. I checked this on RFC 2616: stripping the added tags from the flag-on output gives exactly the flag-off output.

Ids

  • section-abstract-N
  • section-boilerplate.N-k for Status of This Memo and Copyright Notice
  • section-2.1-3 for numbered sections
  • section-appendix.a-N for top-level appendices, and section-a.1-k for appendix subsections
  • Unnumbered back matter such as Contributors continues the appendix lettering, as in the XML-derived HTML

Behaviour

  • Implemented as a final pass, _paragraph_links(), just before the page-break split, so none of the existing regexes see the new tags.
  • No links in the TOC, references, Authors' Addresses, Index, or text before the first section.
  • A paragraph that crosses a page break gets one id and one pilcrow. Page headers and footers are skipped.
  • Figures, tables and lists get no ids but advance the counter, so later ids stay aligned with the XML-derived HTML.
  • No CSS is added (the repo ships none); consumers style a.pilcrow.

Validation

I compared the generated ids with the <p id="section-N-k"> paragraphs in the rfc-editor.org HTML:

RFC Matched Reference paragraphs
9000 989 993
9001 317 319

Known limitations

  • Plain text has no explicit structure, so figure, list and page-break handling is heuristic. Unusual documents may get shifted numbers.
  • We add a few ids the XML version lacks, e.g. one-line pseudocode at body indent, and paragraphs the XML nests inside list items. That is about 11 extra ids in RFC 9000 and 16 in RFC 9001.
  • No list-item ids (section-N-k.j); left for a follow-up.

Other changes

  • Add a .gitignore (the repo had none; __pycache__ had been getting staged).
  • Document the feature in the README.
  • Add 8 tests covering ids, page breaks, figures, the TOC, and the flag being off.

@holloway

Copy link
Copy Markdown
Author

Fixes #90

@kesara kesara left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests seem to fail because of flake8 lint checks.

./rfc2html.py:185:25: W503 line break before binary operator
./rfc2html.py:186:25: W503 line break before binary operator
./rfc2html.py:187:25: W503 line break before binary operator

@holloway

Copy link
Copy Markdown
Author

@kesara thanks, fixed!

suncionjimenezflores-ops

This comment was marked as spam.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants