bibmarkdown 1.1.0 → 1.2.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: 3e44cd9b80ded7fea0a9b95d4155da2d1cdf7115
4
- data.tar.gz: eaf09d977f1ab9a032e0cef5c6e165eeb505903c
3
+ metadata.gz: b1ae9c68a4ae3e578f2e0c51ac4848ad49ba8615
4
+ data.tar.gz: 3a02f49a6aaf61dc9e04c5b6c63449a691574198
5
5
  SHA512:
6
- metadata.gz: 241bf7dc4aeafe5ca924e29457c314ed67cee26c4eab8cbd9e4b7f3af3a279cde3eea7f46cf8a7cf5260a9d2c732f9c0df85d85d0310bf91bd195ba5b4f8b54f
7
- data.tar.gz: 59a5703d1ff9fc4f1f83cc6f3e639b0c08d4bf5d9f9d26771d3d5d66aca593ddac2acc0ecdbb7c5fb3f65293b5ea243bd68ea4c228a6755510e77f28ec6ff68a
6
+ metadata.gz: 46cd8fc901d0000095b9f9ce5abdf25a8cb44610e485f096d8803540172fd8438e3713b11f6c5342c74856178e2cf5aea36ea9fbf846deba002ca1d82fbb885a
7
+ data.tar.gz: 272d0cef6ebb59597cb8ec2da626c7b807fd8499362c414d33fa8c5768f042990fadabe8a77341863c56779e610420366edd1df4fbc6dd060d9a92f0c8ea3831
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
data/bibmarkdown.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bibmarkdown 1.1.0 ruby lib
5
+ # stub: bibmarkdown 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bibmarkdown"
9
- s.version = "1.1.0"
9
+ s.version = "1.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Ruben Verborgh"]
14
- s.date = "2017-01-05"
14
+ s.date = "2017-05-09"
15
15
  s.email = "ruben@verborgh.org"
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE.md",
@@ -11,44 +11,50 @@ module BibMarkdown
11
11
  end
12
12
 
13
13
  def to_markdown
14
- reference_ids = {}
14
+ @references = {}
15
15
 
16
16
  # Replace all citations by links
17
- markdown = @source.gsub %r{\[([^\]]*)\]\(cite:(\w+)\s+([^\)]+)\)} do |match|
18
- html = $1; rel = $2; key = $3
17
+ markdown = @source.gsub %r{\[([^\]]*)\]\(cit[eo]:(\w+)\s+([^\)]+)\)} do |match|
18
+ text = $1; rel = $2; keys = $3
19
19
 
20
- # Look up or assign reference ID
21
- if reference_ids.has_key? key
22
- reference_id = reference_ids[key]
23
- else
24
- reference_id = reference_ids[key] = reference_ids.length + 1
25
- end
26
-
27
- # Look up citation and its URL
28
- entry = @entries[key]
29
- raise "Failed to generate references: entry '#{key}' does not exist." unless entry
30
- url = entry[:url] || ''
20
+ # Create the references
21
+ refs = keys.strip.split(/\s*,\s*/).map {|key| create_reference key }
22
+ raise "Missing reference key in #{match}" if refs.empty?
23
+ reflinks = refs.map{|r| r[:link]}.join ''
31
24
 
32
- # Create the reference
33
- reflink = create_link "[#{reference_id}]", "#ref-#{reference_id}", class: 'reference'
34
-
35
- # If the text is empty, just output the reference
36
- if html.empty?
37
- reflink
38
- # If there is no URL, just output the text with the reference
39
- elsif url.empty?
40
- "#{html} #{reflink}"
41
- # Otherwise, output the link and the reference
25
+ # If the link text is empty, output links to the references
26
+ if text.empty?
27
+ reflinks
28
+ # If there is no URL, output the text followed by links to the references
29
+ elsif refs.first[:url].empty?
30
+ "#{text} #{reflinks}"
31
+ # Otherwise, output the linked text and the references
42
32
  else
43
- "#{create_link html, url, property: 'http://purl.org/spar/cito/' + rel} #{reflink}"
33
+ property = 'http://purl.org/spar/cito/' + rel
34
+ "#{create_link text, refs.first[:url], property: property} #{reflinks}"
44
35
  end
45
36
  end
46
37
 
47
- # Append the reference list to the text
48
- "#{markdown}\n\n#{references_html reference_ids}".rstrip
38
+ # Append the reference list to the document
39
+ "#{markdown}\n\n#{references_html}".rstrip
49
40
  end
50
41
 
51
42
  protected
43
+ def create_reference key
44
+ return @references[key] if @references.has_key? key
45
+
46
+ # Look up citation and its URL
47
+ entry = @entries[key]
48
+ raise "Failed to generate references: entry '#{key}' does not exist." unless entry
49
+ url = entry[:url] || ''
50
+
51
+ # Assign an ID and create a link to the reference
52
+ id = @references.length + 1
53
+ link = create_link "[#{id}]", "#ref-#{id}", class: 'reference'
54
+
55
+ @references[key] = { id: id, url: url, link: link }
56
+ end
57
+
52
58
  def h text
53
59
  CGI::escapeHTML(text || '')
54
60
  end
@@ -59,14 +65,14 @@ module BibMarkdown
59
65
  %Q{<a #{attrs.join ' '}>#{html}</a>}
60
66
  end
61
67
 
62
- def references_html reference_ids
63
- if reference_ids.empty?
68
+ def references_html
69
+ if @references.empty?
64
70
  ''
65
71
  else
66
72
  html = %Q{<h2 id="references">References</h2>\n}
67
73
  html += %Q{<dl class="references">\n}
68
- reference_ids.each do |key, id|
69
- html += %Q{ <dt id="ref-#{id}">[#{id}]</dt>\n}
74
+ @references.each do |key, ref|
75
+ html += %Q{ <dt id="ref-#{ref[:id]}">[#{ref[:id]}]</dt>\n}
70
76
  html += %Q{ <dd>#{reference_html key}</dd>\n}
71
77
  end
72
78
  html += %Q{</dl>\n}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibmarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Verborgh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-05 00:00:00.000000000 Z
11
+ date: 2017-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: citeproc-ruby