Skip to content

Commit

Permalink
Default to single-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Feb 1, 2024
1 parent 9e4bc32 commit 61a0542
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
13 changes: 11 additions & 2 deletions parser-typechecker/src/Unison/Syntax/TermPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,10 +1741,14 @@ prettyDoc2 ac tm = do
then fmt S.DocDelimiter "{{" <> PP.newline <> p <> PP.newline <> fmt S.DocDelimiter "}}"
else fmt S.DocDelimiter "{{" <> PP.softbreak <> p <> PP.softbreak <> fmt S.DocDelimiter "}}"
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
longestRun c s =
case filter (\s -> take 2 s == [c, c]) $
group (PP.toPlainUnbroken $ PP.syntaxToColor s) of
List.group (PP.toPlainUnbroken $ PP.syntaxToColor s) of
[] -> 2
x -> 1 + maximum (map length x)
oneMore c inner = replicate (longestRun c inner) c
Expand Down Expand Up @@ -1778,7 +1782,12 @@ prettyDoc2 ac tm = do
pure $ PP.text t
(toDocCode ppe -> Just d) -> do
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
(toDocJoin ppe -> Just ds) -> foldMapM rec ds
(toDocItalic ppe -> Just d) -> do
Expand Down
16 changes: 8 additions & 8 deletions unison-src/transcripts-using-base/doc.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ and the rendered output using `display`:
section elements.
Text can be **bold**, __italicized__, ~~strikethrough~~,
or ''monospaced'' (or ''monospaced'').
or `monospaced` (or `monospaced`).
You can link to Unison terms, types, and external URLs:
Expand All @@ -122,7 +122,7 @@ and the rendered output using `display`:
[a named term link]({Some}). Term links are handy for
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
useful for creating documents programmatically or just
including other documents.
Expand Down Expand Up @@ -164,9 +164,9 @@ and the rendered output using `display`:
## Bulleted lists
Bulleted lists can use ''+'', ''-'', or ''*'' for the
bullets (though the choice will be normalized away by
the pretty-printer). They can be nested, to any depth:
Bulleted lists can use `+`, `-`, or `*` for the bullets
(though the choice will be normalized away by the
pretty-printer). They can be nested, to any depth:
* A
* B
Expand Down Expand Up @@ -331,9 +331,9 @@ and the rendered output using `display`:
You can include typechecked code snippets inline, for
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
rendering. In richer renderers, the ''sqr'' link will
rendering. In richer renderers, the `sqr` link will
be clickable.
* If your snippet expression is just a single function
application, you can put it in double backticks, like
Expand Down Expand Up @@ -456,7 +456,7 @@ and the rendered output using `display`:
{{
There are also asides, callouts, tables, tooltips, and more.
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}
Expand Down
File renamed without changes.
10 changes: 9 additions & 1 deletion unison-src/transcripts/doc2.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ soft 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
Expand Down
24 changes: 20 additions & 4 deletions unison-src/transcripts/doc2.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ soft 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
Expand Down Expand Up @@ -121,7 +129,15 @@ fulldoc =
hard line break
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
Expand All @@ -145,7 +161,7 @@ fulldoc =
`` 1 + 2 ``
'' "doesn't typecheck" + 1 ''
` "doesn't typecheck" + 1 `
[Link](https://unison-lang.org)
Expand Down Expand Up @@ -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.
}}
```
Expand Down

0 comments on commit 61a0542

Please sign in to comment.