facelessuser / pymdown-extensions

Extensions for Python Markdown
https://facelessuser.github.io/pymdown-extensions/
Other
957 stars 254 forks source link

Allow indexing from end #2517

Open XtremeOwnageDotCom opened 3 days ago

XtremeOwnageDotCom commented 3 days ago

Description

In the current state, when including specific line numbers, we can target specific lines.

  1. To set starting line number: myfile:3
    • This will include the entire file STARTING at line number 3.
  2. For lines up to a specific line: myfile::10
    • This will include lines 1 - 10
  3. For a range of lines: myfile:4:12
    • This will include lines 4 - 12.
  4. To include a SPECIFIC line: myfile:3:3
    • This will only include line number 3

BUT, what if we wanted to include the last 10 lines of the file. There currently is not a way to index from the end of the file.

Benefits

Easy feature, which adds more utility, for potentially niche use-cases.

Solution Idea

Add the ability to do negative indexing:

Given, a file that is 100 lines long-

  1. To set starting line number: myfile:-3
    • This will include lines 97-100
      1. For lines up to a specific line: myfile::-51
    • This will include lines 1 - 49
  2. For a range of lines: myfile:4:-25
    • This will include lines 4 - 75.
  3. To include a SPECIFIC line: myfile:-0:-0
    • This will only include the very last line.
XtremeOwnageDotCom commented 3 days ago

The idea, is from a relatively new feature in c#

Related Docs: