mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-31 04:58:07 +00:00
Add lines
attribute for Git blob include processor
This commit is contained in:
parent
fb5dac150b
commit
07faed03a1
@ -32,6 +32,9 @@ This is only effective if `diff` option is given.
|
||||
- `other` is the other commit to be compared with.
|
||||
This is only effective if `diff` option is given.
|
||||
|
||||
- `lines` get the specified lines from the path.
|
||||
It uses the same parser as the line specifier from link:https://docs.asciidoctor.org/asciidoc/latest/verbatim/highlight-lines/[highlighting select lines] so the syntax is the same.
|
||||
|
||||
There's also a couple of link:https://docs.asciidoctor.org/asciidoc/latest/attributes/options/[options] for this component.
|
||||
You can give the following options through `opts` attribute (i.e., `opts="diff,reverse"`).
|
||||
|
||||
@ -61,3 +64,5 @@ The following examples assume that `doccontentref` points to `content/posts/samp
|
||||
- `include::git:{doccontentref}[opts="diff", path=Gemfile]` should include a diff of the Gemfile from `content/posts/sample` branch (assuming that Gemfile has changed).
|
||||
|
||||
- `include::git:non-existing-rev[opts="diff"]` should result in a warning with the non-existing revision.
|
||||
|
||||
- `include::git:{doccontentref}[path=README, lines=2..5]` should transclude the README file from lines 2-5.
|
||||
|
@ -41,7 +41,19 @@ class GitBlobIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
|
||||
git_object.target.tree.path attrs['path']
|
||||
end
|
||||
|
||||
reader.push_include repo.lookup(inner_entry[:oid]).content
|
||||
content = repo.lookup(inner_entry[:oid]).content
|
||||
|
||||
if attrs.key? 'lines'
|
||||
content_lines = content.lines
|
||||
new_content = +''
|
||||
doc.resolve_lines_to_highlight(content, attrs['lines']).each do |line_no|
|
||||
new_content << content_lines.at(line_no - 1)
|
||||
end
|
||||
|
||||
content = new_content
|
||||
end
|
||||
|
||||
reader.push_include content
|
||||
end
|
||||
rescue StandardError => e
|
||||
reader.push_include "Unresolved directive for '#{target}' with the following error:\n#{e}"
|
||||
|
Loading…
Reference in New Issue
Block a user