Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would like to extract just parts of a file #3

Open
ralfw opened this issue Jan 25, 2016 · 5 comments
Open

Would like to extract just parts of a file #3

ralfw opened this issue Jan 25, 2016 · 5 comments

Comments

@ralfw
Copy link
Contributor

ralfw commented Jan 25, 2016

I'd like to extract just a range of lines from a source code file. The syntax could look like this:

{% codesnippet "./myfile.js", linerange="10-12" %}{% endcodesnippet %}

Ideally I could even specify multiple line ranges, eg:

{% codesnippet "./myfile.js", linerange="10-12, 14, 17-18" %}{% endcodesnippet %}

The ranges would be separated by a line containing just "...", eg:

Line 10
Line 11
Line 12
...
Line 14
...
Line 17
Line 18
SamyPesse added a commit that referenced this issue Jan 25, 2016
@nagim
Copy link

nagim commented Jan 25, 2016

Another "upgrade" to this could be the possibility to "latch onto" some control characters/tags in the source code file, so the referenced part will be the same even if the line numbers changed (if code is added/removed in the file).
This would be like the AsciiDoc feature (example), which would be welcomed by a lot of people (myself included 😄).

@ralfw
Copy link
Contributor Author

ralfw commented Jan 25, 2016

I'd like that, too :-) Example:

{% codesnippet "./myfile.js", tags="#1234,#9876" %}{% endcodesnippet %}

I think there's even no need for a prefix in the source for for opening/closing a tagged range. Each region would just start with a tag and end whenever the same tag appears agains, e.g.

a
b
#1234
c
d
#1234
e
#9876
f
#9876

would be included as

c
d
...
f

@ralfw
Copy link
Contributor Author

ralfw commented Jan 31, 2016

Just saw, a fix has been introduced for this. Great! But it comes with a small bug. Pls see my inline comment on the committed code.

@sbaechler
Copy link

I noticed that currently the lines property seems to fetch the wrong lines. In the example below the lines 93 to 108 have been included.

{% codesnippet "https://raw.githubusercontent.com/sbaechler/polygon/master/src/Hexagon.elm", lines="76:89", language="elm" %}{% endcodesnippet %}

https://sbaechler.gitbooks.io/elm-hexagon/content/v/096ebfc78082d42142074cf98fa0638b0bf0e267/doc/2-dancefloor.html
https://github.com/sbaechler/polygon/blob/master/src/Hexagon.elm

@sbaechler
Copy link

It looks like your Regex is ignoring empty lines: http://stackoverflow.com/questions/5034781/js-regex-to-split-by-line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants