mugiwara85 / CodeblockCustomizer

Codeblock Customizer plugin for Obsidian
MIT License
168 stars 7 forks source link

Optional starting line number #22

Closed mayurankv closed 1 year ago

mayurankv commented 1 year ago

Would it be possible to have an optional starting line number? You mentioned adding a ln:false/ln:true option. I would propose extending this syntax to also allow ln:x where x is a number which is the starting line number. Ideally this would be restricted to positive integers.

Note highlights should refer to the line number as rendered, not the true line number. I.e. a codeblock with ln:901 highlighting the fifth line should have hl:905, not hl:5.

mugiwara85 commented 1 year ago

ln is either true or false. It would make no sense to be able to set a number for this parameter. I can create a parameter offset where you could set the offset. Why would this have to be restricted to positive numbers? Why should highlights refer to the rendered numbered? It would not make much sense for me. If you have set offset to 140 and you have 200 lines of code, then you'd have to count which line is it you want highlight. It would be easier to just look at the line number and set that one, or not?

mayurankv commented 1 year ago

In absence of my original ln suggestion, an offset parameter would be brilliant.

With all due respect I disagree about the ln parameter. It would be trivial to parse such a parameter with either integer or boolean input. Furthermore, it would decrease the number of options specified in the codeblock opening line (which can already get long). This would mean instead of having two different parameters to set, you could capture all of the corresponding behaviour with just one. I understand if you don't wish to implement this in such fashion though.

I feel a bit more strongly about the highlighting issue. On the contrary, if you set the offset to 140 and have 200 lines of code. Say you want to highlight the 100th line, your suggestion would be to add hl:100 and mine would be to add hl:240. If you know what lines you are highlighting by numbers, your method makes more sense, but more often when highlighting, you identify which lines to highlight whilst reading the code (or directly from your IDE) and in both of these scenarios, the code number you would read off would be 240 and not 100. You would never actually know that a line you want to highlight in a segment of code is line 100 unless you read it without the offset added which is unnecessary.

mugiwara85 commented 1 year ago

Ok, that makes sense, I agree with highlighting. So hl:905 instead of hl:5. The ln parameter does work the following way. Say, you enabled line numbers globally. In this case if you specify ln:false line numbers would not be shown to that specific code block. On the other way around if you disabled line numbers globally ln:true would enable line numbers for that specific code block. You are right about the parameters, that they are getting too long. Would ln:true,900 be ok? That way it could be enabled/disabled, and after the "," you could define the offset.

mayurankv commented 1 year ago

I think that would be ok, but would it not be also possible to just have false -> no line numbering true -> line numbering starting at 1 {number} -> line numbering starting at number

The added benefit of this is it is once again the actual line number as seen in the IDE/reading mode not an offset. (i.e. to offset a code by 100 lines, it actually starts at line 101 now. Ideally you would put ln:101 rather than ln:true,100) if that makes sense.

I guess my point is that you would never have ln:false,{number} so why let it be an option? Are you considering the case someone temporarily wants to disable the line numbers and then return to the same offset? I understand this use case but syntactically having the line number stored and not used makes no sense. If you wanted to cater to that use case, the way I would personally do it is have ln as I described above and add a second flag disableln to disable line number irrespective of the previous ln flag. I guess in your way, you could reverse your parameters so have:

ln:false -> no line numbers ln:true -> line numbers starting at 1 (an alias for ln:1) ln:{number} -> line number starting at {number} ln:{number},false -> line number starting at {number} but temporarily disabled

mugiwara85 commented 1 year ago

I agree with this method totally: "I think that would be ok, but would it not be also possible to just have false -> no line numbering true -> line numbering starting at 1 {number} -> line numbering starting at number"

There is no need for an option where line numbers offset is set, but the linenumbers are disabled.

mayurankv commented 1 year ago

Brilliant!

mugiwara85 commented 1 year ago

This one will also be included in Release 1.1.10 image