Skip to content

fix: allow newlines inside bracket link path#94

Open
LoganBarnett wants to merge 1 commit into
PoiScript:v0.10from
LoganBarnett:fix-multiline-bracket-link
Open

fix: allow newlines inside bracket link path#94
LoganBarnett wants to merge 1 commit into
PoiScript:v0.10from
LoganBarnett:fix-multiline-bracket-link

Conversation

@LoganBarnett
Copy link
Copy Markdown

Summary

Emacs org-mode treats bracket links as inline objects bounded by their
enclosing element (paragraph, list item, etc.), not by a single line. A
[[path]] or [[path][desc]] may span a newline inside either part and is
still recognised as one link by Emacs.

orgize previously excluded \n from the path take_while, so multi-line
links written by Emacs were silently dropped on parse. Description parsing
already permitted newlines, so this PR is a single-character change in
src/syntax/link.rs plus regression tests.

Why this is safe

Element-level parsers (paragraph_node, list item bodies, etc.) already
bound the input passed to link_node — paragraphs terminate at blank
lines, so the input slice handed to the link parser cannot extend past
the surrounding element. Removing the per-link newline restriction
therefore cannot let a link swallow material beyond its element.

Reproducer

The downstream project org-fmt
hit this when round-tripping documents written in Emacs:

let org = orgize::Org::parse(
    "Here is a [[really really long link\nthat just keeps going]] in prose.\n",
);
// pre-fix:  zero links found
// post-fix: one link found

Tests

Three new tests in src/syntax/link.rs:

  • parse_multiline_linklink_node directly, covering both
    newline-in-path and newline-in-description cases (snapshot assertions).
  • parse_multiline_link_in_paragraph — end-to-end via Org::parse,
    matching the downstream reproducer.

Full suite passes (148 tests), no regressions.

Notes

The commit message references the related precedent (5bc15d8 fix: newline in not allowed in property name) where the project intentionally tightened
newline handling. This change goes the other direction for links, where
Emacs explicitly allows newlines.

Emacs org-mode treats bracket links as inline objects bounded by their
enclosing element (paragraph, list item, etc.), not by a single line.
A `[[path]]` or `[[path][desc]]` may span a newline inside either part
and is still recognised as one link.

orgize 0.10 previously excluded `\n` from the path `take_while`, so
multi-line links written by Emacs were dropped on parse.  Description
parsing already allowed newlines.

The element-level parsers (e.g. `paragraph_node`) already bound the
input passed to `link_node` at blank lines, so removing the per-link
newline restriction cannot let a link escape its element.
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.

1 participant