mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-13 22:29:35 +03:00
simplify paragraphyText, it's now much better behaved
This commit is contained in:
parent
bf312d314f
commit
d296266602
@ -49,7 +49,7 @@ displayDoc :: (Var v, Monad m)
|
||||
displayDoc ppe terms typeOf evaluated types t = go t
|
||||
where
|
||||
go (DD.DocJoin docs) = foldMap id <$> traverse go docs
|
||||
go (DD.DocBlob txt) = pure $ P.text txt
|
||||
go (DD.DocBlob txt) = pure $ P.paragraphyText txt
|
||||
go (DD.DocLink (DD.LinkTerm (Term.TermLink' r))) = pure $ P.underline (termName ppe r)
|
||||
go (DD.DocLink (DD.LinkType (Term.TypeLink' r))) = pure $ P.underline (typeName ppe r)
|
||||
go (DD.DocSource (DD.LinkTerm (Term.TermLink' r))) = prettyTerm terms r
|
||||
|
@ -143,22 +143,15 @@ wrapImpl (p:ps) = wrap_ . Seq.fromList $
|
||||
wrapString :: (LL.ListLike s Char, IsString s) => String -> Pretty s
|
||||
wrapString s = wrap (lit $ fromString s)
|
||||
|
||||
-- 0. Preserve all leading and trailing spaces
|
||||
-- 1. Convert multiple adjacent blank lines to a single blank line.
|
||||
-- 2. Combine adjacent non-blank lines into one line.
|
||||
-- 3. Wrap each remaining line.
|
||||
-- 0. Preserve all leading and trailing whitespace
|
||||
-- 1. Preserve all newlines
|
||||
-- 2. Wrap all text in between newlines
|
||||
paragraphyText :: (LL.ListLike s Char, IsString s) => Text -> Pretty s
|
||||
paragraphyText t = case span isSpace (Text.unpack $ Text.dropWhileEnd isSpace t) of
|
||||
(sp,t) -> string sp <> lines (go mempty t)
|
||||
where
|
||||
trailingSp = Text.takeWhileEnd isSpace t
|
||||
go acc [] = [wrap acc <> text trailingSp]
|
||||
go acc (span isSpace -> (sp, rest)) =
|
||||
if length (filter (=='\n') sp) < 2 then munch acc
|
||||
else wrap acc : mempty : munch mempty
|
||||
where
|
||||
munch acc = case break isSpace rest of
|
||||
(nonsp, rest) -> go (acc <> string nonsp) rest
|
||||
paragraphyText t = text start <> inner <> text end where
|
||||
inner = sep "\n" . fmap (wrap . text) . Text.splitOn "\n" $ t'
|
||||
(start, t0) = Text.span isSpace t
|
||||
t' = Text.dropWhileEnd isSpace t0
|
||||
end = Text.takeWhileEnd isSpace t0
|
||||
|
||||
wrap :: (LL.ListLike s Char, IsString s) => Pretty s -> Pretty s
|
||||
wrap p = wrapImpl (toLeaves [p]) where
|
||||
|
@ -50,7 +50,7 @@ use .builtin
|
||||
|
||||
docs.List.take = [:
|
||||
|
||||
`@List.take n xs` returns the first `n` elements of `xs`
|
||||
`@List.take n xs` returns the first `n` elements of `xs`. (No need to add line breaks manually. The display command will do wrapping of text for you.)
|
||||
|
||||
## Examples:
|
||||
|
||||
|
@ -92,7 +92,7 @@ use .builtin
|
||||
|
||||
docs.List.take = [:
|
||||
|
||||
`@List.take n xs` returns the first `n` elements of `xs`
|
||||
`@List.take n xs` returns the first `n` elements of `xs`. (No need to add line breaks manually. The display command will do wrapping of text for you.)
|
||||
|
||||
## Examples:
|
||||
|
||||
@ -147,7 +147,9 @@ Now that documentation is linked to the definition. We can view it if we like:
|
||||
|
||||
.> display 1
|
||||
|
||||
`builtin.List.take n xs` returns the first `n` elements of `xs`
|
||||
`builtin.List.take n xs` returns the first `n` elements of
|
||||
`xs`. (No need to add line breaks manually. The display
|
||||
command will do wrapping of text for you.)
|
||||
|
||||
## Examples:
|
||||
|
||||
@ -166,7 +168,9 @@ Or there's also a convenient function, `docs`, which shows the `Doc` values that
|
||||
```ucm
|
||||
.> docs builtin.List.take
|
||||
|
||||
`builtin.List.take n xs` returns the first `n` elements of `xs`
|
||||
`builtin.List.take n xs` returns the first `n` elements of
|
||||
`xs`. (No need to add line breaks manually. The display
|
||||
command will do wrapping of text for you.)
|
||||
|
||||
## Examples:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user