asciidoctor-bibtex 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: b1b51427daaa173649801301b8eec0d06c9d1f33
4
- data.tar.gz: 77424fb797d99b1f89f43b0f2f0120c62f9eb6fa
3
+ metadata.gz: 6579c1fb777b43c77a5775daecbe08f124569428
4
+ data.tar.gz: ef2332508bbc439949a2e8249e6b2be2bfac73ce
5
5
  SHA512:
6
- metadata.gz: eb4354f3d0bb64ca209c47734697c82a57e5284f943b2c6d3187b873a8346532eed91c33746bc08375bd86ac699a8e549aa6c816b8f8cb841404bbb00417be94
7
- data.tar.gz: c21d7fda35a0fa9f5b941efe31684d814403fc5c2df434cd2d01e34abf48e1e4e050fd37625ab9aa09b60916cf605faab1a8f2375ae159d32f66287873435a0f
6
+ metadata.gz: c18f02a2bd15df1c55893619e7c2638c81d04838a582584f52425b8d321fd315e3920054cefaf9de942e5e7ea95d0cdf97211755731823023dc098ea0e00f0ba
7
+ data.tar.gz: 339b8c609873013971dbe03d7fb93d8cb729bb4a753f632f53172b9e2ca7a656bbac684cdefd774f4d47cf5f34f52dd14239a472f8f01ee6f894c7841ea2ffac
data/README.md CHANGED
@@ -1,122 +1,98 @@
1
1
  # asciidoctor-bibtex: add bibtex functionality to asciidoc
2
2
 
3
- asciidoctor-bibtex is a fork of [asciidoc-bib](https://github.com/petercrlane/asciidoc-bib) It generates in-text references and a reference list for an asciidoc file, using a bibtex file as a source of citation information. However, asciidoctor-bibtex proposes a different citation and reference grammar, which resembles the bibtex grammar in LaTeX. The grammar follows asciidoc inline and block macro semantics.
4
-
5
- ## Why a fork
6
-
7
- When I began switching from latex/word to asciidoc, I searched for an easy way to integrate bibtex like references into asciidoc. Then I came across asciidoc-bib, which nearly meet my needs. I can insert citations, generate automatically a complete reference list. But there are aspects in asciidoc-bib that are not pleasing to work with.
8
-
9
- The first is the overriding of `[bibliography]`. Asciidoctor introduces `[xxx]` as an mechanism to customize block styles, roles, etc. `[bibliography]` is reserved for the bibliography section style. asciidoc-bib breaks it and there is no apparent way to fix it.
10
-
11
- The second is the grammar inconsistency with the rest of asciidoc. The `[cite:xxx]` is actually an inline macro but it does not follow the grammar of inline macros. This makes asciidoc-bib not that confortable to write with since it breaks the semantic memory.
12
-
13
- The last is asciidoc-bib does not support asciidoctor arguments and extensions. So I can not use asciidoctor-pdf with it.
14
-
15
- To accommodate the above problems, I create this fork. This fork tries to be as consistent with asciidoctor as possible.
16
-
17
- ## Features
18
-
19
- - bibtex-like syntax for adding a citation within text and placing bibliography
20
- - formatting of references and reference list according to range of styles supported by citeproc-ruby
21
- - supports some styling of citation text (page numbers, bracket placement)
22
- - can be used as an asciidoctor extension
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), although it supports asciidoc to
10
+ asciidoc transformation at the moment. Thus this extension can be used
11
+ together with other asciidoctor extensions such as
12
+ [asciidoctor-mathematical][] and [asciidoctor-pdf][] to enrich your
13
+ asciidoc experience.
14
+
15
+ [asciidoctor-mathematical]: https://github.com/asciidoctor/asciidoctor-mathematical
16
+ [asciidoctor-pdf]: https://github.com/asciidoctor/asciidoctor-pdf
17
+
18
+ ## History
19
+
20
+ asciidoctor-bibtex starts as a fork of [asciidoc-bib][] and goes along a
21
+ different way. The major reason for the fork at the time was the differences in
22
+ citation and bibliography macros. asciidoc-bib failed to follow the grammar of
23
+ macros in asciidoc, thus to avoid breaking existing documents, a fork is
24
+ inevitable. Other reasons include the inability to use asciidoctor arguments
25
+ in asciidoc-bib.
26
+
27
+ While [asciidoc-bib][] focuses on replacing citations in the original
28
+ documents and produces new asciidoc documents, asciidoctor-bibtex focuses on
29
+ compatibility with asciidoctor and other asciidoctor extensions at the very
30
+ beginning. As time passes, asciidoctor-bibtex diverges significantly from its
31
+ ancesstor. For example, asciidoctor-bibtex now supports generating real bibtex
32
+ ciations and bibliography, so it can be used together with
33
+ [asciidoctor-latex][] for native bibtex support.
34
+
35
+ [asciidoc-bib]: https://github.com/petercrlane/asciidoc-bib
36
+ [asciidoctor-latex]: https://github.com/asciidoctor/asciidoctor-latex
23
37
 
24
38
  ## Install
25
39
 
26
40
  gem install asciidoctor-bibtex
27
41
 
28
- Installs two executable programs:
42
+ asciidoctor-bibtex depends on
43
+ [bibtex-ruby](http://github.com/inukshuk/bibtex-ruby),
44
+ [citeproc-ruby](http://github.com/inukshuk/citeproc-ruby) and
45
+ [csl-styles](http://github.com/inukshuk/csl-styles). (Ensure 'ruby-dev' and
46
+ 'libxslt1-dev' are installed, so the dependencies will compile.)
29
47
 
30
- - 'asciidoc-bibtex' for transforming source text into asciidoc
31
- - 'asciidoctor-bibtex' uses asciidoctor extension for single-pass output
32
-
33
- asciidoctor-bibtex depends on [bibtex-ruby](http://github.com/inukshuk/bibtex-ruby), [citeproc-ruby](http://github.com/inukshuk/citeproc-ruby) and [csl-styles](http://github.com/inukshuk/csl-styles). (Ensure 'ruby-dev' and 'libxslt1-dev' are installed, so the dependencies will compile.)
34
-
35
- [asciidoctor](https://github.com/asciidoctor/asciidoctor) must also be installed for 'asciidoctor-bibtex' to work. asciidoctor version 1.5.2 or higher is required.
48
+ [asciidoctor](https://github.com/asciidoctor/asciidoctor) must also be
49
+ installed for 'asciidoctor-bibtex' to work. asciidoctor version 1.5.2 or
50
+ higher is required.
36
51
 
37
52
  ## Usage
38
53
 
39
- There are three ways of using asciidoctor-bibtex.
40
-
41
- The first is required if using _asciidoc_. 'asciidoc-bibtex' works by transforming an asciidoc document containing syntax to include citations and a bibliography. The transformed document will contain a complete reference and bibliography list where indicated, and can then be processed further by asciidoc's toolchain to produce a completed document.
42
-
43
- The second is to use 'asciidoctor-bibtex' to transform your bibtex-enabled documents directly to any backend format supported by asciidoctor. It uses the asciidoctor extension mechanism to hook in the asciidoctor preprocessing process. It support all asciidoctor command-line options.
44
-
45
- The third is to use asciidoctor-bibtex as an asciidoctor extension. It works the same way as the second approach. In addition, one can use other extensions together to provides even richer functionality.
46
-
47
- Styles must be one of those supported by CSL: https://github.com/citation-style-language/styles
48
-
49
- ### Citation syntax
54
+ ### Macros
50
55
 
51
56
  Syntax for inserting a citation is the following inline macro:
52
57
 
53
- cite|citenp:[ref(pages)]
58
+ cite|citenp:[ref(pages), ...]
54
59
 
55
- where '(pages)' is optional. The ref and optional pages may be repeated multiple times, separated by ','. A citation _must_ be complete on a single line of text.
60
+ where '(pages)' is optional.
56
61
 
57
62
  Examples of "chicago-author-date" style:
58
63
 
59
- `cite:[Lane12]` becomes "(Lane 2012)"
60
-
61
- `citenp:[Lane12]` becomes "Lane (2012)"
62
-
63
- `cite:[Lane12(59)]` becomes "(Lane 2012, 59)"
64
+ - `cite:[Lane12]` becomes "(Lane 2012)"
65
+ - `citenp:[Lane12]` becomes "Lane (2012)"
66
+ - `cite:[Lane12(59)]` becomes "(Lane 2012, 59)"
64
67
 
65
68
  For *apa* (Harvard-like) style:
66
69
 
67
- `cite:[Lane12]` becomes "(Lane, 2012)"
68
-
69
- `citenp:[Lane12]` becomes "Lane (2012)"
70
-
71
- `cite:[Lane12(59)]` becomes "(Lane, 2012, p.59)"
70
+ - `cite:[Lane12]` becomes "(Lane, 2012)"
71
+ - `citenp:[Lane12]` becomes "Lane (2012)"
72
+ - `cite:[Lane12(59)]` becomes "(Lane, 2012, p.59)"
72
73
 
73
74
  For *ieee*, a numeric style:
74
75
 
75
76
  `cite:[Lane12,Lane11]` becomes "[1, 2]"
76
77
 
77
- ### Place bibliography in text
78
-
79
- `bibliography::[]` on a line by itself.
80
-
81
- ### Processing Text: Asciidoctor
82
-
83
- asciidoctor-bibtex [OPTIONS] filename
84
-
85
- Looks for a bib file in current folder and in ~/Documents.
86
-
87
- Outputs an html file, including all citations and references.
88
-
89
- asciidoctor-bibtex support all command-line options of asciidoctor, for example, use the follow command to output docbook file:
90
-
91
- asciidoctor-bibtex -b docbook filename
92
-
93
- One may also use as an asciidoctor extension, for example:
94
-
95
- asciidoctor -r asciidoctor-bibtex -r asciidoctor-pdf -b pdf filename
96
-
97
- Options are set through the command-line using the asciidoctor attributes
98
- setting syntax:
99
-
100
- > asciidoctor-bibtex -h
101
-
102
- ...
103
- AsciidoctorBibtex related options:
104
-
105
- -a bib-file=FILENAME Set BibTex filename (default: auto-find)
106
- -a bib-style=STYLE Set BibTex items style (default: apa)
107
- -a bib-numeric-order=<alphabetical|appearance>
108
- Set citation order scheme (default: alphabetical)
109
- -a bib-no-links=1 Do not use links (default: use links)
78
+ To add a list of formatted references, place `bibliography::[]` on a line by itself.
110
79
 
111
- ### Processing text: Asciidoc
80
+ ### Document Attributes
112
81
 
113
- asciidoc-bibtex filename.txt
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 `latex` | `asciidoc` |
114
88
 
115
- Looks for a bib file in current folder and in ~/Documents.
89
+ ### Commandline
116
90
 
117
- Outputs a new file: filename-ref.txt which includes your references.
91
+ Use asciidoctor-bibtex as an extension:
118
92
 
119
- asciidoc-bibtex supports the same command-line options as asciidoc-bib. The only difference is the citation and bibliography syntex.
93
+ ```bash
94
+ asciidoctor -r asciidoctor-bibtex sample.adoc
95
+ ```
120
96
 
121
97
  ## License
122
98
 
@@ -8,17 +8,13 @@ require 'citeproc'
8
8
  require 'csl/styles'
9
9
  require 'set'
10
10
 
11
- # Only require asciidoctor file if asciidoctor gem is installed
12
- unless Gem::Specification.find_all_by_name('asciidoctor').empty?
13
- require_relative 'asciidoctor-bibtex/asciidoctor'
14
- end
11
+ require_relative 'asciidoctor-bibtex/asciidoctor'
15
12
  require_relative 'asciidoctor-bibtex/citation'
16
13
  require_relative 'asciidoctor-bibtex/citationdata'
17
14
  require_relative 'asciidoctor-bibtex/citationutils'
18
15
  require_relative 'asciidoctor-bibtex/citations'
19
16
  require_relative 'asciidoctor-bibtex/extensions'
20
17
  require_relative 'asciidoctor-bibtex/filehandlers'
21
- require_relative 'asciidoctor-bibtex/options'
22
18
  require_relative 'asciidoctor-bibtex/processorutils'
23
19
  require_relative 'asciidoctor-bibtex/processor'
24
20
  require_relative 'asciidoctor-bibtex/styles'
@@ -6,11 +6,43 @@ require 'asciidoctor'
6
6
  require 'asciidoctor/extensions'
7
7
  require 'asciidoctor/reader'
8
8
  require 'asciidoctor/parser'
9
+ require 'bibtex/filters'
10
+ require 'latex/decode/base'
11
+ require 'latex/decode/maths'
12
+ require 'latex/decode/accents'
13
+ require 'latex/decode/diacritics'
14
+ require 'latex/decode/punctuation'
15
+ require 'latex/decode/symbols'
16
+ require 'latex/decode/greek'
9
17
  require_relative 'styles'
10
18
  require_relative 'filehandlers'
11
19
 
12
20
  module AsciidoctorBibtex
13
21
  module Asciidoctor
22
+
23
+ # This filter extends the original latex filter in bibtex-ruby to handle
24
+ # unknown latex macros more gracefully. We could have used latex-decode
25
+ # gem together with our custom replacement rules, but latex-decode eats up
26
+ # all braces after it finishes all decoding. So we hack over the
27
+ # LaTeX.decode function and insert our rules before `strip_braces`.
28
+ class LatexFilter < ::BibTeX::Filter
29
+ def apply(value)
30
+ text = value.to_s
31
+ LaTeX::Decode::Base.normalize(text)
32
+ LaTeX::Decode::Maths.decode!(text)
33
+ LaTeX::Decode::Accents.decode!(text)
34
+ LaTeX::Decode::Diacritics.decode!(text)
35
+ LaTeX::Decode::Punctuation.decode!(text)
36
+ LaTeX::Decode::Symbols.decode!(text)
37
+ LaTeX::Decode::Greek.decode!(text)
38
+ text.gsub!(/\\url\{(.+?)\}/, " \\1 ")
39
+ text.gsub!(/\\\w+(?=\s+\w)/, "")
40
+ text.gsub!(/\\\w+(?:\[.+?\])?\s*\{(.+?)\}/, "\\1")
41
+ LaTeX::Decode::Base.strip_braces(text)
42
+ LaTeX.normalize_C(text)
43
+ end
44
+ end
45
+
14
46
  BibliographyBlockMacroPlaceholder = %(BIBLIOGRAPHY BLOCK MACRO PLACEHOLDER)
15
47
 
16
48
  # This macro processor does only half the work. It just parse the macro
@@ -45,8 +77,8 @@ module AsciidoctorBibtex
45
77
  def process document
46
78
  bibtex_file = (document.attr 'bibtex-file').to_s
47
79
  bibtex_style = ((document.attr 'bibtex-style') || 'ieee').to_s
48
- bibtex_order = ((document.attr 'bibtex-order') || 'alphabetical').to_sym
49
- bibtex_output = ((document.attr 'bibtex-output') || 'asciidoc').to_sym
80
+ bibtex_order = ((document.attr 'bibtex-order') || 'appearance').to_sym
81
+ bibtex_format = ((document.attr 'bibtex-format') || 'asciidoc').to_sym
50
82
 
51
83
  if bibtex_file.empty?
52
84
  bibtex_file = AsciidoctorBibtex::FileHandlers.find_bibliography "."
@@ -59,8 +91,8 @@ module AsciidoctorBibtex
59
91
  exit
60
92
  end
61
93
 
62
- bibtex = BibTeX.open bibtex_file
63
- processor = Processor.new bibtex, true, bibtex_style, bibtex_order == :appearance, bibtex_output
94
+ bibtex = BibTeX.open bibtex_file, :filter => [LatexFilter]
95
+ processor = Processor.new bibtex, true, bibtex_style, bibtex_order == :appearance, bibtex_format
64
96
 
65
97
  prose_blocks = document.find_by {|b| b.content_model == :simple or b.context == :list_item}
66
98
  prose_blocks.each do |block|
@@ -91,7 +123,7 @@ module AsciidoctorBibtex
91
123
  end
92
124
 
93
125
  references_asciidoc = []
94
- if bibtex_output == :latex
126
+ if bibtex_format == :latex
95
127
  references_asciidoc << %(+++\\bibliography{#{bibtex_file}}{}+++)
96
128
  references_asciidoc << %(+++\\bibliographystyle{#{bibtex_style}}+++)
97
129
  else
@@ -55,7 +55,7 @@ module AsciidoctorBibtex
55
55
  end
56
56
 
57
57
  # matches a citation key, such as 'Dan2012(99-100)'
58
- CITATION_KEY = /(\w+)(\(\d+(-\d+)*\))?/
58
+ CITATION_KEY = /([^\s,()\[\]]+)(\(\d+(-\d+)*\))?/
59
59
  # matches a citation type
60
60
  CITATION_TYPE = /cite|citenp/
61
61
  # matches a citation list
@@ -11,14 +11,6 @@ module AsciidoctorBibtex
11
11
  class Processor
12
12
  include ProcessorUtils
13
13
 
14
- # Top-level method to include citations in given asciidoc file
15
- def Processor.run options
16
- processor = Processor.new BibTeX.open(options.bibfile), options.links, options.style, options.numeric_in_appearance_order?, options.output, options.bibfile
17
- processor.read_filenames options.filename
18
- processor.read_citations
19
- processor.add_citations
20
- end
21
-
22
14
  attr_reader :biblio, :links, :style, :citations
23
15
 
24
16
  def initialize biblio, links, style, numeric_in_appearance_order = false, output = :asciidoc, bibfile = ""
@@ -37,101 +29,6 @@ module AsciidoctorBibtex
37
29
  end
38
30
  end
39
31
 
40
- # Given an asciidoc filename, reads in all dependent files based on 'include::' statements
41
- # Leaving a list of files in @filenames
42
- def read_filenames filename
43
- puts "Reading file: #{filename}"
44
- files_to_process = [filename]
45
-
46
- begin
47
- @filenames.add files_to_process.first
48
- File.new(files_to_process.shift).each_line do |line|
49
- if line.include?("include::")
50
- line.split("include::").drop(1).each do |filetxt|
51
- file = File.expand_path(filetxt.partition(/\s|\[/).first)
52
- files_to_process << file unless @filenames.include?(file)
53
- end
54
- end
55
- end
56
- end until files_to_process.empty?
57
- end
58
-
59
- # Scans each filename and extracts citations
60
- def read_citations
61
- @filenames.each do |file|
62
- IO.foreach(file) do |line|
63
- @citations.add_from_line line
64
- end
65
- end
66
- end
67
-
68
- # Read given text to add cites and biblio to a new file
69
- # Order is always decided by author surname first with year.
70
- # If no author present, then use editor field.
71
- # Links indicates if internal links to be added.
72
- # Assumes @filenames has been set to list of filenames to process.
73
- def add_citations
74
- @filenames.each do |curr_file|
75
- ref_filename = FileHandlers.add_ref(curr_file)
76
- puts "Writing file: #{ref_filename}"
77
- output = File.new(ref_filename, "w")
78
-
79
- IO.foreach(curr_file) do |line|
80
- begin # catch any errors, and ensure the lines of text are written
81
- case
82
- when line.include?('include::')
83
- output_include_line output, line
84
- when (line =~ BIBMACRO_FULL) != nil
85
- output_bibliography output
86
- else
87
- output_cite_completed_line output, line
88
- end
89
- rescue # Any errors, just output the line
90
- output.puts line
91
- end
92
- end
93
-
94
- output.close
95
- end
96
- end
97
-
98
- # Output bibliography to given output
99
- def output_bibliography output
100
- if @output == :asciidoc
101
- cites = if Styles.is_numeric?(@style) and @numeric_in_appearance_order
102
- @citations.cites_used
103
- else
104
- sorted_cites
105
- end
106
- cites.each do |ref|
107
- output.puts get_reference(ref)
108
- output.puts
109
- end
110
- else
111
- output.puts "++\\bibliography{#{@bibfile}}++"
112
- output.puts "++\\bibliographystyle{#{@style}}++"
113
- end
114
- end
115
-
116
- def output_include_line output, line
117
- line.split("include::").drop(1).each do |filetxt|
118
- ifile = filetxt.partition(/\s|\[/).first
119
- file = File.expand_path ifile
120
- # make sure included file points to the -ref version
121
- line.gsub!("include::#{ifile}", "include::#{FileHandlers.add_ref(file)}")
122
- end
123
- output.puts line
124
- end
125
-
126
- # For each citation in given line, expand into complete citation text
127
- # before outputting the line
128
- def output_cite_completed_line output, line
129
- @citations.retrieve_citations(line).each do |citation|
130
- line.gsub!(citation.original, complete_citation(citation))
131
- end
132
- output.puts line
133
- end
134
-
135
32
  # Return the complete citation text for given cite_data
136
33
  def complete_citation cite_data
137
34
 
@@ -300,8 +197,5 @@ module AsciidoctorBibtex
300
197
  end
301
198
  end
302
199
 
303
- BIBMACRO_FULL = /bibliography::(.*?)\[(\w+)?\]/
304
200
  end
305
201
  end
306
-
307
-
@@ -1,3 +1,3 @@
1
1
  module AsciidoctorBibtex
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  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.2.0
4
+ version: 0.3.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: 2016-08-28 00:00:00.000000000 Z
11
+ date: 2017-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bibtex-ruby
@@ -52,26 +52,33 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: latex-decode
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
55
69
  description: |
56
- asciidoctor-bibtex is a fork of asciidoc-bib. It generates in-text references
57
- and reference lists for asciidoc files, using specified bibtex file as
58
- ciatation source. The citation syntax follows asciidoc inline and block macro
59
- idiom and resembles bibtex macros, with `cite:[bibref]` or `citenp:[bibref]`
60
- for in-text citation and `bibliography::[]` for reference list. It can be used
61
- standalone or as an asciidoctor extension. See the README for more examples
62
- and further options. The references are formatted using styles provided by
63
- CSL.
70
+ asciidoctor-bibtex adds bibtex support for asciidoc documents by introducing
71
+ two new macros: `cite:[KEY]` and `bibliography::[]`. Citations are parsed and
72
+ replaced with formatted inline texts, and reference lists are automatically
73
+ generated and inserted into where `bibliography::[]` is placed. The
74
+ references are formatted using styles provided by CSL.
64
75
  email: zyangmath@gmail.com
65
- executables:
66
- - asciidoctor-bibtex
67
- - asciidoc-bibtex
76
+ executables: []
68
77
  extensions: []
69
78
  extra_rdoc_files: []
70
79
  files:
71
80
  - LICENSE.txt
72
81
  - README.md
73
- - bin/asciidoc-bibtex
74
- - bin/asciidoctor-bibtex
75
82
  - lib/asciidoctor-bibtex.rb
76
83
  - lib/asciidoctor-bibtex/asciidoctor.rb
77
84
  - lib/asciidoctor-bibtex/bibextension.rb
@@ -81,15 +88,11 @@ files:
81
88
  - lib/asciidoctor-bibtex/citationutils.rb
82
89
  - lib/asciidoctor-bibtex/extensions.rb
83
90
  - lib/asciidoctor-bibtex/filehandlers.rb
84
- - lib/asciidoctor-bibtex/options.rb
85
91
  - lib/asciidoctor-bibtex/processor.rb
86
92
  - lib/asciidoctor-bibtex/processorutils.rb
87
93
  - lib/asciidoctor-bibtex/styles.rb
88
94
  - lib/asciidoctor-bibtex/version.rb
89
- - samples/biblio.bib
90
- - samples/sample-1.adoc
91
- - samples/sample-2.adoc
92
- homepage: https://github.com/ProgramFan/asciidoctor-bibtex
95
+ homepage: https://github.com/asciidoctor/asciidoctor-bibtex
93
96
  licenses:
94
97
  - OWL
95
98
  metadata: {}
@@ -109,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
112
  version: '0'
110
113
  requirements: []
111
114
  rubyforge_project:
112
- rubygems_version: 2.6.6
115
+ rubygems_version: 2.6.7
113
116
  signing_key:
114
117
  specification_version: 4
115
- summary: asciidoctor-bibtex adds bibtex references to an asciidoc file.
118
+ summary: Adding bibtex functionality to asciidoc
116
119
  test_files: []
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Executable for asciidoc-bibtex
4
- #
5
- # Provides some command line options for adding reference material
6
- # to asciidoc files, generating revised files for processing by
7
- # asciidoc.
8
- #
9
- # Copyright (c) Peter Lane, 2012-13.
10
- # Released under Open Works License, 0.9.2
11
-
12
- unless $:.include?(libdir = File.expand_path('../lib', File.dirname(__FILE__)))
13
- $:.unshift libdir
14
- end
15
- require 'asciidoctor-bibtex'
16
-
17
- options = AsciidoctorBibtex::Options.new
18
- options.parse!
19
- AsciidoctorBibtex::Processor.run options
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Executable asciidoctor-bib
4
- #
5
- # Uses asciidoctor preprocessor extension to include citations and bibliography
6
- # in a single pass.
7
- #
8
- # Copyright (c) Peter Lane, 2013.
9
- # Released under Open Works License, 0.9.2
10
-
11
- unless $:.include?(libdir = File.expand_path('../lib', File.dirname(__FILE__)))
12
- $:.unshift libdir
13
- end
14
- require 'asciidoctor-bibtex'
15
- require 'asciidoctor/cli'
16
-
17
- # Treat '--version' specially, like that in asciidoctor-pdf
18
- options = Asciidoctor::Cli::Options.new
19
- unless (ARGV & ['-V', '--version']).empty?
20
- $stdout.write %(Asciidoctor Bib #{AsciidoctorBibtex::VERSION} using )
21
- # NOTE the print_version method was added in Asciidoctor 1.5.2
22
- if options.respond_to? :print_version
23
- options.print_version
24
- else
25
- puts %(Asciidoctor #{::Asciidoctor::VERSION} [http://asciidoctor.org])
26
- end
27
- exit 0
28
- end
29
-
30
- # Add help information on how to set bibtex related values via asciidoctor
31
- # commandline. This is the usual CLI attributes definition.
32
- if not (ARGV & ['-h', '--help']).empty?
33
- # parse argument with asciidoctor to print asciidoctor's helps
34
- options.parse! ARGV
35
- puts ""
36
- puts "AsciidoctorBibtex related options:"
37
- puts ""
38
- puts " -a bibtex-file=FILENAME Set BibTex filename (default: auto-find)"
39
- puts " -a bibtex-style=STYLE Set BibTex items style (default: apa)"
40
- puts " -a bibtex-order=<alphabetical|appearance>"
41
- puts " Set citation order scheme (default: alphabetical)"
42
- puts ""
43
- exit 0
44
- end
45
-
46
- # Use standard asciidoctor CLI mechanism to call asciidoctor, so we can accept
47
- # all asciidoctor options. Note that we only accept asciidoctor options here.
48
- # This code is stolen shamlessly from asciidoctor-pdf
49
- case (result = options.parse! ARGV)
50
- when Integer
51
- exit result
52
- else
53
- invoker = Asciidoctor::Cli::Invoker.new options
54
- GC.start
55
- invoker.invoke!
56
- exit invoker.code
57
- end
@@ -1,168 +0,0 @@
1
- # Class to read in asciidoc-bibtex options from command-line, and
2
- # store results in an accessible form.
3
- #
4
- # Copyright (c) Peter Lane, 2013.
5
- # Released under Open Works License, 0.9.2
6
-
7
- require 'optparse'
8
-
9
- module AsciidoctorBibtex
10
- class Options
11
- attr_reader :bibfile, :filename, :links, :style, :output
12
-
13
- def initialize(program_name = 'asciidoc-bibtex')
14
- @bibfile = ''
15
- @links = true
16
- @numeric_order = :alphabetical
17
- @style = AsciidoctorBibtex::Styles.default_style
18
- @program_name = program_name
19
- @output = "asciidoc"
20
- end
21
-
22
- # Public: Parse options from commandline.
23
- # This function is used by asciidoc-bib command.
24
- def parse!(args = ARGV)
25
- options = OptionParser.new do |opts|
26
- opts.banner = "Usage: #{@program_name} filename"
27
- opts.on("-h", "--help", "help message") do |v|
28
- puts "#{@program_name} #{AsciidoctorBibtex::VERSION}"
29
- puts
30
- puts options
31
- puts
32
- puts "All styles available through CSL are supported."
33
- puts "The default style is 'apa'."
34
- exit!
35
- end
36
- opts.on("-b", "--bibfile FILE", "location of bib file") do |v|
37
- @bibfile = v
38
- end
39
- opts.on("-n", "--no-links", "do not add internal links") do |v|
40
- @links = false
41
- end
42
- opts.on('', '--numeric-alphabetic-order', 'sort numeric styles in alphabetical order (DEFAULT)') do |v|
43
- @numeric_order = :alphabetical
44
- end
45
- opts.on('', '--numeric-appearance-order', 'sort numeric styles in order of appearance') do |v|
46
- @numeric_order = :appearance
47
- end
48
- opts.on("-s", "--style STYLE", "reference style") do |v|
49
- @style = v
50
- end
51
- opts.on("--output-style OUTPUT_STYLE", "Output style (asciidoc or latex)") do |v|
52
- @output = v
53
- end
54
- opts.on("-v", "--version", "show version") do |v|
55
- puts "#{@program_name} version #{AsciidoctorBibtex::VERSION}"
56
- exit!
57
- end
58
- end
59
-
60
- begin
61
- options.parse! args
62
- rescue
63
- puts options
64
- exit!
65
- end
66
-
67
- # unless specified by caller, try to find the bibliography
68
- if @bibfile.empty?
69
- @bibfile = AsciidoctorBibtex::FileHandlers.find_bibliography "."
70
- if @bibfile.empty?
71
- @bibfile = AsciidoctorBibtex::FileHandlers.find_bibliography "#{ENV['HOME']}/Documents"
72
- end
73
- end
74
- if @bibfile.empty?
75
- puts "Error: could not find a bibliography file"
76
- exit
77
- end
78
- unless AsciidoctorBibtex::Styles.valid? @style
79
- puts "Error: style #{@style} was not one of the available styles"
80
- exit
81
- end
82
-
83
- if args.length == 1
84
- @filename = args[0]
85
- else
86
- puts "Error: a single file to convert must be given"
87
- exit
88
- end
89
-
90
- puts "Reading biblio: #{@bibfile}"
91
- puts "Reference style: #{@style}"
92
- puts "Numerical order: #{@numeric_order}"
93
- puts "Output style: #{@output}"
94
- end
95
-
96
- # Public: Parse values given `attrs`
97
- # This function is used by asciidoctor preprocessor to determine options
98
- # from document attributes. According to the attribute preccedence rule,
99
- # attrs_cli > attrs_src > default
100
- def parse_attributes(attrs_cli, attrs_src)
101
- if attrs_cli['bib-style']
102
- @style = attrs_cli['bib-style']
103
- elsif attrs_src['bib-style']
104
- @style = attrs_src['bib-style']
105
- end
106
- if attrs_cli['bib-file']
107
- @bibfile = attrs_cli['bib-file']
108
- elsif attrs_src['bib-file']
109
- @bibfile = attrs_src['bib-file']
110
- end
111
- order = nil
112
- if attrs_cli['bib-numeric-order']
113
- order = attrs_cli['bib-numeric-order']
114
- elsif attrs_src['bib-numeric-order']
115
- order = attrs_src['bib-numeric-order']
116
- end
117
- if order == nil
118
- @numeric_order = :appearance
119
- elsif order == "appearance"
120
- @numeric_order = :appearance
121
- elsif order == "alphabetical"
122
- @numeric_order = :alphabetical
123
- else
124
- raise RuntimeError.new "Unknown numeric order: #{order}"
125
- end
126
- if attrs_cli['bib-no-links']
127
- @links = false
128
- elsif attrs_src['bib-no-links']
129
- @links = false
130
- end
131
- if attrs_cli['bib-output']
132
- @output = attrs_cli['bib-output']
133
- elsif attrs_src['bib-output']
134
- @output = attrs_src["bib-output"]
135
- else
136
- @output = "asciidoc"
137
- end
138
-
139
- # unless specified by caller, try to find the bibliography
140
- if @bibfile.empty?
141
- @bibfile = AsciidoctorBibtex::FileHandlers.find_bibliography "."
142
- if @bibfile.empty?
143
- @bibfile = AsciidoctorBibtex::FileHandlers.find_bibliography "#{ENV['HOME']}/Documents"
144
- end
145
- elsif not File.file? @bibfile
146
- puts "Error: bibliography file '#{@bibfile}' does not exist"
147
- exit
148
- end
149
- if @bibfile.empty?
150
- puts "Error: could not find a bibliography file"
151
- exit
152
- end
153
- unless AsciidoctorBibtex::Styles.valid? @style
154
- puts "Error: style #{@style} was not one of the available styles"
155
- exit
156
- end
157
-
158
- puts "Reading biblio: #{@bibfile}"
159
- puts "Reference style: #{@style}"
160
- puts "Numerical order: #{@numeric_order}"
161
- puts "Output style: #{@output}"
162
- end
163
-
164
- def numeric_in_appearance_order?
165
- @numeric_order == :appearance
166
- end
167
- end
168
- end
@@ -1,31 +0,0 @@
1
- @book{Lane12a,
2
- author = {P. Lane},
3
- title = {Book title},
4
- publisher = {Publisher},
5
- year = {2000}
6
- }
7
-
8
- @book{Lane12b,
9
- author = {K. Mane and D. Smith},
10
- title = {Book title},
11
- publisher = {Publisher},
12
- year = {2000}
13
- }
14
-
15
- @book{Anderson98,
16
- editor = {J. R. Anderson and C. Lebiere},
17
- title = {The Atomic Components of Thought},
18
- publisher = {Lawrence Erlbaum},
19
- address = {Mahwah, NJ},
20
- year = {1998}
21
- }
22
-
23
- @article{Anderson04,
24
- author = {J. R. Anderson and D. Bothell and M. D. Byrne and S. Douglass and C. Lebiere and Y. L. Qin},
25
- title = {An integrated theory of the mind},
26
- journal = {Psychological Review},
27
- volume = {111},
28
- number = {4},
29
- pages = {1036--1060},
30
- year = {2004}
31
- }
@@ -1,38 +0,0 @@
1
- = Sample of using asciidoctor-bibtex
2
- :bibtex-file: biblio.bib
3
- :bibtex-order: alphabetical
4
- :bibtex-style: ieee
5
-
6
- The bibliography is searched in the folder of the document, and then in
7
- ~/Documents.
8
-
9
- Author-year references can use different styles such as: cite:[Lane12b] or
10
- citenp:[Lane12a].
11
-
12
- Page numbers can be added: cite:[Lane12a(89)] or citenp:[Lane12a(89-93)].
13
-
14
- A bit of pretext can be included too: See cite:[Lane12a(89)]
15
-
16
- We can include other files, which are also processed:
17
-
18
- include::sample-2.adoc[]
19
-
20
- To include the reference list, use the section template before title, to
21
- prevent problems with a2x.
22
-
23
- References can be inserted in lists, too:
24
-
25
- 1. See cite:[Lane12a].
26
- 2. See cite:[Anderson98].
27
- 3. See cite:[Anderson04].
28
-
29
- Also works for unordered list:
30
-
31
- * See cite:[Lane12a].
32
- * See cite:[Anderson98].
33
- * See cite:[Anderson04].
34
-
35
- [sect2]
36
- == Bibliography
37
-
38
- bibliography::biblio.bib[ieee]
@@ -1,18 +0,0 @@
1
- == Sample file 2: multiple authors ==
2
-
3
- Author-year references can use different styles such as: cite:[Lane12b] or
4
- citenp:[Lane12b].
5
-
6
- Page numbers can be added: cite:[Lane12b(89)] or citenp:[Lane12b(89-93)].
7
-
8
- A bit of pretext can be included too: See cite:[Lane12b(89)]
9
-
10
- === multiple refs ===
11
-
12
- One citation can include several references, such as cite:[Lane12a,Lane12b].
13
-
14
- These can include pages and be in-text: citenp:[Lane12a(78), Lane12b(89-93)].
15
-
16
- And include pretext: See cite:[Lane12a, Lane12b(89-93)]
17
-
18
- Note: citations cannot be split over lines; each citation must be on one line.