asciidoctor-bibliography 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +10 -0
- data/lib/asciidoctor-bibliography/citation.rb +14 -1
- data/lib/asciidoctor-bibliography/citation_item.rb +4 -0
- data/lib/asciidoctor-bibliography/version.rb +1 -1
- data/lib/csl/styles/rfc-v3.csl +1 -1
- data/spec/citation_item_spec.rb +14 -0
- data/spec/csl/styles/rfc_v3_spec.rb +2 -2
- data/spec/macros_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6160a0148bcc81aa588bd2c333b4cb209ffc1ec7
|
4
|
+
data.tar.gz: fff771f653fb8dd39bc581326748afe767c884c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 252da4287ea790422111c8628686675672c5dd8422daf89c721d118a94a935b221d1f1ceb3ce3ce140d57863ff13c0489ab6424cc3e22ba04b4ff14977d9e4ef
|
7
|
+
data.tar.gz: 3be21ac1c4ed50b01f6cda42b898c2af9e0cead327bc17c854b32b8a6c342220a1d5736bffb084bbeb3abbc0ceee5599bf18aeb84e4e61b9062a3887bc7ad120
|
data/README.adoc
CHANGED
@@ -131,6 +131,16 @@ To `prefix` and `suffix` citations with arbitrary strings you can use the relati
|
|
131
131
|
cite:[Aa2017, prefix="see ", suffix=" if you will"]
|
132
132
|
----
|
133
133
|
|
134
|
+
You can replace the rendered citation with arbitrary `text` or interpolate it directly:
|
135
|
+
|
136
|
+
[source,asciidoc]
|
137
|
+
----
|
138
|
+
cite:[Aa2017, text="replacement text"]
|
139
|
+
// the next two lines are equivalent:
|
140
|
+
cite:[Aa2017, prefix="see ", suffix=" if you will"]
|
141
|
+
cite:[Aa2017, text="see {cite} if you will"]
|
142
|
+
----
|
143
|
+
|
134
144
|
To cite multiple resources you concatenate them as follows:
|
135
145
|
|
136
146
|
[source,asciidoc]
|
@@ -71,6 +71,7 @@ module AsciidoctorBibliography
|
|
71
71
|
items = prepare_items bibliographer, formatter, tex: tex
|
72
72
|
formatted_citation = formatter.engine.renderer.render(items, formatter.engine.style.citation)
|
73
73
|
escape_brackets_inside_xref! formatted_citation
|
74
|
+
interpolate_formatted_citation! formatted_citation
|
74
75
|
formatted_citation
|
75
76
|
end
|
76
77
|
|
@@ -80,9 +81,20 @@ module AsciidoctorBibliography
|
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
84
|
+
def interpolate_formatted_citation!(formatted_citation)
|
85
|
+
citation_items.each do |citation_item|
|
86
|
+
key = Regexp.escape citation_item.key
|
87
|
+
formatted_citation.gsub!(/___#{key}___(?<citation>.*?)___\/#{key}___/) do
|
88
|
+
# NOTE: this is slight overkill but easy to extend
|
89
|
+
(citation_item.text || "{cite}").
|
90
|
+
sub("{cite}", Regexp.last_match[:citation])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
83
95
|
def prepare_items(bibliographer, formatter, tex: false)
|
84
96
|
# NOTE: when we're using our custom TeX CSL styles prefix/suffix are used as
|
85
|
-
#
|
97
|
+
# variables for metadata instead of as parameters for citations.
|
86
98
|
cites_with_local_attributes = citation_items.map { |cite| prepare_metadata bibliographer, cite, affix: tex }
|
87
99
|
formatter.import cites_with_local_attributes
|
88
100
|
formatter.force_sort!(mode: :citation)
|
@@ -104,6 +116,7 @@ module AsciidoctorBibliography
|
|
104
116
|
ci = citation_items.detect { |c| c.key == item.id }
|
105
117
|
wrap_item item, ci.prefix, ci.suffix if affix
|
106
118
|
id = xref_id "bibliography", ci.target, item.id
|
119
|
+
wrap_item item, "___#{item.id}___", "___/#{item.id}___"
|
107
120
|
wrap_item item, "xref:#{id}{{{", "}}}" if options.hyperlinks?
|
108
121
|
item.label, item.locator = ci.locator
|
109
122
|
end
|
data/lib/csl/styles/rfc-v3.csl
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
</macro>
|
13
13
|
<citation>
|
14
14
|
<layout>
|
15
|
-
<group delimiter=" " prefix="<
|
15
|
+
<group delimiter=" " prefix="<xref " suffix="/>">
|
16
16
|
<text variable="citation-label" prefix="target="" suffix="""/>
|
17
17
|
<text variable="locator" prefix="section="" suffix="""/>
|
18
18
|
</group>
|
data/spec/citation_item_spec.rb
CHANGED
@@ -95,4 +95,18 @@ describe AsciidoctorBibliography::CitationItem do
|
|
95
95
|
expect(subject.suffix).to be_nil
|
96
96
|
end
|
97
97
|
end
|
98
|
+
|
99
|
+
describe "#text" do
|
100
|
+
subject { described_class.new }
|
101
|
+
|
102
|
+
it "returns the text if it exist" do
|
103
|
+
subject.parse_attribute_list("foo, text='prefix {ref} suffix'")
|
104
|
+
expect(subject.text).to eq("prefix {ref} suffix")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "returns nil if no text exists" do
|
108
|
+
subject.parse_attribute_list("foo, bar, zod=quz")
|
109
|
+
expect(subject.text).to be_nil
|
110
|
+
end
|
111
|
+
end
|
98
112
|
end
|
@@ -7,12 +7,12 @@ describe "cite macro with rfc-v3 style" do
|
|
7
7
|
|
8
8
|
it "formats a single citation" do
|
9
9
|
expect(formatted_citation("cite:[RFC2119]", options: options)).
|
10
|
-
to eq '+++<
|
10
|
+
to eq '+++<xref target="RFC2119"/>+++'
|
11
11
|
end
|
12
12
|
|
13
13
|
it "formats a single citation with locator" do
|
14
14
|
expect(formatted_citation("cite:[RFC2119, section=1.2.3]", options: options)).
|
15
|
-
to eq '+++<
|
15
|
+
to eq '+++<xref target="RFC2119" section="1.2.3"/>+++'
|
16
16
|
end
|
17
17
|
|
18
18
|
it "formats a single bibliography entry" do
|
data/spec/macros_spec.rb
CHANGED
@@ -13,6 +13,16 @@ describe "cite macro with apa style" do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
describe "cite macro with arbitrary interpolated text" do
|
17
|
+
it "formats a complex citation" do
|
18
|
+
expect(formatted_citation("cite:[Erdos65, text=foo {cite} bar]",
|
19
|
+
options: { "bibliography-style" => "apa",
|
20
|
+
"bibliography-database" => "database.bib",
|
21
|
+
"bibliography-hyperlinks" => "true" })).
|
22
|
+
to eq "(xref:bibliography-default-Erdos65[foo Erdős, Heyting, & Brouwer, 1965 bar])"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
16
26
|
describe "fullcite macro with apa style" do
|
17
27
|
it "formats a complex citation" do
|
18
28
|
expect(formatted_citation("fullcite:[Erdos65]",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-bibliography
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|