Skip to content

Commit ef09006

Browse files
gpetiotjonludlam
authored andcommitted
Normalize tests in code spans
1 parent 0eb22a3 commit ef09006

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
- Updated colors for code fragments (@EmileTrotignon, #1023)
1818
- Fixed complexity of looking up `.odoc` files (@panglesd, #1075)
19+
- Normalize whitespaces in codespans (@gpetiot, #1085)
20+
A newline followed by any whitespaces is normalized as one space character.
1921

2022
### Changed
2123

src/parser/lexer.mll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ let horizontal_space =
263263
[' ' '\t']
264264
let newline =
265265
'\n' | "\r\n"
266+
let whitespace =
267+
horizontal_space | newline
266268

267269
let reference_start =
268270
"{!" | "{{!" | "{:" | "{{:"
@@ -609,13 +611,13 @@ and code_span buffer nesting_level start_offset input = parse
609611
{ Buffer.add_char buffer c;
610612
code_span buffer nesting_level start_offset input lexbuf }
611613

612-
| newline newline
614+
| newline whitespace+ as sp
613615
{ warning
614616
input
615617
(Parse_error.not_allowed
616-
~what:(Token.describe (`Blank_line "\n\n"))
618+
~what:(Token.describe (`Blank_line sp))
617619
~in_what:(Token.describe (`Code_span "")));
618-
Buffer.add_char buffer '\n';
620+
Buffer.add_char buffer ' ';
619621
code_span buffer nesting_level start_offset input lexbuf }
620622

621623
| eof

src/parser/test/test.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,7 @@ let%expect_test _ =
817817
{|
818818
((output
819819
(((f.ml (1 0) (3 4))
820-
(paragraph (((f.ml (1 0) (3 4)) (code_span "foo\
821-
\nbar")))))))
820+
(paragraph (((f.ml (1 0) (3 4)) (code_span "foo bar")))))))
822821
(warnings
823822
( "File \"f.ml\", line 1, character 4 to line 3, character 0:\
824823
\nBlank line is not allowed in '[...]' (code)."))) |}]
@@ -829,8 +828,7 @@ let%expect_test _ =
829828
{|
830829
((output
831830
(((f.ml (1 0) (3 4))
832-
(paragraph (((f.ml (1 0) (3 4)) (code_span "foo\
833-
\nbar")))))))
831+
(paragraph (((f.ml (1 0) (3 4)) (code_span "foo bar")))))))
834832
(warnings
835833
( "File \"f.ml\", line 1, character 4 to line 3, character 0:\
836834
\nBlank line is not allowed in '[...]' (code)."))) |}]

test/generators/html/Markup.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ <h6 id="subparagraph"><a href="#subparagraph" class="anchor"></a>
123123
<p>Code can appear <b>inside <code>other</code> markup</b>. Its display
124124
shouldn't be affected.
125125
</p>
126-
<p>There is no differences between <code>a b</code> and
127-
<code>a
128-
b</code>
129-
.
126+
<p>There is no differences between <code>a b</code> and <code>a b</code>.
130127
</p>
131128
<h2 id="links-and-references">
132129
<a href="#links-and-references" class="anchor"></a>Links and references

test/generators/latex/Markup.tex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ \subsection{Styling\label{styling}}%
3434

3535
Code can appear \bold{inside \ocamlinlinecode{other} markup}. Its display shouldn't be affected.
3636

37-
There is no differences between \ocamlinlinecode{a b} and \ocamlinlinecode{a
38-
b}.
37+
There is no differences between \ocamlinlinecode{a b} and \ocamlinlinecode{a b}.
3938

4039
\subsection{Links and references\label{links-and-references}}%
4140
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.

test/generators/man/Markup.3o

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ This is also true between non-code markup and code\.
8686
.sp
8787
Code can appear \fBinside other markup\fR\. Its display shouldn't be affected\.
8888
.sp
89-
There is no differences between a b and a
90-
b\.
89+
There is no differences between a b and a b\.
9190
.nf
9291
.sp
9392
.in 3

0 commit comments

Comments
 (0)