From 9ed8aec16a94afde716de2b4ebf64236859a6123 Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Wed, 21 Feb 2024 15:30:51 +0000 Subject: [PATCH 1/7] Add test --- test/generators/cases/markup.mli | 2 ++ test/generators/html/Markup.html | 5 +++++ test/generators/latex/Markup.tex | 3 +++ test/generators/man/Markup.3o | 3 +++ 4 files changed, 13 insertions(+) diff --git a/test/generators/cases/markup.mli b/test/generators/cases/markup.mli index 81d20ec473..2a824cce19 100644 --- a/test/generators/cases/markup.mli +++ b/test/generators/cases/markup.mli @@ -57,6 +57,8 @@ Code can appear {b inside [other] markup}. Its display shouldn't be affected. + There is no differences between [a b] and [a + b]. {1 Links and references} diff --git a/test/generators/html/Markup.html b/test/generators/html/Markup.html index 056e53af61..f41ac6a7a7 100644 --- a/test/generators/html/Markup.html +++ b/test/generators/html/Markup.html @@ -123,6 +123,11 @@

Code can appear inside other markup. Its display shouldn't be affected.

+

There is no differences between a b and + a + b + . +

diff --git a/test/generators/latex/Markup.tex b/test/generators/latex/Markup.tex index 70ecd380fd..a0ae689609 100644 --- a/test/generators/latex/Markup.tex +++ b/test/generators/latex/Markup.tex @@ -34,6 +34,9 @@ \subsection{Styling\label{styling}}% Code can appear \bold{inside \ocamlinlinecode{other} markup}. Its display shouldn't be affected. +There is no differences between \ocamlinlinecode{a b} and \ocamlinlinecode{a + b}. + \subsection{Links and references\label{links-and-references}}% This is a \href{\#}{link}\footnote{\url{\#}}. It sends you to the top of this page. Links can have markup inside them: \href{\#}{\bold{bold}}\footnote{\url{\#}}, \href{\#}{\emph{italics}}\footnote{\url{\#}}, \href{\#}{\emph{emphasis}}\footnote{\url{\#}}, \href{\#}{super\textsuperscript{script}}\footnote{\url{\#}}, \href{\#}{sub\textsubscript{script}}\footnote{\url{\#}}, and \href{\#}{\ocamlinlinecode{code}}\footnote{\url{\#}}. Links can also be nested \emph{\href{\#}{inside}\footnote{\url{\#}}} markup. Links cannot be nested inside each other. This link has no replacement text: \href{\#}{\#}\footnote{\url{\#}}. The text is filled in by odoc. This is a shorthand link: \href{\#}{\#}\footnote{\url{\#}}. The text is also filled in by odoc in this case. diff --git a/test/generators/man/Markup.3o b/test/generators/man/Markup.3o index e28eb65f17..cb2cdc6a0f 100644 --- a/test/generators/man/Markup.3o +++ b/test/generators/man/Markup.3o @@ -85,6 +85,9 @@ It's possible for two markup elements to appear \fBnext\fR \fIto\fR each other a This is also true between non-code markup and code\. .sp Code can appear \fBinside other markup\fR\. Its display shouldn't be affected\. +.sp +There is no differences between a b and a + b\. .nf .sp .in 3 From 3acdd04e0c6372fc1e402b78b975ca52fc4f62bf Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Wed, 21 Feb 2024 15:41:30 +0000 Subject: [PATCH 2/7] Normalize tests in code spans --- CHANGES.md | 2 ++ src/parser/lexer.mll | 8 +++++--- src/parser/test/test.ml | 6 ++---- test/generators/html/Markup.html | 5 +---- test/generators/latex/Markup.tex | 3 +-- test/generators/man/Markup.3o | 3 +-- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b567b5957b..ad192926be 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,8 @@ - Updated colors for code fragments (@EmileTrotignon, #1023) - Fixed complexity of looking up `.odoc` files (@panglesd, #1075) +- Normalize whitespaces in codespans (@gpetiot, #1085) + A newline followed by any whitespaces is normalized as one space character. ### Changed diff --git a/src/parser/lexer.mll b/src/parser/lexer.mll index 0cde0b4343..ec24c5c3e3 100644 --- a/src/parser/lexer.mll +++ b/src/parser/lexer.mll @@ -263,6 +263,8 @@ let horizontal_space = [' ' '\t'] let newline = '\n' | "\r\n" +let whitespace = + horizontal_space | newline let reference_start = "{!" | "{{!" | "{:" | "{{:" @@ -609,13 +611,13 @@ and code_span buffer nesting_level start_offset input = parse { Buffer.add_char buffer c; code_span buffer nesting_level start_offset input lexbuf } - | newline newline + | newline whitespace+ as sp { warning input (Parse_error.not_allowed - ~what:(Token.describe (`Blank_line "\n\n")) + ~what:(Token.describe (`Blank_line sp)) ~in_what:(Token.describe (`Code_span ""))); - Buffer.add_char buffer '\n'; + Buffer.add_char buffer ' '; code_span buffer nesting_level start_offset input lexbuf } | eof diff --git a/src/parser/test/test.ml b/src/parser/test/test.ml index caed0e7f6e..80403a11b2 100644 --- a/src/parser/test/test.ml +++ b/src/parser/test/test.ml @@ -817,8 +817,7 @@ let%expect_test _ = {| ((output (((f.ml (1 0) (3 4)) - (paragraph (((f.ml (1 0) (3 4)) (code_span "foo\ - \nbar"))))))) + (paragraph (((f.ml (1 0) (3 4)) (code_span "foo bar"))))))) (warnings ( "File \"f.ml\", line 1, character 4 to line 3, character 0:\ \nBlank line is not allowed in '[...]' (code)."))) |}] @@ -829,8 +828,7 @@ let%expect_test _ = {| ((output (((f.ml (1 0) (3 4)) - (paragraph (((f.ml (1 0) (3 4)) (code_span "foo\ - \nbar"))))))) + (paragraph (((f.ml (1 0) (3 4)) (code_span "foo bar"))))))) (warnings ( "File \"f.ml\", line 1, character 4 to line 3, character 0:\ \nBlank line is not allowed in '[...]' (code)."))) |}] diff --git a/test/generators/html/Markup.html b/test/generators/html/Markup.html index f41ac6a7a7..0de80bf90f 100644 --- a/test/generators/html/Markup.html +++ b/test/generators/html/Markup.html @@ -123,10 +123,7 @@

Code can appear inside other markup. Its display shouldn't be affected.

-

There is no differences between a b and - a - b - . +

There is no differences between a b and a b.