Skip to content

Commit

Permalink
[new] Support literate Djot files
Browse files Browse the repository at this point in the history
Djot is a markup format that is derived from CommonMark, it's code block
syntax is identical to CommonMark's, so we can support it as a
CommonMark style literate formate by just adding the file extension.
  • Loading branch information
nmccarty authored and buzden committed Feb 22, 2025
1 parent 4e8847b commit 69f198d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ This CHANGELOG describes the merged but unreleased changes. Please see [CHANGELO
with `_builtin.<TAG>` (eg `_builtin.CONS`). This allows the identity optimisation
to optimise conversions between list-shaped things.

* [Djot](https://djot.net/) files can now be compiled as CommonMark style
Literate Idris files.

### Backend changes

#### RefC Backend
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Michael Morgan
Milan Kral
Molly Miller
Mounir Boudia
Nathan McCarty
Nick Drozd
Nicolas Biri
Niklas Larsson
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference/literate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Each of the following markup is recognised regardless of case:
CommonMark
**********

We treat files with an extension of ``.md`` and ``.markdown`` as CommonMark style literate files.
We treat Markdown files with an extension of ``.md`` or ``.markdown`` and Djot files with an extension of ``.dj`` as CommonMark style literate files.

+ CommonMark source blocks for idris sans options are recognised as visible code blocks::

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Unlit.idr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ styleCMark : LiterateStyle
styleCMark = MkLitStyle
[("```idris", "```"), ("~~~idris", "~~~"), ("<!-- idris", "-->")]
Nil
[".md", ".markdown"]
[".md", ".markdown", ".dj"]

export
styleTeX : LiterateStyle
Expand Down
29 changes: 29 additions & 0 deletions tests/idris2/literate/literate020/IEdit.dj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
```idris
data Vect : Nat -> Type -> Type where
Nil : Vect Z a
(::) : a -> Vect k a -> Vect (S k) a
```

<!-- idris
%name Vect xs, ys, zs
-->

```idris
dupAll : Vect n a -> Vect n (a, a)
dupAll xs = zipHere xs xs
where
zipHere : forall n . Vect n a -> Vect n b -> Vect n (a, b)
```


<!-- idris

data Foobar = MkFoo

-->


```idris
showFooBar : Foobar -> String
showFooBar MkFoo = "MkFoo"
```
4 changes: 4 additions & 0 deletions tests/idris2/literate/literate020/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1/1: Building IEdit (IEdit.dj)
Main> zipHere [] [] = []
zipHere (x :: xs) (y :: ys) = (x, y) :: zipHere xs ys
Main> Bye for now!
2 changes: 2 additions & 0 deletions tests/idris2/literate/literate020/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:gd 15 zipHere
:q
3 changes: 3 additions & 0 deletions tests/idris2/literate/literate020/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. ../../../testutils.sh

idris2 IEdit.dj < input

0 comments on commit 69f198d

Please sign in to comment.