Open SkytAsul opened 2 months ago
false
and none
should disable gobbling, I guess.
For now, setting gobble: 0
should work.
Thanks. I have another problem: the auto
gobble value does not work properly if used alongside showrange
.
For instance:
#sourcecode(showrange: (5, 7))[```
4 spaces
4 spaces
4 spaces
4 spaces
8 spaces
8 spaces
8 spaces
4 spaces
```]
Will only remove 4 spaces instead of 8.
Good catch. Whitespace is removed before slicing the code to the desired range. This probably should be done the other way around.
I don't understand why. Slicing the code to the range is done at line 152: https://github.com/jneug/typst-codelst/blob/bda9c7a6dad678749846eeeaa643cd19f30ca495/codelst.typ#L152 Whitespace removal is done at line 288: https://github.com/jneug/typst-codelst/blob/bda9c7a6dad678749846eeeaa643cd19f30ca495/codelst.typ#L288 I would like to propose a PR but this does not make sense :sweat_smile:
The package needs to do several steps of pre-processing to the code. The line you reference is needed for parsing labels and acts on the code before syntax highlighting. The actual slicing happens around line 197, after highlighting (to make sure things like comments are highlighted properly, before cutting of lines).
The gobbling acts on the raw text of the code, again before highlighting.
I see. Unfortunately, if the gobbling code is moved inside the show rule, we lose ability to easily trim the string because we end up having to modify content. I'll try to see what I can do and if I end up with something usable, I'll make a PR.
Yes, that's why I implemented it the way it is. You can remove whitespace after highlighting, but it's a bit more messy.
But I think it should be possible to simply remove the whitespace from the complete code (even lines outside the range with less whitespace), because it won't mess with syntax highlighting.
It's a lot messier, I just finished it and it's really ugly. You can see my commit if you want: https://github.com/SkytAsul/typst-codelst/commit/2f86d1e03c6bd6c00f08330fff64be798809ce8f (I could have probably done it a little cleaner, but the main idea is here.)
If what you meant in your above message is to gobble the whitespaces even in lines that contains less whitespaces that the desired gobbling amount, well that's clever but it could cause issue on languages relying on indentation? Idk if the syntax coloring is basing itself on indentation.
True. It would probably not work for e.g. Python.
I'm currently on holidays but will habe a look at your code in the next few days.
No hurry. It works for me so take your time, enjoy your holidays :)
Hello!
Setting
gobble: false
as a parameter tosourcecode
does not work: