asciidoctor-csl 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91d11025bf31c30262f9edf298ebf53b5039c458d3d8415e782ee69778a0b2e5
4
- data.tar.gz: 3f06bc987a676662545763a41483833e86a2eaade05cb4eb8aa7dff773171208
3
+ metadata.gz: 3b880f935d5f43d4ccfb97b46ff5622cd61aeea3bc71f6b97a18cb010ca68d32
4
+ data.tar.gz: 64a474f6dd9e279f965687eb3296aed7a4a27c0f30b1396020c4a6ced437bfbb
5
5
  SHA512:
6
- metadata.gz: 75b1473dd6047b43cab042abc3d5cc1ea1cb3f0ec515342afa4db5f17a3d922b79a6a14b8abb22413b4d6ca0680c9bf580bb3ccd4819cddf6a02a9602010d1a3
7
- data.tar.gz: ae2b790ba2d632736f6b1f9d61335b69ea86610f431623f5896f0e2b308d9fdc0da8023579cc0ca5ae716cd48bf9045bca8546c43f4924f2707da1938e5e03ce
6
+ metadata.gz: a5d3e789eb43329656c173d70668e30d1aa456066a61debb33c1da10c163b2f888d3548afcc14b9e31bcd6a9330bc0e89197ce41e0370e5480fe9b7184770e9e
7
+ data.tar.gz: 0e323c23f6adea8c4c701626971ee37a5a9af23475ef345b26802440e2605c6c663513d6c94f0062ebbd62a430dc89f349a34a6e80bc99e2b4021e0c972612d1
data/README.adoc CHANGED
@@ -80,6 +80,10 @@ Other values are `book`, `column`, `figure`, `folio`, `issue`, `line`, `note`, `
80
80
  |`link`
81
81
  |If the document has a bibliography, each cited item links to its entry.
82
82
  Use `link=false` to disable this for a single citation.
83
+
84
+ |`parens`
85
+ |Use `parens=false` to leave out the parentheses around the citation, e.g. to write "(see Smith, 2020, or the appendix)" yourself.
86
+ This removes the prefix and suffix the style puts around the whole citation; it does not affect brackets around each item, as in IEEE.
83
87
  |===
84
88
 
85
89
  With multiple keys, the locator and suffix apply to the last source, and the prefix to the first.
@@ -7,7 +7,7 @@ require 'citeproc'
7
7
  module AsciidoctorCsl
8
8
  # CitationMacro
9
9
  #
10
- # The `cite:key1,key2[locator, label, prefix=..., suffix=..., link=false]` macro.
10
+ # The `cite:key1,key2[locator, label, prefix=..., suffix=..., link=false, parens=false]` macro.
11
11
  class CitationMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
12
12
  include ::Asciidoctor::Logging
13
13
 
@@ -43,12 +43,8 @@ module AsciidoctorCsl
43
43
 
44
44
  items.last[:suffix] = ", #{attributes['suffix']}" if attributes['suffix']
45
45
 
46
- if csl.nil?
47
- logger.warn 'cite: CSL style not found'
48
- return nil
49
- end
50
-
51
46
  csl.engine.format.link_citations = @bibliography && attributes['link'] != 'false'
47
+ csl.engine.format.bare_citations = attributes['parens'] == 'false'
52
48
  text = csl.render(:citation, items)
53
49
  return create_footnote parent, text if csl.engine.style.info.citation_format == :note
54
50
 
@@ -8,6 +8,8 @@ module AsciidoctorCsl
8
8
  PROTECTED_RX = /<<[^,>]+,|\{[\w-]+}|\b[a-z][\w-]*:\S*?\[[^\]]*\]|\[[^\]]*\](?=#)|\+\+\+.*?\+\+\+|\+[^+]+\+/
9
9
  PLACEHOLDER_RX = /\u0000(\d+)\u0000/
10
10
  URL_VARIABLES = %w[URL DOI].freeze
11
+ BLOCK_EDGE = "\u0001"
12
+ LINE_BREAK = " +\n{empty}" # {empty} keeps the next line from starting a list, comment, etc.
11
13
 
12
14
  # Whether rendered citations link to their bibliography entry.
13
15
  attr_accessor :link_citations
@@ -21,6 +23,9 @@ module AsciidoctorCsl
21
23
  # Whether we are rendering inside a citation's cross-reference, where links cannot nest.
22
24
  attr_accessor :in_xref
23
25
 
26
+ # Whether citations leave out the affixes of their layout.
27
+ attr_accessor :bare_citations
28
+
24
29
  def bibliography(bibliography, _locale = nil)
25
30
  bibliography.connector = "\n\n"
26
31
  bibliography
@@ -76,6 +81,18 @@ module AsciidoctorCsl
76
81
  end
77
82
  end
78
83
 
84
+ # Blocks get their own line.
85
+ # AsciiDoc has no margins, so the margin column stays inline.
86
+ def apply_display
87
+ case options[:display]
88
+ when 'block', 'indent' then output.replace "#{BLOCK_EDGE}#{output}#{BLOCK_EDGE}"
89
+ when 'left-margin' then output << ' '
90
+ when 'right-inline' then nil
91
+ else
92
+ logger.warn "csl: unsupported display '#{options[:display]}'"
93
+ end
94
+ end
95
+
79
96
  # Replace the AsciiDoc syntax by placeholders without letters, so we only transform actual text.
80
97
  def apply_text_case
81
98
  protected = []
@@ -88,16 +105,24 @@ module AsciidoctorCsl
88
105
  output.gsub!(PLACEHOLDER_RX) { protected[Regexp.last_match(1).to_i] } if protected
89
106
  end
90
107
 
91
- # An affix that became part of a link is not added again.
108
+ # An affix that became part of a link is not added again, and bare citations have no layout affixes.
92
109
  def prefix
93
- @prefix_in_link ? '' : super
110
+ @prefix_in_link || bare_citation_layout? ? '' : super
111
+ end
112
+
113
+ def suffix
114
+ bare_citation_layout? ? '' : super
94
115
  end
95
116
 
96
117
  protected
97
118
 
98
- # Escape URLs and DOIs before any formatting, so AsciiDoc does not parse them.
119
+ # Before formatting, escape URLs and DOIs, so AsciiDoc does not parse them,
120
+ # and turn block edges into line breaks, so the layout's affixes stay on the first and last line.
99
121
  def setup!
100
122
  super
123
+ if node.is_a?(CSL::Style::Layout)
124
+ output.replace output.split(BLOCK_EDGE).map(&:strip).reject(&:empty?).join(LINE_BREAK)
125
+ end
101
126
  escape_url if node.is_a?(CSL::Style::Text) && URL_VARIABLES.include?(node.variable)
102
127
  end
103
128
 
@@ -134,6 +159,10 @@ module AsciidoctorCsl
134
159
  "pass:c[#{text.gsub(']', '\]')}]"
135
160
  end
136
161
 
162
+ def bare_citation_layout?
163
+ bare_citations && node.is_a?(CSL::Style::Layout) && node.parent.is_a?(CSL::Style::Citation)
164
+ end
165
+
137
166
  def url?(text)
138
167
  text.match?(%r{\Ahttps?://}i)
139
168
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsciidoctorCsl
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-csl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niko Strijbol