asciidoctor-bibtex 0.5.0 → 0.8.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 +151 -0
- data/lib/asciidoctor-bibtex/bibitem_macro.rb +53 -0
- data/lib/asciidoctor-bibtex/{CitationMacro.rb → citation_macro.rb} +1 -1
- data/lib/asciidoctor-bibtex/{CitationUtils.rb → citation_utils.rb} +0 -0
- data/lib/asciidoctor-bibtex/extensions.rb +36 -12
- data/lib/asciidoctor-bibtex/{PathUtils.rb → path_utils.rb} +0 -0
- data/lib/asciidoctor-bibtex/{Processor.rb → processor.rb} +73 -27
- data/lib/asciidoctor-bibtex/{StringUtils.rb → string_utils.rb} +0 -0
- data/lib/asciidoctor-bibtex/{StyleUtils.rb → style_utils.rb} +0 -0
- data/lib/asciidoctor-bibtex/version.rb +1 -1
- metadata +31 -50
- data/README.md +0 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d1f03803a062ef4e551b3b974200595dd61e1b79d5b1e55f476b4aa9191abdb
|
4
|
+
data.tar.gz: edcba2be0db713c30e82b155cb350e70fc3ffe64db6709d7ab3740251ccb8e37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ddbc0f7c25bc17f2bf25eb6e4711bbab5583a1e1ea472e911cacd04798a345c5bb6cf5a44bcf8504db65b4bb1efbf4a883c9f552d1fa40a9a94ea283c999c65
|
7
|
+
data.tar.gz: df997b1243e28c0f42e13083df3a6f57b7afadca8895d08268d4ede6ceba48ad34e1cd70b9948b247cda6e400aa61aa25c8b88d90f04a7b5d5937a6a0328de5e
|
data/README.adoc
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
= asciidoctor-bibtex: bibtex integration for AsciiDoc
|
2
|
+
// Settings:
|
3
|
+
:idprefix:
|
4
|
+
:idseparator: -
|
5
|
+
ifndef::env-github[:icons: font]
|
6
|
+
ifdef::env-github,env-browser[]
|
7
|
+
:toc: macro
|
8
|
+
:toclevels: 1
|
9
|
+
endif::[]
|
10
|
+
ifdef::env-github[]
|
11
|
+
:!toc-title:
|
12
|
+
:status:
|
13
|
+
endif::[]
|
14
|
+
// URLs:
|
15
|
+
:url-asciidoctor: http://asciidoctor.org
|
16
|
+
:url-asciidoctor-mathematical: https://github.com/asciidoctor/asciidoctor-mathematical
|
17
|
+
:url-asciidoctor-pdf: https://github.com/asciidoctor/asciidoctor-pdf
|
18
|
+
:url-asciidoctor-latex: https://github.com/asciidoctor/asciidoctor-latex
|
19
|
+
:url-asciidoc-bib: https://github.com/petercrlane/asciidoc-bib
|
20
|
+
:url-gem: https://rubygems.org/gems/asciidoctor-bibtex
|
21
|
+
|
22
|
+
ifdef::status[]
|
23
|
+
image:https://img.shields.io/travis/asciidoctor/asciidoctor-bibtex/master.svg[Build Status (Travis CI),link=https://travis-ci.org/asciidoctor/asciidoctor-bibtex]
|
24
|
+
image:https://img.shields.io/gem/v/asciidoctor-bibtex.svg[Latest Release, link=https://rubygems.org/gems/asciidoctor-bibtex]
|
25
|
+
endif::[]
|
26
|
+
|
27
|
+
asciidoctor-bibtex adds bibtex integration to AsciiDoc documents by introducing three new macros: `cite:[KEY]`, `bibitem:[KEY]` and `bibliography::[]`. Citations are parsed and replaced with formatted inline texts, and reference lists are automatically generated and inserted into where `bibliography::[]` is placed. `bibitem:[KEY]` will insert a rendered bibliography item directly into the text.
|
28
|
+
|
29
|
+
asciidoctor-bibtex is designed to be used as an extension to {url-asciidoctor}[Asciidoctor]. Thus this extension can be used together with other asciidoctor extensions such as {url-asciidoctor-mathematical}[asciidoctor-mathematical] and {url-asciidoctor-pdf}[asciidoctor-pdf] to enrich your AsciiDoc experience.
|
30
|
+
|
31
|
+
NOTE: asciidoctor-bibtex no longer supports AsciiDoc-to-AsciiDoc conversion.
|
32
|
+
|
33
|
+
== History
|
34
|
+
|
35
|
+
asciidoctor-bibtex starts as a fork of {url-asciidoc-bib}[asciidoc-bib] and goes along a different path.
|
36
|
+
The major reason for the fork at the time was the differences in citation and bibliography macros.
|
37
|
+
asciidoc-bib failed to follow the grammar of macros in AsciiDoc and thus caused problems with existing documents and extensions.
|
38
|
+
Thus, a fork was needed.
|
39
|
+
Another reason was the inability to pass configuration via AsciiDoc attributes.
|
40
|
+
|
41
|
+
While {url-asciidoc-bib}[asciidoc-bib] focuses on replacing citations in the original documents and produces new AsciiDoc documents, asciidoctor-bibtex focuses on compatibility with Asciidoctor and other Asciidoctor extensions at the very beginning.
|
42
|
+
As time passes, asciidoctor-bibtex diverges significantly from its ancesstor.
|
43
|
+
For example, asciidoctor-bibtex now supports generating real bibtex citations and bibliography, so it can be used together with {url-asciidoctor-latex}[asciidoctor-latex] for native bibtex support.
|
44
|
+
|
45
|
+
== Install
|
46
|
+
|
47
|
+
$ gem install asciidoctor-bibtex
|
48
|
+
|
49
|
+
asciidoctor-bibtex depends on https://github.com/inukshuk/bibtex-ruby[bibtex-ruby], https://github.com/inukshuk/citeproc-ruby[citeproc-ruby], and https://github.com/inukshuk/csl-styles[csl-styles].
|
50
|
+
Ensure the `ruby-dev` and `libxslt1-dev` packages are installed on your machine so the dependencies will compile properly.
|
51
|
+
|
52
|
+
{url-asciidoctor}[Asciidoctor] must also be installed for 'asciidoctor-bibtex' to work.
|
53
|
+
Asciidoctor version 2.0.0 or higher is required.
|
54
|
+
|
55
|
+
== Usage
|
56
|
+
|
57
|
+
First, you need to have a valid bibtex file.
|
58
|
+
You specify the location to this file using the `bibtex-file` document attribute.
|
59
|
+
|
60
|
+
=== Macros
|
61
|
+
|
62
|
+
Syntax for inserting a citation is the following inline macro:
|
63
|
+
|
64
|
+
cite|citenp:[ref(pages), ...]
|
65
|
+
|
66
|
+
where '(pages)' is optional.
|
67
|
+
|
68
|
+
Examples of "chicago-author-date" style:
|
69
|
+
|
70
|
+
* `cite:[Lane12]` becomes "(Lane 2012)"
|
71
|
+
* `citenp:[Lane12]` becomes "Lane (2012)"
|
72
|
+
* `cite:[Lane12(59)]` becomes "(Lane 2012, 59)"
|
73
|
+
|
74
|
+
For *apa* (Harvard-like) style:
|
75
|
+
|
76
|
+
* `cite:[Lane12]` becomes "(Lane, 2012)"
|
77
|
+
* `citenp:[Lane12]` becomes "Lane (2012)"
|
78
|
+
* `cite:[Lane12(59)]` becomes "(Lane, 2012, p.59)"
|
79
|
+
|
80
|
+
For *ieee*, a numeric style:
|
81
|
+
|
82
|
+
`cite:[Lane12,Lane11]` becomes "[1, 2]"
|
83
|
+
|
84
|
+
To add a list of formatted references, place `bibliography::[]` on a line by itself.
|
85
|
+
|
86
|
+
One can use `bibitem:[Lane12]` to insert a rendered bibliography item inline, maybe to generate a cv. For example:
|
87
|
+
|
88
|
+
[source, asciidoc]
|
89
|
+
----
|
90
|
+
= My CV
|
91
|
+
|
92
|
+
== Publications
|
93
|
+
|
94
|
+
=== 2019
|
95
|
+
|
96
|
+
- bibitem:[Me2019a]
|
97
|
+
- bibitem:[Me2019b]
|
98
|
+
- bibitem:[Me2019c]
|
99
|
+
----
|
100
|
+
|
101
|
+
=== Configuration
|
102
|
+
|
103
|
+
Configuration is applied in the form of AsciiDoc document attributes, which must be defined in the document header.
|
104
|
+
|
105
|
+
|===
|
106
|
+
| Attribute Name | Description | Valid Values | Default Value
|
107
|
+
|
108
|
+
| bibtex-file
|
109
|
+
| Bibtex database file
|
110
|
+
| any string, or empty
|
111
|
+
| Automatic searching
|
112
|
+
|
113
|
+
| bibtex-style
|
114
|
+
| Reference formatting style
|
115
|
+
| any style supported by csl-styles
|
116
|
+
| ieee
|
117
|
+
|
118
|
+
| bibtex-order
|
119
|
+
| Order of citations
|
120
|
+
| `appearance` or `alphabetical`
|
121
|
+
| `appearance`
|
122
|
+
|
123
|
+
| bibtex-format
|
124
|
+
| Formatting of citations and bibliography
|
125
|
+
| `asciidoc`, `bibtex` or `biblatex`
|
126
|
+
| `asciidoc`
|
127
|
+
|
128
|
+
| bibtex-throw
|
129
|
+
| Throw an error on unknown references
|
130
|
+
| `true` or `false`
|
131
|
+
| `false`
|
132
|
+
|
133
|
+
| bibtex-citation-template
|
134
|
+
| Custom citation template for numeric style
|
135
|
+
| Any string matching `/(.+?)\$id(.+)/`
|
136
|
+
| `[$id]`
|
137
|
+
|===
|
138
|
+
|
139
|
+
=== Commandline
|
140
|
+
|
141
|
+
Use asciidoctor-bibtex as an extension with the CLI:
|
142
|
+
|
143
|
+
$ asciidoctor -r asciidoctor-bibtex sample.adoc
|
144
|
+
|
145
|
+
== License
|
146
|
+
|
147
|
+
The files within this project may be distributed under the terms of the http://owl.apotheon.org[Open Works License].
|
148
|
+
|
149
|
+
== Links
|
150
|
+
|
151
|
+
See {url-asciidoc-bib} for the original asciidoc-bib source.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# BibitemMacro.rb
|
3
|
+
#
|
4
|
+
# Copyright (c) Zhang Yang, 2020.
|
5
|
+
#
|
6
|
+
# Released under Open Works License, 0.9.2
|
7
|
+
#
|
8
|
+
|
9
|
+
module AsciidoctorBibtex
|
10
|
+
# BibitemMacro
|
11
|
+
#
|
12
|
+
# Class to hold information about a bibitem macro. A bibtem macro has
|
13
|
+
# only text and key
|
14
|
+
#
|
15
|
+
# This class also provides a class method to extract macros from a line of
|
16
|
+
# text.
|
17
|
+
#
|
18
|
+
class BibitemMacro
|
19
|
+
#
|
20
|
+
# Grammar for the bibitem macro: bibitem:[key]
|
21
|
+
#
|
22
|
+
|
23
|
+
# matches a bibitem key
|
24
|
+
BIBITEM_KEY = /[^\s\]]+/.freeze
|
25
|
+
# matches the full macro
|
26
|
+
BIBITEM_MACRO = /bibitem:\[(#{BIBITEM_KEY})\]/.freeze
|
27
|
+
|
28
|
+
# Given a line, return a list of BibitemMacro instances
|
29
|
+
def self.extract_macros(line)
|
30
|
+
result = []
|
31
|
+
full = BIBITEM_MACRO.match line
|
32
|
+
while full
|
33
|
+
text = full[0]
|
34
|
+
key = full[1]
|
35
|
+
result << BibitemMacro.new(text, key)
|
36
|
+
# look for next citation on line
|
37
|
+
full = BIBITEM_MACRO.match full.post_match
|
38
|
+
end
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :text, :key
|
43
|
+
|
44
|
+
# Create a BibitemMacro object
|
45
|
+
#
|
46
|
+
# text: the full macro text matched by BIBITEM_MACRO
|
47
|
+
# key: bibitem key
|
48
|
+
def initialize(text, key)
|
49
|
+
@text = text
|
50
|
+
@key = key
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -54,7 +54,7 @@ module AsciidoctorBibtex
|
|
54
54
|
|
55
55
|
# Given a line, return a list of CitationData instances
|
56
56
|
# containing information on each set of citation information
|
57
|
-
def self.
|
57
|
+
def self.extract_macros(line)
|
58
58
|
result = []
|
59
59
|
full = CITATION_MACRO.match line
|
60
60
|
while full
|
File without changes
|
@@ -7,8 +7,8 @@ require 'asciidoctor/extensions'
|
|
7
7
|
require 'asciidoctor/reader'
|
8
8
|
require 'asciidoctor/parser'
|
9
9
|
|
10
|
-
require_relative '
|
11
|
-
require_relative '
|
10
|
+
require_relative 'path_utils'
|
11
|
+
require_relative 'processor'
|
12
12
|
|
13
13
|
module AsciidoctorBibtex
|
14
14
|
module Asciidoctor
|
@@ -67,10 +67,14 @@ module AsciidoctorBibtex
|
|
67
67
|
bibtex_order = ((document.attr 'bibtex-order') || 'appearance').to_sym
|
68
68
|
bibtex_format = ((document.attr 'bibtex-format') || 'asciidoc').to_sym
|
69
69
|
bibtex_throw = ((document.attr 'bibtex-throw') || 'false').to_s.downcase
|
70
|
+
bibtex_citation_template = ((document.attr 'bibtex-citation-template') || '[$id]').to_s
|
70
71
|
|
71
72
|
# Fild bibtex file automatically if not supplied.
|
72
73
|
if bibtex_file.empty?
|
73
|
-
bibtex_file = AsciidoctorBibtex::PathUtils.
|
74
|
+
bibtex_file = AsciidoctorBibtex::PathUtils.find_bibfile document.base_dir
|
75
|
+
end
|
76
|
+
if bibtex_file.empty?
|
77
|
+
bibtex_file = AsciidoctorBibtex::PathUtils.find_bibfile '.'
|
74
78
|
end
|
75
79
|
if bibtex_file.empty?
|
76
80
|
bibtex_file = AsciidoctorBibtex::PathUtils.find_bibfile "#{ENV['HOME']}/Documents"
|
@@ -84,23 +88,32 @@ module AsciidoctorBibtex
|
|
84
88
|
prose_blocks = document.find_by do |b|
|
85
89
|
(b.content_model == :simple) ||
|
86
90
|
(b.context == :list_item) ||
|
87
|
-
(b.context == :table_cell)
|
91
|
+
(b.context == :table_cell) ||
|
92
|
+
(b.title?)
|
88
93
|
end
|
89
94
|
return nil if prose_blocks.nil?
|
90
95
|
|
91
96
|
processor = Processor.new bibtex_file, true, bibtex_style, bibtex_locale,
|
92
97
|
bibtex_order == :appearance, bibtex_format,
|
93
|
-
bibtex_throw == 'true'
|
98
|
+
bibtex_throw == 'true', custom_citation_template: bibtex_citation_template
|
94
99
|
|
95
100
|
# First pass: extract all citations.
|
96
101
|
prose_blocks.each do |block|
|
97
102
|
if block.context == :list_item || block.context == :table_cell
|
98
|
-
|
99
|
-
|
100
|
-
|
103
|
+
# NOTE: we access the instance variable @text for raw text.
|
104
|
+
# Otherwise the footnotes in the text will be pre-processed and
|
105
|
+
# ghost footnotes will be inserted (as of asciidoctor 2.0.10).
|
106
|
+
line = block.instance_variable_get(:@text)
|
107
|
+
unless line.nil? || line.empty?
|
108
|
+
processor.process_citation_macros line
|
109
|
+
end
|
110
|
+
elsif block.content_model == :simple
|
101
111
|
block.lines.each do |line|
|
102
112
|
processor.process_citation_macros line
|
103
113
|
end
|
114
|
+
else
|
115
|
+
line = block.instance_variable_get(:@title)
|
116
|
+
processor.process_citation_macros line
|
104
117
|
end
|
105
118
|
end
|
106
119
|
# Make processor finalize macro processing as required.
|
@@ -109,14 +122,25 @@ module AsciidoctorBibtex
|
|
109
122
|
# Second pass: replace citations with citation texts.
|
110
123
|
prose_blocks.each do |block|
|
111
124
|
if block.context == :list_item || block.context == :table_cell
|
112
|
-
|
113
|
-
line =
|
114
|
-
|
115
|
-
|
125
|
+
# NOTE: we access the instance variable @text for raw text.
|
126
|
+
line = block.instance_variable_get(:@text)
|
127
|
+
unless line.nil? or line.empty?
|
128
|
+
line = processor.replace_citation_macros(line)
|
129
|
+
line = processor.replace_bibitem_macros(line)
|
130
|
+
block.text = line
|
131
|
+
end
|
132
|
+
elsif block.content_model == :simple
|
116
133
|
block.lines.each_with_index do |line, index|
|
117
134
|
line = processor.replace_citation_macros(line)
|
135
|
+
line = processor.replace_bibitem_macros(line)
|
118
136
|
block.lines[index] = line
|
119
137
|
end
|
138
|
+
else
|
139
|
+
# NOTE: we access the instance variable @text for raw text.
|
140
|
+
line = block.instance_variable_get(:@title)
|
141
|
+
line = processor.replace_citation_macros(line)
|
142
|
+
line = processor.replace_bibitem_macros(line)
|
143
|
+
block.title = line
|
120
144
|
end
|
121
145
|
end
|
122
146
|
|
File without changes
|
@@ -16,10 +16,11 @@ require 'latex/decode/symbols'
|
|
16
16
|
require 'latex/decode/greek'
|
17
17
|
require 'set'
|
18
18
|
|
19
|
-
require_relative '
|
20
|
-
require_relative '
|
21
|
-
require_relative '
|
22
|
-
require_relative '
|
19
|
+
require_relative 'citation_macro'
|
20
|
+
require_relative 'citation_utils'
|
21
|
+
require_relative 'bibitem_macro'
|
22
|
+
require_relative 'string_utils'
|
23
|
+
require_relative 'style_utils'
|
23
24
|
|
24
25
|
module AsciidoctorBibtex
|
25
26
|
# This filter extends the original latex filter in bibtex-ruby to handle
|
@@ -49,7 +50,7 @@ module AsciidoctorBibtex
|
|
49
50
|
class Processor
|
50
51
|
def initialize(bibfile, links = false, style = 'ieee', locale = 'en-US',
|
51
52
|
numeric_in_appearance_order = false, output = :asciidoc,
|
52
|
-
throw_on_unknown = false)
|
53
|
+
throw_on_unknown = false, custom_citation_template: '[$id]')
|
53
54
|
raise "File '#{bibfile}' is not found" unless FileTest.file? bibfile
|
54
55
|
|
55
56
|
bibtex = BibTeX.open bibfile, filter: [LatexFilter]
|
@@ -62,6 +63,13 @@ module AsciidoctorBibtex
|
|
62
63
|
@filenames = Set.new
|
63
64
|
@output = output
|
64
65
|
@throw_on_unknown = throw_on_unknown
|
66
|
+
@bibtex_ob = '['
|
67
|
+
@bibtex_cb = ']'
|
68
|
+
match = custom_citation_template.match(/^(.+?)\$id(.+)$/)
|
69
|
+
unless match.nil?
|
70
|
+
@bibtex_ob = match[1]
|
71
|
+
@bibtex_cb = match[2]
|
72
|
+
end
|
65
73
|
|
66
74
|
if (output != :latex) && (output != :bibtex) && (output != :biblatex)
|
67
75
|
@citeproc = CiteProc::Processor.new style: @style, format: :html, locale: @locale
|
@@ -75,7 +83,7 @@ module AsciidoctorBibtex
|
|
75
83
|
# processor will build a list of all citation keys in the same order as they
|
76
84
|
# appear in the original document.
|
77
85
|
def process_citation_macros(line)
|
78
|
-
CitationMacro.
|
86
|
+
CitationMacro.extract_macros(line).each do |citation|
|
79
87
|
@citations += citation.items.collect(&:key)
|
80
88
|
end
|
81
89
|
end
|
@@ -97,7 +105,10 @@ module AsciidoctorBibtex
|
|
97
105
|
# Remove { } from grouped names for sorting.
|
98
106
|
author = bibitem.author
|
99
107
|
author = bibitem.editor if author.nil?
|
100
|
-
|
108
|
+
year = bibitem.year
|
109
|
+
sortable = CitationUtils.author_chicago(author).map { |s| s.upcase.delete '{}' }
|
110
|
+
sortable << year if year
|
111
|
+
sortable
|
101
112
|
end
|
102
113
|
end
|
103
114
|
nil
|
@@ -107,19 +118,29 @@ module AsciidoctorBibtex
|
|
107
118
|
#
|
108
119
|
# Return new text with all macros replaced.
|
109
120
|
def replace_citation_macros(line)
|
110
|
-
CitationMacro.
|
121
|
+
CitationMacro.extract_macros(line).each do |citation|
|
111
122
|
line = line.gsub(citation.text, build_citation_text(citation))
|
112
123
|
end
|
113
124
|
line
|
114
125
|
end
|
115
126
|
|
127
|
+
# Replace bibitem macros with rendered bibitem.
|
128
|
+
#
|
129
|
+
# Return new text with all macros replaced.
|
130
|
+
def replace_bibitem_macros(line)
|
131
|
+
BibitemMacro.extract_macros(line).each do |item|
|
132
|
+
line = line.gsub(item.text, build_bibitem_text(item.key))
|
133
|
+
end
|
134
|
+
line
|
135
|
+
end
|
136
|
+
|
116
137
|
# Build the bibliography list just as bibtex.
|
117
138
|
#
|
118
139
|
# Return an array of texts representing an asciidoc list.
|
119
140
|
def build_bibliography_list
|
120
141
|
result = []
|
121
|
-
@citations.
|
122
|
-
result << build_bibliography_item(ref)
|
142
|
+
@citations.each_with_index do |ref, index|
|
143
|
+
result << build_bibliography_item(ref, index)
|
123
144
|
result << ''
|
124
145
|
end
|
125
146
|
result
|
@@ -129,17 +150,42 @@ module AsciidoctorBibtex
|
|
129
150
|
# Internal functions
|
130
151
|
#
|
131
152
|
|
153
|
+
# Build the asciidoc text for a single bibliography item
|
154
|
+
def build_bibitem_text(key)
|
155
|
+
begin
|
156
|
+
if @biblio[key].nil?
|
157
|
+
puts "Unknown reference: #{key}"
|
158
|
+
cptext = key
|
159
|
+
else
|
160
|
+
cptext = @citeproc.render :bibliography, id: key
|
161
|
+
cptext = cptext.first
|
162
|
+
end
|
163
|
+
rescue Exception => e
|
164
|
+
puts "Failed to render #{key}: #{e}"
|
165
|
+
cptext = key
|
166
|
+
end
|
167
|
+
StringUtils.html_to_asciidoc(cptext)
|
168
|
+
end
|
169
|
+
|
132
170
|
# Build bibliography text for a given reference
|
133
|
-
def build_bibliography_item(key)
|
171
|
+
def build_bibliography_item(key, index = 0)
|
172
|
+
index += 1
|
134
173
|
result = ''
|
135
|
-
result << '. ' if StyleUtils.is_numeric? @style
|
136
174
|
|
137
175
|
begin
|
138
|
-
cptext = @
|
176
|
+
cptext = if @biblio[key].nil?
|
177
|
+
nil
|
178
|
+
else
|
179
|
+
@citeproc.render :bibliography, id: key
|
180
|
+
end
|
139
181
|
rescue Exception => e
|
140
182
|
puts "Failed to render #{key}: #{e}"
|
141
183
|
end
|
184
|
+
|
142
185
|
result << "[[#{key}]]" if @links
|
186
|
+
if StyleUtils.is_numeric? @style
|
187
|
+
result << "#{@bibtex_ob}#{index}#{@bibtex_cb} "
|
188
|
+
end
|
143
189
|
if cptext.nil?
|
144
190
|
return result + key
|
145
191
|
else
|
@@ -174,8 +220,8 @@ module AsciidoctorBibtex
|
|
174
220
|
else
|
175
221
|
result = ''
|
176
222
|
if StyleUtils.is_numeric? @style
|
177
|
-
ob =
|
178
|
-
cb =
|
223
|
+
ob = "+#{@bibtex_ob}+"
|
224
|
+
cb = "+#{@bibtex_cb}+"
|
179
225
|
separator = ','
|
180
226
|
elsif macro.type == 'cite'
|
181
227
|
ob = '('
|
@@ -197,14 +243,14 @@ module AsciidoctorBibtex
|
|
197
243
|
# if found, insert reference information
|
198
244
|
if @biblio[cite.key].nil?
|
199
245
|
if @throw_on_unknown
|
200
|
-
raise "Unknown reference: #{cite.
|
246
|
+
raise "Unknown reference: #{cite.key}"
|
201
247
|
else
|
202
|
-
puts "Unknown reference: #{cite.
|
203
|
-
cite_text = cite.
|
248
|
+
puts "Unknown reference: #{cite.key}"
|
249
|
+
cite_text = cite.key.to_s
|
204
250
|
end
|
205
251
|
else
|
206
252
|
cite_text = citation_text(macro, cite)
|
207
|
-
|
253
|
+
end
|
208
254
|
|
209
255
|
result << StringUtils.html_to_asciidoc(cite_text)
|
210
256
|
result << '>>' if @links
|
@@ -226,13 +272,13 @@ module AsciidoctorBibtex
|
|
226
272
|
result << ' '
|
227
273
|
# use p.x for single numerical page and pp.x for all others. This will
|
228
274
|
# produce pp. 1 seq for complex locators, which is the correct behavior.
|
229
|
-
if @style.include? 'chicago'
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
275
|
+
result << if @style.include? 'chicago'
|
276
|
+
cite.locator
|
277
|
+
elsif /^\d+$/ =~ cite.locator
|
278
|
+
"p. #{cite.locator}"
|
279
|
+
else
|
280
|
+
"pp. #{cite.locator}"
|
281
|
+
end
|
236
282
|
end
|
237
283
|
|
238
284
|
result
|
@@ -263,7 +309,7 @@ module AsciidoctorBibtex
|
|
263
309
|
cite_text = @citeproc.render :citation, id: cite.key
|
264
310
|
cite_text = cite_text.gsub('(', '')
|
265
311
|
cite_text = cite_text.gsub(')', '')
|
266
|
-
cite_text
|
312
|
+
cite_text += format_locator(cite)
|
267
313
|
year = @biblio[cite.key].year
|
268
314
|
if !year.nil? && macro.type == 'citenp'
|
269
315
|
segs = cite_text.partition(year.to_s)
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,49 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-bibtex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zhang YANG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0.0
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: '2.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2.0.0
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
26
|
+
version: '2.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: bibtex-ruby
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
33
|
+
version: '5.1'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
40
|
+
version: '5.1'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: citeproc-ruby
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,63 +86,50 @@ dependencies:
|
|
92
86
|
requirements:
|
93
87
|
- - "~>"
|
94
88
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '5'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: bundler
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '2'
|
89
|
+
version: 5.11.0
|
110
90
|
type: :development
|
111
91
|
prerelease: false
|
112
92
|
version_requirements: !ruby/object:Gem::Requirement
|
113
93
|
requirements:
|
114
94
|
- - "~>"
|
115
95
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
96
|
+
version: 5.11.0
|
117
97
|
- !ruby/object:Gem::Dependency
|
118
98
|
name: rake
|
119
99
|
requirement: !ruby/object:Gem::Requirement
|
120
100
|
requirements:
|
121
101
|
- - "~>"
|
122
102
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
103
|
+
version: 12.3.0
|
124
104
|
type: :development
|
125
105
|
prerelease: false
|
126
106
|
version_requirements: !ruby/object:Gem::Requirement
|
127
107
|
requirements:
|
128
108
|
- - "~>"
|
129
109
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
131
|
-
description:
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
110
|
+
version: 12.3.0
|
111
|
+
description: 'asciidoctor-bibtex is an Asciidocotor extension that adds bibtex support
|
112
|
+
for AsciiDoc documents. It does so by introducing two new macros: `cite:[KEY]` and
|
113
|
+
`bibliography::[]`. Citations are parsed and replaced with formatted inline text,
|
114
|
+
and reference lists are automatically generated and inserted where the `bibliography::[]`
|
115
|
+
macro is placed. The references are formatted using styles provided by CSL.'
|
116
|
+
email:
|
117
|
+
- zyangmath@gmail.com
|
138
118
|
executables: []
|
139
119
|
extensions: []
|
140
120
|
extra_rdoc_files: []
|
141
121
|
files:
|
142
122
|
- LICENSE.txt
|
143
|
-
- README.
|
123
|
+
- README.adoc
|
144
124
|
- lib/asciidoctor-bibtex.rb
|
145
|
-
- lib/asciidoctor-bibtex/
|
146
|
-
- lib/asciidoctor-bibtex/
|
147
|
-
- lib/asciidoctor-bibtex/
|
148
|
-
- lib/asciidoctor-bibtex/Processor.rb
|
149
|
-
- lib/asciidoctor-bibtex/StringUtils.rb
|
150
|
-
- lib/asciidoctor-bibtex/StyleUtils.rb
|
125
|
+
- lib/asciidoctor-bibtex/bibitem_macro.rb
|
126
|
+
- lib/asciidoctor-bibtex/citation_macro.rb
|
127
|
+
- lib/asciidoctor-bibtex/citation_utils.rb
|
151
128
|
- lib/asciidoctor-bibtex/extensions.rb
|
129
|
+
- lib/asciidoctor-bibtex/path_utils.rb
|
130
|
+
- lib/asciidoctor-bibtex/processor.rb
|
131
|
+
- lib/asciidoctor-bibtex/string_utils.rb
|
132
|
+
- lib/asciidoctor-bibtex/style_utils.rb
|
152
133
|
- lib/asciidoctor-bibtex/version.rb
|
153
134
|
homepage: https://github.com/asciidoctor/asciidoctor-bibtex
|
154
135
|
licenses:
|
@@ -160,17 +141,17 @@ require_paths:
|
|
160
141
|
- lib
|
161
142
|
required_ruby_version: !ruby/object:Gem::Requirement
|
162
143
|
requirements:
|
163
|
-
- - "
|
144
|
+
- - ">="
|
164
145
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
146
|
+
version: 2.4.0
|
166
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
148
|
requirements:
|
168
149
|
- - ">="
|
169
150
|
- !ruby/object:Gem::Version
|
170
151
|
version: '0'
|
171
152
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
153
|
+
rubygems_version: 3.1.2
|
173
154
|
signing_key:
|
174
155
|
specification_version: 4
|
175
|
-
summary:
|
156
|
+
summary: An Asciidoctor extension that adds bibtex integration to AsciiDoc
|
176
157
|
test_files: []
|
data/README.md
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
# asciidoctor-bibtex: add bibtex functionality to asciidoc
|
2
|
-
|
3
|
-
asciidoctor-bibtex adds bibtex support for asciidoc documents by introducing
|
4
|
-
two new macros: `cite:[KEY]` and `bibliography::[]`. Citations are parsed and
|
5
|
-
replaced with formatted inline texts, and reference lists are automatically
|
6
|
-
generated and inserted into where `bibliography::[]` is placed.
|
7
|
-
|
8
|
-
asciidoctor-bibtex is designed to be used as an extension to
|
9
|
-
[asciidoctor](http://asciidoctor.org). Thus this extension can be used
|
10
|
-
together with other asciidoctor extensions such as
|
11
|
-
[asciidoctor-mathematical][] and [asciidoctor-pdf][] to enrich your
|
12
|
-
asciidoc experience. Note that asciidoctor-bibtex no longer support asciidoc-to-asciidoc conversion.
|
13
|
-
|
14
|
-
[asciidoctor-mathematical]: https://github.com/asciidoctor/asciidoctor-mathematical
|
15
|
-
[asciidoctor-pdf]: https://github.com/asciidoctor/asciidoctor-pdf
|
16
|
-
|
17
|
-
## History
|
18
|
-
|
19
|
-
asciidoctor-bibtex starts as a fork of [asciidoc-bib][] and goes along a
|
20
|
-
different way. The major reason for the fork at the time was the differences in
|
21
|
-
citation and bibliography macros. asciidoc-bib failed to follow the grammar of
|
22
|
-
macros in asciidoc, thus to avoid breaking existing documents, a fork is
|
23
|
-
inevitable. Other reasons include the inability to use asciidoctor arguments
|
24
|
-
in asciidoc-bib.
|
25
|
-
|
26
|
-
While [asciidoc-bib][] focuses on replacing citations in the original
|
27
|
-
documents and produces new asciidoc documents, asciidoctor-bibtex focuses on
|
28
|
-
compatibility with asciidoctor and other asciidoctor extensions at the very
|
29
|
-
beginning. As time passes, asciidoctor-bibtex diverges significantly from its
|
30
|
-
ancesstor. For example, asciidoctor-bibtex now supports generating real bibtex
|
31
|
-
citations and bibliography, so it can be used together with
|
32
|
-
[asciidoctor-latex][] for native bibtex support.
|
33
|
-
|
34
|
-
[asciidoc-bib]: https://github.com/petercrlane/asciidoc-bib
|
35
|
-
[asciidoctor-latex]: https://github.com/asciidoctor/asciidoctor-latex
|
36
|
-
|
37
|
-
## Install
|
38
|
-
|
39
|
-
gem install asciidoctor-bibtex
|
40
|
-
|
41
|
-
asciidoctor-bibtex depends on
|
42
|
-
[bibtex-ruby](http://github.com/inukshuk/bibtex-ruby),
|
43
|
-
[citeproc-ruby](http://github.com/inukshuk/citeproc-ruby) and
|
44
|
-
[csl-styles](http://github.com/inukshuk/csl-styles). (Ensure 'ruby-dev' and
|
45
|
-
'libxslt1-dev' are installed, so the dependencies will compile.)
|
46
|
-
|
47
|
-
[asciidoctor](https://github.com/asciidoctor/asciidoctor) must also be
|
48
|
-
installed for 'asciidoctor-bibtex' to work. asciidoctor version 1.5.2 or
|
49
|
-
higher is required.
|
50
|
-
|
51
|
-
## Usage
|
52
|
-
|
53
|
-
### Macros
|
54
|
-
|
55
|
-
Syntax for inserting a citation is the following inline macro:
|
56
|
-
|
57
|
-
cite|citenp:[ref(pages), ...]
|
58
|
-
|
59
|
-
where '(pages)' is optional.
|
60
|
-
|
61
|
-
Examples of "chicago-author-date" style:
|
62
|
-
|
63
|
-
- `cite:[Lane12]` becomes "(Lane 2012)"
|
64
|
-
- `citenp:[Lane12]` becomes "Lane (2012)"
|
65
|
-
- `cite:[Lane12(59)]` becomes "(Lane 2012, 59)"
|
66
|
-
|
67
|
-
For *apa* (Harvard-like) style:
|
68
|
-
|
69
|
-
- `cite:[Lane12]` becomes "(Lane, 2012)"
|
70
|
-
- `citenp:[Lane12]` becomes "Lane (2012)"
|
71
|
-
- `cite:[Lane12(59)]` becomes "(Lane, 2012, p.59)"
|
72
|
-
|
73
|
-
For *ieee*, a numeric style:
|
74
|
-
|
75
|
-
`cite:[Lane12,Lane11]` becomes "[1, 2]"
|
76
|
-
|
77
|
-
To add a list of formatted references, place `bibliography::[]` on a line by itself.
|
78
|
-
|
79
|
-
### Document Attributes
|
80
|
-
|
81
|
-
| Attribute Name | Description | Valid Values | Default Value |
|
82
|
-
| -------------- | --------------- | ---------- | -------------- |
|
83
|
-
| bibtex-file | Bibtex database file | any string, or empty | Automatic searching |
|
84
|
-
| bibtex-style | Reference formatting style | any style supported by csl-styles | ieee |
|
85
|
-
| bibtex-order | Order of citations | `appearance` or `alphabetical` | `appearance` |
|
86
|
-
| bibtex-format | Formatting of citations and bibliography | `asciidoc`, `bibtex` or `biblatex` | `asciidoc` |
|
87
|
-
| bibtex-throw | Throw an error on unknown references | `true` or `false` | `false` |
|
88
|
-
|
89
|
-
### Commandline
|
90
|
-
|
91
|
-
Use asciidoctor-bibtex as an extension:
|
92
|
-
|
93
|
-
```bash
|
94
|
-
asciidoctor -r asciidoctor-bibtex sample.adoc
|
95
|
-
```
|
96
|
-
|
97
|
-
## License
|
98
|
-
|
99
|
-
The files within this project may be distributed under the terms of
|
100
|
-
the Open Works License: http://owl.apotheon.org
|
101
|
-
|
102
|
-
## Links
|
103
|
-
|
104
|
-
See https://github.com/petercrlane/asciidoc-bib for the original asciidoc-bib.
|