jgm / djot

A light markup language
https://djot.net
MIT License
1.66k stars 43 forks source link

Prettier plugin or standalone formatter #129

Closed mtsknn closed 1 year ago

mtsknn commented 1 year ago

Not sure if this is in the scope of this project/repo, but here goes:

Prettier is essential for me when authoring Markdown, so I'd very much like a Djot formatter. Maybe not yet, considering that Djot is still evolving, but eventually.

Benefits:

Some things to format off the top of my head:

Example:

jgm commented 1 year ago

If you have pandoc, you can already do this kind of reformatting by using the custom lua reader/writer supplied in this repository.

$ pandoc -f djot-reader.lua -t djot-writer.lua
1.  This is   a
list item.

> This is a block
quote.

```js
const
 foo  =
'bar' ;
Result:
  1. This is a list item.

This is a block quote.

const
 foo  =
'bar' ;


Note: you defiintely don't want line breaks to be changed in a code block, as in your example, since that changes the semantics.
jgm commented 1 year ago

That said, it would be nice to have a native djot renderer built in.

jgm commented 1 year ago

Oh I see, I suppose the prettier formatter will pass javascript code through a javascript code formatter? Well, that can certainly be done with djot using filters. More documentation on that coming later.

mtsknn commented 1 year ago

If you have pandoc, you can already do this kind of reformatting by using the custom lua reader/writer supplied in this repository.

Nice. Is there a way to preserve line breaks (in prose)? I like Semantic Line Breaks, but the example you provided breaks that.

Oh I see, I suppose the prettier formatter will pass javascript code through a javascript code formatter?

Exactly. Looks like I failed to articulate that.

Well, that can certainly be done with djot using filters. More documentation on that coming later.

Nice. I'll repeat one point from my previous comment now that we are on the same page regarding code formatting:

It could be nice if one could configure what code formatters the Djot formatter should use. E.g. Go code blocks could be configured to be formatted with gofmt, and JavaScript code blocks with Prettier or deno fmt. This would be better than Prettier + Markdown as Prettier supports only a few languages.

waldyrious commented 1 year ago

Nice. Is there a way to preserve line breaks (in prose)?

I suppose #108 (i.e. supporting a concrete syntax tree) might be able to address this use case.

jgm commented 1 year ago

We already have softbreak elements in the AST, so we have everything we need to preserve the original line breaks.

jgm commented 1 year ago

Closing this in favor of #135