Skip to content

Embed only part of a file by specifying start and end line numbers #11

Description

@lukehorvat

First of all, thanks for your good work on this plugin.

Lately, I've been thinking that it would be cool if you could embed only small parts of individual files i.e. from line A to line B. Ideally, this feature would be enabled by specifying optional start and end line number parameters in the shortcode.

[gist id=546764 file=file.txt start=4 end=12]

And if one does not specify a start or an end, it defaults to the beginning or end of the file respectively.

Looking at your code, on line 116 you do this:

$gist .= htmlentities($fileInfo['content']);

I don't have any familiarity with PHP, but from what I can assume, htmlentities() converts the file contents to a single string containing HTML. So, I'm thinking you could simply split the string on <br/> (or \n if you do it before calling htmlentities()) to get an array of individual lines, get the sub-array from index start to end, and then convert that sub-array back to a string and assign it to the $gist variable.

What do you think?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions