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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee3b6315f9a710c52dd9b90d032bd6ea5f23c69c
4
- data.tar.gz: c4cb88fc6f415e11bf87306ee0cb54f6011ef2c3
3
+ metadata.gz: 6160a0148bcc81aa588bd2c333b4cb209ffc1ec7
4
+ data.tar.gz: fff771f653fb8dd39bc581326748afe767c884c4
5
5
  SHA512:
6
- metadata.gz: 8027a65944c8da37afa92525556f0a6e651d4a63a262ed68ce4e195ea88d54c5377f89a52b792834bd0493357d3d2e72883f6b601a64986cf6f9fe719eb02777
7
- data.tar.gz: 0a3373d5c62e52d8badc699bf122fc46bad03b8a10938e9cca9f1eae89197a4d44b771ddbb2311ad726898e144468e070f7ac603e8e3805aee56a36f69424dfe
6
+ metadata.gz: 252da4287ea790422111c8628686675672c5dd8422daf89c721d118a94a935b221d1f1ceb3ce3ce140d57863ff13c0489ab6424cc3e22ba04b4ff14977d9e4ef
7
+ data.tar.gz: 3be21ac1c4ed50b01f6cda42b898c2af9e0cead327bc17c854b32b8a6c342220a1d5736bffb084bbeb3abbc0ceee5599bf18aeb84e4e61b9062a3887bc7ad120
@@ -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
- # varieables for metadata instead of as parameters for citations.
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
@@ -18,6 +18,10 @@ module AsciidoctorBibliography
18
18
  named_attributes["suffix"]
19
19
  end
20
20
 
21
+ def text
22
+ named_attributes["text"]
23
+ end
24
+
21
25
  def locators
22
26
  named_attributes.select { |key, _| LOCATORS.include? key }
23
27
  end
@@ -1,3 +1,3 @@
1
1
  module AsciidoctorBibliography
2
- VERSION = "0.6.0".freeze
2
+ VERSION = "0.7.0".freeze
3
3
  end
@@ -12,7 +12,7 @@
12
12
  </macro>
13
13
  <citation>
14
14
  <layout>
15
- <group delimiter=" " prefix="&lt;relref " suffix="/&gt;">
15
+ <group delimiter=" " prefix="&lt;xref " suffix="/&gt;">
16
16
  <text variable="citation-label" prefix="target=&quot;" suffix="&quot;"/>
17
17
  <text variable="locator" prefix="section=&quot;" suffix="&quot;"/>
18
18
  </group>
@@ -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 '+++<relref target="RFC2119"/>+++'
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 '+++<relref target="RFC2119" section="1.2.3"/>+++'
15
+ to eq '+++<xref target="RFC2119" section="1.2.3"/>+++'
16
16
  end
17
17
 
18
18
  it "formats a single bibliography entry" do
@@ -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.6.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-14 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor