Skip to content

Commit

Permalink
Allow multi-line bold, italics, and strikethru
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Feb 5, 2024
1 parent 4eb0147 commit be330a8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
15 changes: 15 additions & 0 deletions unison-src/transcripts/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ structural type Optional a = More Text
{{ A doc before a type with no type-vars }}
type Two = One Nat | Two Text
-- Regression for https://github.com/unisonweb/unison/issues/4669
multilineBold = {{
**This paragraph is really really really really really long and spans multiple lines
with a strike-through block**
_This paragraph is really really really really really long and spans multiple lines
with a strike-through block_
~This paragraph is really really really really really long and spans multiple lines
with a strike-through block~
}}
```

```ucm
Expand Down
29 changes: 29 additions & 0 deletions unison-src/transcripts/formatter.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ structural type Optional a = More Text
{{ A doc before a type with no type-vars }}
type Two = One Nat | Two Text
-- Regression for https://github.com/unisonweb/unison/issues/4669
multilineBold = {{
**This paragraph is really really really really really long and spans multiple lines
with a strike-through block**
_This paragraph is really really really really really long and spans multiple lines
with a strike-through block_
~This paragraph is really really really really really long and spans multiple lines
with a strike-through block~
}}
```

```ucm
Expand Down Expand Up @@ -91,6 +106,20 @@ structural type Optional a = More Text | Some | Other a | None Nat
Two.doc = {{ A doc before a type with no type-vars }}
type Two = One Nat | Two Text
-- Regression for https://github.com/unisonweb/unison/issues/4669
multilineBold =
{{
**This paragraph is really really really really really long and spans
multiple lines with a strike-through block**
__This paragraph is really really really really really long and spans
multiple lines with a strike-through block__
~~This paragraph is really really really really really long and spans
multiple lines with a strike-through block~~
}}
```

Formatter should leave things alone if the file doesn't typecheck.
Expand Down
10 changes: 9 additions & 1 deletion unison-syntax/src/Unison/Syntax/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,14 @@ lexemes' eof =
nonNewlineSpace ch = isSpace ch && ch /= '\n' && ch /= '\r'
nonNewlineSpaces = P.takeWhileP Nothing nonNewlineSpace

-- Allows whitespace or a newline, but not more than two newlines in a row.
whitespaceWithoutParagraphBreak :: P ()
whitespaceWithoutParagraphBreak = void do
void nonNewlineSpaces
optional newline >>= \case
Just _ -> void nonNewlineSpaces
Nothing -> pure ()

fencedBlock =
P.label "block eval (syntax: a fenced code block)" $
evalUnison <|> exampleBlock <|> other
Expand Down Expand Up @@ -651,7 +659,7 @@ lexemes' eof =
wrap (name end) . wrap "syntax.docParagraph" $
join
<$> P.someTill
(leafy (closing <|> (void $ lit end)) <* nonNewlineSpaces)
(leafy (closing <|> (void $ lit end)) <* whitespaceWithoutParagraphBreak)
(lit end)

externalLink =
Expand Down

0 comments on commit be330a8

Please sign in to comment.