Skip to content

Fix issue #865 - #1439

Open
Tim-ats-d wants to merge 4 commits into
ocaml:masterfrom
Tim-ats-d:multines-line-link
Open

Fix issue #865#1439
Tim-ats-d wants to merge 4 commits into
ocaml:masterfrom
Tim-ats-d:multines-line-link

Conversation

@Tim-ats-d

@Tim-ats-d Tim-ats-d commented May 22, 2026

Copy link
Copy Markdown

First try to fix the issue #865. The patch is dead simple, I've only added a multilines_link_to_link which properly reformats multi lines link into normal ones.

As I'm not yet really familiar with the Odoc codebase, don't hesitate to tell where can I define the multilines_link_to_link function or if the test need to reside in its own file!

Cc @panglesd

@panglesd panglesd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I left some comments. This also needs a change entry!

Comment thread src/parser/syntax.ml
Comment thread src/parser/syntax.ml Outdated
Comment on lines +171 to +178
let multilines_link_to_link link =
String.split_on_char '\n' link
|> List.map (fun line ->
String.trim @@
if String.ends_with ~suffix:{|\|} line then
String.(sub line 0 (length line - 1))
else line)
|> String.concat ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does not really correspond to what we expect (escaping newlines):

a
b\      <--- there are whitespace after the \
c\      <--- no newlines after the \

will be interpreted as abc. The biggest problem probably being that the trailing \ is removed (?)

Comment thread src/parser/syntax.ml Outdated
Comment thread src/parser/syntax.ml Outdated
@Tim-ats-d
Tim-ats-d force-pushed the multines-line-link branch from dc5e535 to c245e0d Compare May 27, 2026 10:45
@Tim-ats-d

Copy link
Copy Markdown
Author

I've changed the behavior to be more fine-grained. Ending backslash should now be preserved in the extracted link.
Here are some examples:

{{:https://github.com/ocaml/\
   odoc/\
issues/\
                865\  }this issue}

=> https://github.com/ocaml/odoc/issues/865\

{{:https://github.com/ocaml/\
   odoc/issues/\

865

}this issue}

=> https://github.com/ocaml/odoc/issues/865

{{:https://github.com/ocaml/odoc/issues/\
865/   /\
ending worlds}this issue} 

=> https://github.com/ocaml/odoc/issues/865/ /ending worlds"

@Tim-ats-d
Tim-ats-d force-pushed the multines-line-link branch from 822e7d1 to a1f7ca7 Compare July 20, 2026 14:12

@panglesd panglesd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(I've checked in the definition of a URI, whitespace and \ are not allowed in URI. Which does not mean they should be removed, it would be surprising as browsers handle their percent-encoding.)

One sentence should be added to the docs. Without it, it is difficult to say whether there is a bug in the implementation, or if it had the behaviour you wanted. My problem with the current implementation is that they cannot satisfyingly be expressed in English. ("When a backslash is followed by whitespace, remove both except at the end where if there is no whitespace the backslash is kept").

I suggest to make it either:

When a backslash is followed by whitespace, both are removed

which implies a small modification to your code

or:

Removes all backlashes and the space that follows them

which has a simpler implementation but is more invasive. I think I prefer the first one.

Could you add a sentence in the docs that says what is done to backslash and whitespace, and have the implementation correspond?

Comment thread src/parser/syntax.ml Outdated
Comment thread src/parser/syntax.ml Outdated
Comment thread src/parser/syntax.ml Outdated
Comment on lines +182 to +184
| (`Backslash | `Escaping), _ ->
Buffer.add_char buf chr;
`Char)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The docs says:

When a backslash is followed by whitespace, both are removed.

but here, even without whitespace, the backslash is removed...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
| (`Backslash | `Escaping), _ ->
Buffer.add_char buf chr;
`Char)
| (`Backslash | `Escaping), _ ->
if state = `Backslash then Buffer.add_char buf '\\';
Buffer.add_char buf chr;
`Char)

or a more elegant version if you have one.

Actually see https://github.com/ocaml/odoc/pull/1439/changes#r3623267227

Comment thread src/parser/syntax.ml Outdated
@Tim-ats-d

Copy link
Copy Markdown
Author

Should be fine now 😄

@panglesd panglesd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me! Thanks!

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.

2 participants