Skip to content

Commit

Permalink
Merge pull request #4655 from unisonweb/cp/text-codeblock-fix
Browse files Browse the repository at this point in the history
Fix raw text-block indentation
  • Loading branch information
aryairani authored Jan 31, 2024
2 parents a162fcc + 1f67d09 commit 9e4bc32
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 32 deletions.
10 changes: 3 additions & 7 deletions parser-typechecker/src/Unison/Syntax/TermPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,13 +1737,9 @@ prettyDoc2 ::
prettyDoc2 ac tm = do
ppe <- getPPE
let brace p =
fmt S.DocDelimiter "{{"
<> PP.softbreak
<> p
<> PP.softbreak
<> fmt
S.DocDelimiter
"}}"
if PP.isMultiLine p
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
-- Finds the longest run of a character and return one bigger than that
longestRun c s =
Expand Down
18 changes: 12 additions & 6 deletions unison-src/transcripts-round-trip/main.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ fix_2224b = cases
fix_2271 : Doc2
fix_2271 =
{{ # Full doc body indented
{{
# Full doc body indented
``` raw
myVal1 = 42
Expand All @@ -179,7 +180,8 @@ fix_2271 =
indented2="this is two indents"
```
I am two spaces over }}
I am two spaces over
}}
Fix_2337.f : Fix_2337 -> Boolean
Fix_2337.f = cases Fix_2337 a b -> a
Expand Down Expand Up @@ -304,10 +306,12 @@ fix_4384b = {{ {{ docExampleBlock 0 '99 }} }}
fix_4384c : Doc2
fix_4384c =
use Nat +
{{ {{ docExampleBlock 0 do
{{
{{ docExampleBlock 0 do
x = 1
y = 2
x + y }} }}
x + y }}
}}
fix_4384d : Doc2
fix_4384d =
Expand Down Expand Up @@ -432,11 +436,13 @@ multiline_list =
nested_fences : Doc2
nested_fences =
{{ ```` raw
{{
```` raw
```unison
r = "boopydoo"
```
```` }}
````
}}
raw_a : Text
raw_a =
Expand Down
6 changes: 4 additions & 2 deletions unison-src/transcripts-using-base/doc.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ Lastly, it's common to build longer documents including subdocuments via `{{ sub
doc.guide : Doc2
doc.guide =
{{ # Unison computable documentation
{{
# Unison computable documentation
{{ basicFormatting }}
Expand All @@ -565,7 +566,8 @@ Lastly, it's common to build longer documents including subdocuments via `{{ sub
{{ nonUnisonCodeBlocks }}
{{ otherElements }} }}
{{ otherElements }}
}}
.> display doc.guide
Expand Down
110 changes: 110 additions & 0 deletions unison-src/transcripts/doc2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Test parsing and round-trip of doc2 syntax elements

```ucm:hide
.> builtins.mergeio
```

```unison:hide
otherDoc : a -> Doc2
otherDoc _ = {{ yo }}
otherTerm : Nat
otherTerm = 99
fulldoc : Doc2
fulldoc =
use Nat +
{{
Heres some text with a
soft line break
hard line break
Here's a cool **BOLD** __italic__ ~~strikethrough~~ thing with an inline code block ''1 + 2''
# Heading
## Heading 2
Term Link: {otherTerm}
Type Link: {type Optional}
Term source:
@source{term}
Term signature:
@signature{term}
* List item
Inline code:
`` 1 + 2 ``
` "doesn't typecheck" + 1 `
[Link](https://unison-lang.org)
![Image](https://share-next.unison-lang.org/static/unison-logo-circle.png)
Horizontal rule
---
Video
{{
Special
(Embed
(Any (Video [MediaSource "test.mp4" None] [("poster", "test.png")])))
}}
Transclusion/evaluation:
{{ otherDoc (a -> Word a) }}
---
The following markdown features aren't supported by the Doc format yet, but maybe will someday
> Block quote
Table
| Header 1 | Header 2 |
| -------- | -------- |
| Cell 1 | Cell 2 |
Indented Code block
'''
Exact whitespace should be preserved across multiple updates. Don't mess with the logo!
_____ _
| | |___|_|___ ___ ___
| | | | |_ -| . | |
|_____|_|_|_|___|___|_|_|
Line with no whitespace:
Should have one full trailing newline below here:
'''
Inline '' text literal with 1 space of padding '' in the middle of a sentence.
}}
```

Format it to check that everything pretty-prints in a valid way.

```ucm
.> debug.format
```
Loading

0 comments on commit 9e4bc32

Please sign in to comment.