diff --git a/parser-typechecker/src/Unison/Syntax/TermPrinter.hs b/parser-typechecker/src/Unison/Syntax/TermPrinter.hs index f7bcd3a0d..891047f95 100644 --- a/parser-typechecker/src/Unison/Syntax/TermPrinter.hs +++ b/parser-typechecker/src/Unison/Syntax/TermPrinter.hs @@ -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 @@ -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 diff --git a/unison-src/transcripts-using-base/doc.output.md b/unison-src/transcripts-using-base/doc.output.md index a9e9add88..1d7c8a3f5 100644 --- a/unison-src/transcripts-using-base/doc.output.md +++ b/unison-src/transcripts-using-base/doc.output.md @@ -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: @@ -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. @@ -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 @@ -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 @@ -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} diff --git a/unison-src/transcripts/docs.md b/unison-src/transcripts/doc1.md similarity index 100% rename from unison-src/transcripts/docs.md rename to unison-src/transcripts/doc1.md diff --git a/unison-src/transcripts/docs.output.md b/unison-src/transcripts/doc1.output.md similarity index 100% rename from unison-src/transcripts/docs.output.md rename to unison-src/transcripts/doc1.output.md diff --git a/unison-src/transcripts/doc2.md b/unison-src/transcripts/doc2.md index 89ac97009..278cc8f49 100644 --- a/unison-src/transcripts/doc2.md +++ b/unison-src/transcripts/doc2.md @@ -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 diff --git a/unison-src/transcripts/doc2.output.md b/unison-src/transcripts/doc2.output.md index 1b7573357..e303b639a 100644 --- a/unison-src/transcripts/doc2.output.md +++ b/unison-src/transcripts/doc2.output.md @@ -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 @@ -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 @@ -145,7 +161,7 @@ fulldoc = `` 1 + 2 `` - '' "doesn't typecheck" + 1 '' + ` "doesn't typecheck" + 1 ` [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. }} ```