astrale-sharp / typstfmt

Apache License 2.0
253 stars 25 forks source link

Unstable indentation calcultation #120

Open drupol opened 1 year ago

drupol commented 1 year ago

Hello,

When running typstfmt on this snippet:

#focus-slide[
  #fit-to-height(3em)[Introduction]

  #pdfpc.speaker-note(```
    Let's start the introduction with a quote from Foo Bar
  ```)
]

the resulting output is:

#focus-slide[
  #fit-to-height(3em)[Introduction]

  #pdfpc.speaker-note(```
      Let's start the introduction with a quote from Ken Thompson
    ```)
]

I believe that there's an issue in the #pdfpc.speaker-note handling. Also, when running multiple times the formatter on that example, the indentation never stops growing, after a couple of times, it become:

#focus-slide[
  #fit-to-height(3em)[Introduction]

  #pdfpc.speaker-note(```
                    Let's start the introduction with a quote from Ken Thompson
                  ```)
]
astrale-sharp commented 1 year ago

Thanks a lot for the report! I'll investigate !

astrale-sharp commented 1 year ago

This is a hard problem to solve right now.

format_content_blocks adds an indent to everything inside a content block and since it still valid spaces for the raw block, it "absorbs" them.

A temporary solution could be to disable indenting inside markup blocks (possibly only if it contains raw text!

I went ahead and implemented this temporary solution here https://github.com/astrale-sharp/typstfmt/commit/6974e5d907fc1a561872ae90402549f7afe397ed, ideally, the program could be smart enough to only indent where there is no raw text