domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.
https://domluna.github.io/JuliaFormatter.jl/dev/
MIT License
579 stars 69 forks source link

Format *md documents without normalizing markdown. #638

Open iago-lito opened 2 years ago

iago-lito commented 2 years ago

I am very happy that JuliaFormatter.jl crawls within my *md files to correctly format chuks of julia code found there. But I wish it would leave the rest of the document alone. Or that I at least could configure what it does within it. Do I have any option to control formatting of the markdown parts? For instance, I wished that:

Text, and a [cool ref][ref] to that super ref [here][ref].

[ref]: https://long.url.factorized

```julia
a(b=5)
Be reformatted to 
````jmd
Text, and a [cool ref][ref] to that super ref [here][ref].

[ref]: https://long.url.factorized

```julia
a(b = 5)

Instead of 
````jmd
Text, and a [cool ref](https://long.url.factorized) to that super ref [here](https://long.url.factorized).

```julia
a(b = 5)
domluna commented 2 years ago

hmm this might be related to https://github.com/MichaelHatherly/CommonMark.jl/issues/43

iago-lito commented 2 years ago

I'm sorry @domluna I'm not sure I understand why you think it would be related. Can you elaborate? My understanding is that JuliaFormatter.jl is responsible for the splitting/splicing of julia/markdown parts. And that it then hands the markdown parts out to CommonMark.jl. As a consequence, the decision how to format the markdown parts is up to CommonMark.jl, but the decision whether or not to format the markdown parts is only up to JuliaFormatter.jl, is it not?

domluna commented 2 years ago

Hmmm that might be right. I'm not entirely sure it can be decoupled like that though. Because even if I do

    formatted = markdown(
        enable!(
            Parser(),
            [
                # AdmonitionRule(),
                # FootnoteRule(),
                # MathRule(),
                # TableRule(),
                # FrontMatterRule(),
                FormatRule(style, state.opts),
            ],
        )(
            deindented_string,
        ),
    )

it still produces the output above. But there might be a way not alter the markdown at all.

jlperla commented 1 year ago

Any movement on this by chance? I would love to be able to have automatic formatting on save for julia markdown files stored in jupyterbook/myst

domluna commented 1 year ago

i think this is blocked by commonmark atm

On Mon, Jul 10, 2023 at 2:30 PM Jesse Perla @.***> wrote:

Any movement on this by chance? I would love to be able to have automatic formatting on save for julia markdown files stored in jupyterbook/myst

— Reply to this email directly, view it on GitHub https://github.com/domluna/JuliaFormatter.jl/issues/638#issuecomment-1629487311, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAORUF7IRDGA225LHIJ72KLXPRC3ZANCNFSM6AAAAAAQKOIHLQ . You are receiving this because you were mentioned.Message ID: @.***>

jlperla commented 1 year ago

Thanks @domluna

Is another way to do this just to more manually scan through the file and manually format selections? I don't want the formatter to touch the non-julia code at all. It might not even fulfill commonmark.