mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
Merge pull request #4659 from unisonweb/cp/inline-literal-escaping
Default to single-quotes
This commit is contained in:
commit
9a058a381e
@ -1741,10 +1741,14 @@ prettyDoc2 ac tm = do
|
|||||||
then fmt S.DocDelimiter "{{" <> PP.newline <> p <> PP.newline <> fmt S.DocDelimiter "}}"
|
then fmt S.DocDelimiter "{{" <> PP.newline <> p <> PP.newline <> fmt S.DocDelimiter "}}"
|
||||||
else fmt S.DocDelimiter "{{" <> PP.softbreak <> p <> PP.softbreak <> fmt S.DocDelimiter "}}"
|
else fmt S.DocDelimiter "{{" <> PP.softbreak <> p <> PP.softbreak <> fmt S.DocDelimiter "}}"
|
||||||
bail tm = brace <$> pretty0 ac tm
|
bail tm = brace <$> pretty0 ac tm
|
||||||
|
contains :: Char -> Pretty SyntaxText -> Bool
|
||||||
|
contains c p =
|
||||||
|
PP.toPlainUnbroken (PP.syntaxToColor p)
|
||||||
|
& elem c
|
||||||
-- Finds the longest run of a character and return one bigger than that
|
-- Finds the longest run of a character and return one bigger than that
|
||||||
longestRun c s =
|
longestRun c s =
|
||||||
case filter (\s -> take 2 s == [c, c]) $
|
case filter (\s -> take 2 s == [c, c]) $
|
||||||
group (PP.toPlainUnbroken $ PP.syntaxToColor s) of
|
List.group (PP.toPlainUnbroken $ PP.syntaxToColor s) of
|
||||||
[] -> 2
|
[] -> 2
|
||||||
x -> 1 + maximum (map length x)
|
x -> 1 + maximum (map length x)
|
||||||
oneMore c inner = replicate (longestRun c inner) c
|
oneMore c inner = replicate (longestRun c inner) c
|
||||||
@ -1778,7 +1782,12 @@ prettyDoc2 ac tm = do
|
|||||||
pure $ PP.text t
|
pure $ PP.text t
|
||||||
(toDocCode ppe -> Just d) -> do
|
(toDocCode ppe -> Just d) -> do
|
||||||
inner <- rec d
|
inner <- rec d
|
||||||
let quotes = PP.string $ oneMore '\'' inner
|
let quotes =
|
||||||
|
-- Prefer ` if there aren't any in the inner text,
|
||||||
|
-- otherwise use one more than the longest run of ' in the inner text
|
||||||
|
if contains '`' inner
|
||||||
|
then PP.string $ oneMore '\'' inner
|
||||||
|
else PP.string "`"
|
||||||
pure $ PP.group $ quotes <> inner <> quotes
|
pure $ PP.group $ quotes <> inner <> quotes
|
||||||
(toDocJoin ppe -> Just ds) -> foldMapM rec ds
|
(toDocJoin ppe -> Just ds) -> foldMapM rec ds
|
||||||
(toDocItalic ppe -> Just d) -> do
|
(toDocItalic ppe -> Just d) -> do
|
||||||
|
@ -112,7 +112,7 @@ and the rendered output using `display`:
|
|||||||
section elements.
|
section elements.
|
||||||
|
|
||||||
Text can be **bold**, __italicized__, ~~strikethrough~~,
|
Text can be **bold**, __italicized__, ~~strikethrough~~,
|
||||||
or ''monospaced'' (or ''monospaced'').
|
or `monospaced` (or `monospaced`).
|
||||||
|
|
||||||
You can link to Unison terms, types, and external URLs:
|
You can link to Unison terms, types, and external URLs:
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ and the rendered output using `display`:
|
|||||||
[a named term link]({Some}). Term links are handy for
|
[a named term link]({Some}). Term links are handy for
|
||||||
linking to other documents!
|
linking to other documents!
|
||||||
|
|
||||||
You can use ''{{ .. }}'' to escape out to regular Unison
|
You can use `{{ .. }}` to escape out to regular Unison
|
||||||
syntax, for instance {{ docWord "__not bold__" }}. This is
|
syntax, for instance {{ docWord "__not bold__" }}. This is
|
||||||
useful for creating documents programmatically or just
|
useful for creating documents programmatically or just
|
||||||
including other documents.
|
including other documents.
|
||||||
@ -164,9 +164,9 @@ and the rendered output using `display`:
|
|||||||
|
|
||||||
## Bulleted lists
|
## Bulleted lists
|
||||||
|
|
||||||
Bulleted lists can use ''+'', ''-'', or ''*'' for the
|
Bulleted lists can use `+`, `-`, or `*` for the bullets
|
||||||
bullets (though the choice will be normalized away by
|
(though the choice will be normalized away by the
|
||||||
the pretty-printer). They can be nested, to any depth:
|
pretty-printer). They can be nested, to any depth:
|
||||||
|
|
||||||
* A
|
* A
|
||||||
* B
|
* B
|
||||||
@ -331,9 +331,9 @@ and the rendered output using `display`:
|
|||||||
You can include typechecked code snippets inline, for
|
You can include typechecked code snippets inline, for
|
||||||
instance:
|
instance:
|
||||||
|
|
||||||
* {{ docExample 2 '(f x -> f x + sqr 1) }} - the ''2''
|
* {{ docExample 2 '(f x -> f x + sqr 1) }} - the `2`
|
||||||
says to ignore the first two arguments when
|
says to ignore the first two arguments when
|
||||||
rendering. In richer renderers, the ''sqr'' link will
|
rendering. In richer renderers, the `sqr` link will
|
||||||
be clickable.
|
be clickable.
|
||||||
* If your snippet expression is just a single function
|
* If your snippet expression is just a single function
|
||||||
application, you can put it in double backticks, like
|
application, you can put it in double backticks, like
|
||||||
@ -456,7 +456,7 @@ and the rendered output using `display`:
|
|||||||
{{
|
{{
|
||||||
There are also asides, callouts, tables, tooltips, and more.
|
There are also asides, callouts, tables, tooltips, and more.
|
||||||
These don't currently have special syntax; just use the
|
These don't currently have special syntax; just use the
|
||||||
''{{ }}'' syntax to call these functions directly.
|
`{{ }}` syntax to call these functions directly.
|
||||||
|
|
||||||
@signatures{docAside, docCallout, docBlockquote, docTooltip, docTable}
|
@signatures{docAside, docCallout, docBlockquote, docTooltip, docTable}
|
||||||
|
|
||||||
|
@ -20,7 +20,15 @@ soft line break
|
|||||||
|
|
||||||
hard line break
|
hard line break
|
||||||
|
|
||||||
Here's a cool **BOLD** __italic__ ~~strikethrough~~ thing with an inline code block ''1 + 2''
|
Here's a cool **BOLD** __italic__ ~~strikethrough~~ thing with an inline code block `1 + 2`
|
||||||
|
|
||||||
|
Should print with appropriate fences for the contents:
|
||||||
|
|
||||||
|
`No fancy quotes`
|
||||||
|
|
||||||
|
'' There are `backticks` in here ''
|
||||||
|
|
||||||
|
''' There are `backticks` and ''quotes'' in here '''
|
||||||
|
|
||||||
# Heading
|
# Heading
|
||||||
|
|
||||||
|
@ -16,7 +16,15 @@ soft line break
|
|||||||
|
|
||||||
hard line break
|
hard line break
|
||||||
|
|
||||||
Here's a cool **BOLD** __italic__ ~~strikethrough~~ thing with an inline code block ''1 + 2''
|
Here's a cool **BOLD** __italic__ ~~strikethrough~~ thing with an inline code block `1 + 2`
|
||||||
|
|
||||||
|
Should print with appropriate fences for the contents:
|
||||||
|
|
||||||
|
`No fancy quotes`
|
||||||
|
|
||||||
|
'' There are `backticks` in here ''
|
||||||
|
|
||||||
|
''' There are `backticks` and ''quotes'' in here '''
|
||||||
|
|
||||||
# Heading
|
# Heading
|
||||||
|
|
||||||
@ -121,7 +129,15 @@ fulldoc =
|
|||||||
hard line break
|
hard line break
|
||||||
|
|
||||||
Here's a cool **BOLD** __italic__ ~~strikethrough~~ thing with an inline code
|
Here's a cool **BOLD** __italic__ ~~strikethrough~~ thing with an inline code
|
||||||
block ''1 + 2''
|
block `1 + 2`
|
||||||
|
|
||||||
|
Should print with appropriate fences for the contents:
|
||||||
|
|
||||||
|
`No fancy quotes`
|
||||||
|
|
||||||
|
'' There are `backticks` in here ''
|
||||||
|
|
||||||
|
''' There are `backticks` and ''quotes'' in here '''
|
||||||
|
|
||||||
# Heading
|
# Heading
|
||||||
|
|
||||||
@ -145,7 +161,7 @@ fulldoc =
|
|||||||
|
|
||||||
`` 1 + 2 ``
|
`` 1 + 2 ``
|
||||||
|
|
||||||
'' "doesn't typecheck" + 1 ''
|
` "doesn't typecheck" + 1 `
|
||||||
|
|
||||||
[Link](https://unison-lang.org)
|
[Link](https://unison-lang.org)
|
||||||
|
|
||||||
@ -194,7 +210,7 @@ fulldoc =
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
Inline '' text literal with 1 space of padding '' in the middle of a
|
Inline ` text literal with 1 space of padding ` in the middle of a
|
||||||
sentence.
|
sentence.
|
||||||
}}
|
}}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user