HTML writer: don't break lines inside code elements.

With the new (default) line wrapping of HTML, in
conjunction with the default CSS which includes
`code { whitespace: pre-wrap; }`, spurious line
breaks could be introduced into inline code.

Closes #7858.
This commit is contained in:
John MacFarlane 2022-01-20 09:17:34 -08:00
parent d9ec95e7ab
commit ef8135b4a7
3 changed files with 18 additions and 14 deletions

View file

@ -30,9 +30,13 @@ layoutMarkup = go True mempty
in literal open'
<> attrs
<> char '>'
<> (if allowsWrap open'
then go wrap mempty content
else flush $ go False mempty content)
<> (case open' of
"<code" -> go False mempty content
t | t == "<pre" ||
t == "<style" ||
t == "<script" ||
t == "<textarea" -> flush $ go False mempty content
| otherwise -> go wrap mempty content)
<> literal (getText close)
go wrap attrs (CustomParent tag content) =
char '<'
@ -77,9 +81,6 @@ layoutMarkup = go True mempty
go _ _ (Empty _) = mempty
space' wrap = if wrap then space else char ' '
allowsWrap :: T.Text -> Bool
allowsWrap t =
not (t == "<pre" || t == "<style" || t == "<script" || t == "<textarea")
fromChoiceString :: Bool -- ^ Allow wrapping
-> ChoiceString -- ^ String to render

View file

@ -3,8 +3,7 @@
I want to explain the interface of \lstinline[language=Java]{public class MyClass}.
^D
<p>I want to explain the interface of <code
class="sourceCode java"><span class="kw">public</span> <span
class="kw">class</span> MyClass</code>.</p>
class="sourceCode java"><span class="kw">public</span> <span class="kw">class</span> MyClass</code>.</p>
```
@ -12,8 +11,8 @@ class="kw">class</span> MyClass</code>.</p>
% pandoc -f latex -t html
I want to explain the interface of \lstinline{public class MyClass}.
^D
<p>I want to explain the interface of <code>public class
MyClass</code>.</p>
<p>I want to explain the interface of
<code>public class MyClass</code>.</p>
```
@ -47,8 +46,7 @@ I want to explain the interface of \lstinline[language=Java]{public class MyClas
I want to explain the interface of \mintinline{java}{public class MyClass}.
^D
<p>I want to explain the interface of <code
class="sourceCode java"><span class="kw">public</span> <span
class="kw">class</span> MyClass</code>.</p>
class="sourceCode java"><span class="kw">public</span> <span class="kw">class</span> MyClass</code>.</p>
```
@ -57,8 +55,7 @@ class="kw">class</span> MyClass</code>.</p>
I want to explain the interface of \mintinline{java}|public class MyClass|.
^D
<p>I want to explain the interface of <code
class="sourceCode java"><span class="kw">public</span> <span
class="kw">class</span> MyClass</code>.</p>
class="sourceCode java"><span class="kw">public</span> <span class="kw">class</span> MyClass</code>.</p>
```

6
test/command/7858.md Normal file
View file

@ -0,0 +1,6 @@
```
% pandoc -t html --columns=50 --wrap=auto
`neuth asontue stheuosnt aeosunth asnoetuh asneotuh snatehou snatoehu sntahe ousntahoe unstaheou sntaheou aoeu sthoeu sntaoeusnth ansoetuhs atoeuh saonteu`
^D
<p><code>neuth asontue stheuosnt aeosunth asnoetuh asneotuh snatehou snatoehu sntahe ousntahoe unstaheou sntaheou aoeu sthoeu sntaoeusnth ansoetuhs atoeuh saonteu</code></p>
```