owickstrom / pandoc-include-code

A Pandoc filter for including code from source files
Mozilla Public License 2.0
139 stars 18 forks source link

Ability to .numberLines starting at the actual line number in the file #9

Closed tekknolagi closed 6 years ago

tekknolagi commented 6 years ago

I'm not sure how would be the best way to do this, but it would be nice to be able to do something like:

    ```{.python .numberLines include=a.py snippet=plasma-equation}
`plasma` is parametrized by two variables, `T_p` and `T_gamma`, because they
appear as different constants in $(i)$ and $(ii)$:

```{.python .numberLines include=a.py snippet=exercises}
```


And have section 1 be lines 1-14, and section 2 be lines 15-30 -- instead of both starting at 1.

Otherwise, I love this filter! Thanks a bunch for writing it -- it has made my build system so much easier.
owickstrom commented 6 years ago

That's a good suggestion! I usually don't use .numberLines, but I can see how that would be useful. The filter could detect numberLines being in the classes, and add the appropriate the startFrom attribute. The issue right now is that the snippet support is a bit hacky. If you want to have a stab at it, let me know!

owickstrom commented 6 years ago

In fact, I'm giving this an hour of refactoring and trying it out. :)

owickstrom commented 6 years ago

I'm working on this branch: https://github.com/owickstrom/pandoc-include-code/tree/snippet-line-numbers

So far I've only restricted the filter a bit, prohibiting the "range mode" and "snippet mode" of inclusion being used together. This is to make the program flow simpler before adding the startFrom support, which should be pretty straightforward now.

owickstrom commented 6 years ago

I think this should be working now. Can you try installing from the branch I referred to? Thanks!

tekknolagi commented 6 years ago

Oh, wow. I'll take a look!

tekknolagi commented 6 years ago

I'm not sure I'm doing it right. I have {include=a-pdf.py .python .numberLines snippet=plasma-equation} and {.python .numberLines include=a-pdf.py snippet=bisect-rootfind}, but the line numbers for both snippets start at 1.

tekknolagi commented 6 years ago

Actually, this appears to work. I think I was looking at the wrong PDF. Awesome, thanks!

owickstrom commented 6 years ago

Nice! I'll merge it then, and close the ticket. Also releasing a new version on Hackage.

owickstrom commented 6 years ago

Closed by #10.