diff --git a/src/Juvix/Compiler/Backend/Markdown/Data/Types.hs b/src/Juvix/Compiler/Backend/Markdown/Data/Types.hs index 2e3341641b..6ed14f4237 100644 --- a/src/Juvix/Compiler/Backend/Markdown/Data/Types.hs +++ b/src/Juvix/Compiler/Backend/Markdown/Data/Types.hs @@ -123,7 +123,7 @@ instance MK.ToPlainText Mk where builder :: Mk -> [Text] builder = \case MkConcat a b -> builder a <> builder b - MkTextBlock t -> [trimText (t ^. textBlock) <> nl] + MkTextBlock t -> [t ^. textBlock] MkJuvixCodeBlock j -> [textJuvixCodeBlock j] MkNull -> mempty @@ -209,7 +209,7 @@ processCodeBlock info t loc = _juvixCodeBlockInterval = loc } _ -> - let b = "```" <> info <> nl <> t <> "```" + let b = "```" <> info <> t <> "```" in MkTextBlock TextBlock {_textBlock = b, _textBlockInterval = loc} instance-- (MK.IsInline TextBlock) => diff --git a/src/Juvix/Compiler/Backend/Markdown/Translation/FromTyped/Source.hs b/src/Juvix/Compiler/Backend/Markdown/Translation/FromTyped/Source.hs index d8c1d9af41..d7c4d05d7b 100644 --- a/src/Juvix/Compiler/Backend/Markdown/Translation/FromTyped/Source.hs +++ b/src/Juvix/Compiler/Backend/Markdown/Translation/FromTyped/Source.hs @@ -146,13 +146,16 @@ go = do Html.preEscapedText $ Text.intercalate "\n\n" $ map (toStrict . Html.renderHtml) htmlStatements + let _processingStateMk = if j ^. juvixCodeBlockOptions . mkJuvixBlockOptionsHide then MkNull else MkTextBlock TextBlock - { _textBlock = resHtml, + { _textBlock = + Text.replace "\n" "
" $ + resHtml, _textBlockInterval = j ^. juvixCodeBlockInterval } let newState = diff --git a/tests/positive/Markdown/Test.juvix.md b/tests/positive/Markdown/Test.juvix.md index 138b11f0e4..d9d76cb7c7 100644 --- a/tests/positive/Markdown/Test.juvix.md +++ b/tests/positive/Markdown/Test.juvix.md @@ -9,7 +9,6 @@ module Test; Certain blocks can be hidden from the output by adding the `hide` attribute, as shown below. - ```juvix hide import Stdlib.Prelude open; ``` @@ -27,4 +26,67 @@ Commands like `typecheck` and `compile` can be used with Juvix Markdown files. ```juvix main : IO := readLn (printNatLn ∘ fibonacci ∘ stringToNat); -``` \ No newline at end of file +``` + +Other code blocks are not touched, e.g: + +```text +This is a text block +``` + + +```haskell +module Test where +``` + +Blocks indented. + + ```haskell + module Test where + ``` + +Empty blocks: + +``` +``` + +We also use other markup for documentation such as: + +!!! note + + We use this kind of markup for notes, solutions, and other stuff + + 1. More text + + ```text + f {n : Nat := 0} {m : Nat := n + 1} .... + ``` + + 2. Second text + + +??? info "Solution" + + Initial function arguments that match variables or wildcards in all clauses can + be moved to the left of the colon in the function definition. For example, + + ```juvix + module move-to-left; + import Stdlib.Data.Nat open; + + add (n : Nat) : Nat -> Nat + | zero := n + | (suc m) := suc (add n m); + end; + ``` + + is equivalent to + + ```juvix + module example-add; + import Stdlib.Data.Nat open; + add : Nat -> Nat -> Nat + | n zero := n + | n (suc m) := suc (add n m); + end; + ``` \ No newline at end of file diff --git a/tests/positive/Markdown/markdown/Test.md b/tests/positive/Markdown/markdown/Test.md index c9728e9475..a803ebfec1 100644 --- a/tests/positive/Markdown/markdown/Test.md +++ b/tests/positive/Markdown/markdown/Test.md @@ -3,18 +3,62 @@ A Juvix Markdown file name ends with `.juvix.md`. This kind of file must contain a module declaration at the top, as shown below ---in the first code block. -
module Test;
-
+
module Test;
Certain blocks can be hidden from the output by adding the `hide` attribute, as shown below. -
fib : Nat  Nat  Nat  Nat
-  | zero x1 _ := x1
-  | (suc n) x1 x2 := fib n x2 (x1 + x2);
 
-fibonacci (n : Nat) : Nat := fib n 0 1;
+
fib : Nat  Nat  Nat  Nat
| zero x1 _ := x1
| (suc n) x1 x2 := fib n x2 (x1 + x2);

fibonacci (n : Nat) : Nat := fib n 0 1;
Commands like `typecheck` and `compile` can be used with Juvix Markdown files.
main : IO := readLn (printNatLn  fibonacci  stringToNat);
+ +Other code blocks are not touched, e.g: + +```text +This is a text block +``` + + +```haskell +module Test where +``` + +Blocks indented. + + ```haskell + module Test where + ``` + +Empty blocks: + +``` +``` + +We also use other markup for documentation such as: + +!!! note + + We use this kind of markup for notes, solutions, and other stuff + + 1. More text + + ```text + f {n : Nat := 0} {m : Nat := n + 1} .... + ``` + + 2. Second text + + +??? info "Solution" + + Initial function arguments that match variables or wildcards in all clauses can + be moved to the left of the colon in the function definition. For example, + +
module move-to-left;
import Stdlib.Data.Nat open;

add
(n : Nat) : Nat -> Nat
| zero := n
| (suc m) := suc (add n m);
end;
+ + is equivalent to + +
module example-add;
import Stdlib.Data.Nat open;

add
: Nat -> Nat -> Nat
| n zero := n
| n (suc m) := suc (add n m);
end;