Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raw text-block indentation #4655

Merged
merged 12 commits into from
Jan 31, 2024
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is a smidge strange, but it does round-trip. Rúnar and I tried to improve it without much luck :'(

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
106 changes: 106 additions & 0 deletions unison-src/transcripts/doc2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# 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!

_____ _
| | |___|_|___ ___ ___
| | | | |_ -| . | |
|_____|_|_|_|___|___|_|_|
Should have one full trailing newline below here:

'''

Inline '' text literal with 1 space of padding '' in the middle of a sentence.

}}
```

```ucm
.> debug.format
-- Format it again to ensure multiple round-trips don't cause changes.
.> debug.format
```
Loading
Loading