asciidoctor-bibtex 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/asciidoctor-bibtex/bibextension.rb +4 -2
- data/lib/asciidoctor-bibtex/processor.rb +2 -2
- data/lib/asciidoctor-bibtex/version.rb +1 -1
- data/lib/utils.rb +111 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c520a15832ff368d7b14a6a8c7d65081dc5f91c
|
4
|
+
data.tar.gz: 9433420aea00d9dfee97101f4fcab7efb87cf25e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d27c4efc1fb2ba1a73ef421070e3bfdc37556b73a529af48334f655c7c2c4f497488c0956b5927475424ccd6fa8849f511ba25b440e55b431b15d5f75a26a5de
|
7
|
+
data.tar.gz: 3765a65c06eb84aa7eb60589beb33df412e4171ea3e322585efeaab8364d29e33689b3616eee969fd2c493516d82506a07d9626abdc9aac8af67985ea4e72048
|
data/README.md
CHANGED
@@ -79,12 +79,12 @@ To add a list of formatted references, place `bibliography::[]` on a line by its
|
|
79
79
|
|
80
80
|
### Document Attributes
|
81
81
|
|
82
|
-
| Attribute Name | Description | Valid Values
|
83
|
-
| -------------- | --------------- | ----------
|
84
|
-
| bibtex-file | Bibtex database file | any string, or empty
|
85
|
-
| bibtex-style | Reference formatting style | any style supported by csl-styles
|
86
|
-
| bibtex-order | Order of citations | `appearance` or `alphabetical`
|
87
|
-
| bibtex-format | Formatting of citations and bibliography | `asciidoc` or `
|
82
|
+
| Attribute Name | Description | Valid Values | Default Value |
|
83
|
+
| -------------- | --------------- | ---------- | -------------- |
|
84
|
+
| bibtex-file | Bibtex database file | any string, or empty | Automatic searching |
|
85
|
+
| bibtex-style | Reference formatting style | any style supported by csl-styles | ieee |
|
86
|
+
| bibtex-order | Order of citations | `appearance` or `alphabetical` | `appearance` |
|
87
|
+
| bibtex-format | Formatting of citations and bibliography | `asciidoc` or `bibtex` or `biblatex` | `asciidoc` |
|
88
88
|
|
89
89
|
### Commandline
|
90
90
|
|
@@ -52,7 +52,7 @@ module AsciidoctorBibtex
|
|
52
52
|
class BibliographyBlockMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
|
53
53
|
use_dsl
|
54
54
|
named :bibliography
|
55
|
-
|
55
|
+
name_positional_attributes :style
|
56
56
|
|
57
57
|
def process parent, target, attrs
|
58
58
|
# NOTE: bibtex-file and bibtex-style set by this macro shall be
|
@@ -123,9 +123,11 @@ module AsciidoctorBibtex
|
|
123
123
|
end
|
124
124
|
|
125
125
|
references_asciidoc = []
|
126
|
-
if bibtex_format == :latex
|
126
|
+
if bibtex_format == :latex or bibtex_format == :bibtex
|
127
127
|
references_asciidoc << %(+++\\bibliography{#{bibtex_file}}{}+++)
|
128
128
|
references_asciidoc << %(+++\\bibliographystyle{#{bibtex_style}}+++)
|
129
|
+
elsif bibtex_format == :biblatex
|
130
|
+
references_asciidoc << %(+++\\printbibliography+++)
|
129
131
|
else
|
130
132
|
processor.cites.each do |ref|
|
131
133
|
references_asciidoc << processor.get_reference(ref)
|
@@ -23,7 +23,7 @@ module AsciidoctorBibtex
|
|
23
23
|
@output = output
|
24
24
|
@bibfile = bibfile
|
25
25
|
|
26
|
-
if output != :latex
|
26
|
+
if output != :latex and output != :bibtex and output != :biblatex
|
27
27
|
@citeproc = CiteProc::Processor.new style: @style, format: :html
|
28
28
|
@citeproc.import @biblio.to_citeproc
|
29
29
|
end
|
@@ -32,7 +32,7 @@ module AsciidoctorBibtex
|
|
32
32
|
# Return the complete citation text for given cite_data
|
33
33
|
def complete_citation cite_data
|
34
34
|
|
35
|
-
if @output == :latex
|
35
|
+
if @output == :latex or @output == :bibtex or @output == :biblatex
|
36
36
|
result = '+++'
|
37
37
|
cite_data.cites.each do |cite|
|
38
38
|
# NOTE: xelatex does not support "\citenp", so we output all
|
data/lib/utils.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Some extension and helper methods.
|
2
|
+
#
|
3
|
+
# Copyright (c) Peter Lane, 2012-13.
|
4
|
+
# Copyright (c) Zhang YANG, 2016-09.
|
5
|
+
# Released under Open Works License, 0.9.2
|
6
|
+
|
7
|
+
module AsciidoctorBibtex
|
8
|
+
module Utils
|
9
|
+
|
10
|
+
def find_bibtex_database dir
|
11
|
+
begin
|
12
|
+
candidates = Dir.glob("#{dir}/*.bib")
|
13
|
+
if candidates.empty?
|
14
|
+
return ""
|
15
|
+
else
|
16
|
+
return candidates.first
|
17
|
+
end
|
18
|
+
rescue # catch all errors, and return empty string
|
19
|
+
return ""
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Used with numeric styles to combine consecutive numbers into ranges
|
24
|
+
# e.g. 1,2,3 -> 1-3, or 1,2,3,6,7,8,9,12 -> 1-3,6-9,12
|
25
|
+
# leave references with page numbers alone
|
26
|
+
def combine_consecutive_numbers str
|
27
|
+
nums = str.split(",").collect(&:strip)
|
28
|
+
res = ""
|
29
|
+
# Loop through ranges
|
30
|
+
start_range = 0
|
31
|
+
while start_range < nums.length do
|
32
|
+
end_range = start_range
|
33
|
+
while (end_range < nums.length-1 and
|
34
|
+
nums[end_range].is_i? and
|
35
|
+
nums[end_range+1].is_i? and
|
36
|
+
nums[end_range+1].to_i == nums[end_range].to_i + 1) do
|
37
|
+
end_range += 1
|
38
|
+
end
|
39
|
+
if end_range - start_range >= 2
|
40
|
+
res += "#{nums[start_range]}-#{nums[end_range]}, "
|
41
|
+
else
|
42
|
+
start_range.upto(end_range) do |i|
|
43
|
+
res += "#{nums[i]}, "
|
44
|
+
end
|
45
|
+
end
|
46
|
+
start_range = end_range + 1
|
47
|
+
end
|
48
|
+
# finish by removing last comma
|
49
|
+
res.gsub(/, $/, '')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module AsciidoctorBibtexArrayExtensions
|
55
|
+
|
56
|
+
# Retrieve the third item of an array
|
57
|
+
# Note: no checks for validity
|
58
|
+
def third
|
59
|
+
self[2]
|
60
|
+
end
|
61
|
+
|
62
|
+
# Join items in array using commas and 'and' on last item
|
63
|
+
def semantic_join
|
64
|
+
if size < 2
|
65
|
+
return self.join("")
|
66
|
+
end
|
67
|
+
result = ""
|
68
|
+
self.each_with_index do |item, index|
|
69
|
+
if index.zero?
|
70
|
+
result << item
|
71
|
+
elsif index == size-1
|
72
|
+
result << " and #{item}"
|
73
|
+
else
|
74
|
+
result << ", #{item}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
return result
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# monkey patch the extension methods to Array
|
83
|
+
class Array
|
84
|
+
include AsciidoctorBibtexArrayExtensions
|
85
|
+
end
|
86
|
+
|
87
|
+
# Converts html output produced by citeproc to asciidoc markup
|
88
|
+
module StringHtmlToAsciiDoc
|
89
|
+
def html_to_asciidoc
|
90
|
+
r = self.gsub(/<\/?i>/, '_')
|
91
|
+
r = r.gsub(/<\/?b>/, '*')
|
92
|
+
r = r.gsub(/<\/?span.*?>/, '')
|
93
|
+
r = r.gsub(/\{|\}/, '')
|
94
|
+
r
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Provides a check that a string is in integer
|
99
|
+
# Taken from:
|
100
|
+
# http://stackoverflow.com/questions/1235863/test-if-a-string-is-basically-an-integer-in-quotes-using-ruby
|
101
|
+
module IntegerCheck
|
102
|
+
def is_i?
|
103
|
+
!!(self =~ /^[-+]?[0-9]+$/)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# monkey patch the extension methods into String
|
108
|
+
class String
|
109
|
+
include StringHtmlToAsciiDoc
|
110
|
+
include IntegerCheck
|
111
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-bibtex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zhang YANG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bibtex-ruby
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/asciidoctor-bibtex/processorutils.rb
|
93
93
|
- lib/asciidoctor-bibtex/styles.rb
|
94
94
|
- lib/asciidoctor-bibtex/version.rb
|
95
|
+
- lib/utils.rb
|
95
96
|
homepage: https://github.com/asciidoctor/asciidoctor-bibtex
|
96
97
|
licenses:
|
97
98
|
- OWL
|