0143eb4c by Sylvester Keil

Support multiple locator labels

See #147
1 parent a4adcb40
......@@ -361,13 +361,18 @@ like: `...as Matz explains (2008, p. 42)`.
#### Page numbers and locators
If you would like to add page numbers to your citation, you can use the
`-l` or `--locator` option. For example, `{% cite ruby -l 23-5 %}` would
If you would like to add page numbers or similar locators to your citation,
use the `-l` or `--locator` option. For example, `{% cite ruby --locator 23-5 %}` would
produce a citation like `(Matsumoto, 2008, pp. 23-5)`.
When quoting multiple items (see above) you can add multiple locators after
the list of ids. For example, `{% cite ruby microscope -l 2 -l 24 & 32 %}`.
Page is the default locator, however, you can indicate the type of locator
by adding a `-L` or `--label` option (one for each locator) for instance,
`{% cite ruby microscope --label chapter --locator 3 -L figure -l 24 & 32 %}`
produces something like: `(Matsumoto, 2008, chap. 3; Shaughnessy, 2013, figs. 24 & 32)`.
#### Displaying formatted references
If you want to display the full formatted reference entry, you can use the
......
......@@ -250,6 +250,39 @@ Feature: Citations
year = {2008},
publisher = {O'Reilly Media}
}
@book{microscope,
title = {Ruby Under a Microscope},
author = {Pat Shaughnessy},
year = {2013},
publisher = {No Starch Press}
}
"""
And I have a page "scholar.html":
"""
---
---
{% cite ruby microscope --label chapter --locator 2-3 -L figure -l 4,5 %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "Matsumoto, 2008, chaps. 2-3; Shaughnessy, 2013, figs. 4,5" in "_site/scholar.html"
@tags @cite @locator @label
Scenario: Citations with multiple locator labels
Given I have a scholar configuration with:
| key | value |
| source | ./_bibliography |
| bibliography | my_references |
And I have a "_bibliography" directory
And I have a file "_bibliography/my_references.bib":
"""
@book{ruby,
title = {The Ruby Programming Language},
author = {Matsumoto, Yukihiro},
year = {2008},
publisher = {O'Reilly Media}
}
"""
And I have a page "scholar.html":
"""
......@@ -260,7 +293,7 @@ Feature: Citations
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
And I should see "Flanagan & Matsumoto, 2008, chap. 3" in "_site/scholar.html"
And I should see "Matsumoto, 2008, chap. 3" in "_site/scholar.html"
@tags @cite @citation_number
Scenario: Multiple citations using citation numbers
......
......@@ -18,9 +18,7 @@ module Jekyll
module Utilities
attr_reader :config, :site, :context,
:prefix, :text, :offset, :max, :label
attr_reader :config, :site, :context, :prefix, :text, :offset, :max
def split_arguments(arguments)
......@@ -71,7 +69,7 @@ module Jekyll
end
opts.on('-L', '--label LABEL') do |label|
@label = label
labels << label
end
opts.on('-o', '--offset OFFSET') do |offset|
......@@ -112,6 +110,10 @@ module Jekyll
@locators ||= []
end
def labels
@labels ||= []
end
def bibtex_files
@bibtex_files ||= [config['bibliography']]
end
......@@ -568,7 +570,7 @@ module Jekyll
end
def render_citation(items)
renderer.render items.zip(locators).map { |entry, locator|
renderer.render items.zip(locators.zip(labels)).map { |entry, (locator, label)|
cited_keys << entry.key
cited_keys.uniq!
......