markdownr 0.5.14 → 0.5.15

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: f80b8ab8eaa610c955ccd7838ed37f02d900c9e73ce64e52c163b4992a9be5a0
4
- data.tar.gz: 2e26441fbcf5355977e3393b1948b39af22c07301317355627a48252fd394768
3
+ metadata.gz: 77fceda0fe858b6e806b6c0a5e77bd4983d3ee35ed461dfd9542eacd35eb599d
4
+ data.tar.gz: 7b63eb14d6e54995594ab7f6a365e5bd92b6a73769c9576e9a0e8c32f74ab578
5
5
  SHA512:
6
- metadata.gz: '0639cf0ff09aec6ad21db709b8d8a2a6f98780ad26d3602beaba00b736f877fe81622113c283caf2ecee5f431dffc542c1ac00095905e85219d43766e94049a2'
7
- data.tar.gz: a1846784c14a99b559cad1314260b09dfff5aeeda243dac14d2e2c78f5f619b030a54a225305827fa5a4042b3a11a12e29e946c3e985b22bdaf4f1959e074f0f
6
+ metadata.gz: 121ba459b814911e3031a8adc78e470401dc74d1cb738a419eddc9d53137411e47cb46e6b3275c186c92723ad87a6f2e91f712436b070eb286816c9fecfcecf5
7
+ data.tar.gz: 88581d13772f4c632f19bead603f33b175c5ac26d90d14a3d5697aafd5b0aacc8f479a56f9ab4f20c08a81fa647561ede9f7533213984b13c290f83acf0e230f
@@ -136,14 +136,8 @@ module MarkdownServer
136
136
 
137
137
  # Auto-link bare Bible verse citations (e.g. "John 3:16" → BibleGateway link).
138
138
  # Skips inline code, fenced code blocks, and citations already inside a link.
139
- text = text.gsub(BIBLE_CITATION_RE) do |m|
140
- next m if $1 || $2 || $3 # code span / code fence / existing link
141
- citation = $4
142
- entry = BIBLE_BOOK_MAP_SORTED.find { |k, _| citation.start_with?(k) }
143
- next m unless entry
144
- abbrev, canonical = entry
145
- rest = citation[abbrev.length..].sub(/\A\.?[ \t]?/, "")
146
- url = "https://www.biblegateway.com/passage/?search=#{CGI.escape("#{canonical} #{rest}")}&version=CEB"
139
+ text = MarkdownServer.link_citations(text) do |canonical, verse, citation|
140
+ url = "https://www.biblegateway.com/passage/?search=#{CGI.escape("#{canonical} #{verse}")}&version=CEB"
147
141
  "[#{citation}](#{url})"
148
142
  end
149
143
 
@@ -32,46 +32,47 @@ module MarkdownServer
32
32
  "Genesis"=>"Genesis","Gen."=>"Genesis","Gen"=>"Genesis","Gn"=>"Genesis",
33
33
  "Exodus"=>"Exodus","Ex."=>"Exodus","Exo"=>"Exodus","Ex"=>"Exodus",
34
34
  "Leviticus"=>"Leviticus","Lev."=>"Leviticus","Lev"=>"Leviticus",
35
- "Numbers"=>"Numbers","Num."=>"Numbers","Nu."=>"Numbers","Nu"=>"Numbers",
35
+ "Numbers"=>"Numbers","Num."=>"Numbers","Num"=>"Numbers","Nu."=>"Numbers","Nu"=>"Numbers",
36
36
  "Deuteronomy"=>"Deuteronomy","Deut."=>"Deuteronomy","Deut"=>"Deuteronomy",
37
37
  "Dt."=>"Deuteronomy","Dt"=>"Deuteronomy",
38
- "Joshua"=>"Joshua","Josh."=>"Joshua",
39
- "Judges"=>"Judges","Judg."=>"Judges",
38
+ "Joshua"=>"Joshua","Josh."=>"Joshua","Josh"=>"Joshua",
39
+ "Judges"=>"Judges","Judg."=>"Judges","Judg"=>"Judges",
40
40
  "Ruth"=>"Ruth",
41
41
  "1 Samuel"=>"1 Samuel","1Samuel"=>"1 Samuel","1 Sam."=>"1 Samuel","1 Sam"=>"1 Samuel","1Sam."=>"1 Samuel",
42
42
  "2 Samuel"=>"2 Samuel","2Samuel"=>"2 Samuel","2 Sam."=>"2 Samuel","2 Sam"=>"2 Samuel","2Sam."=>"2 Samuel","2Sa."=>"2 Samuel",
43
- "1 Kings"=>"1 Kings","1Kings"=>"1 Kings","1 Ki."=>"1 Kings","1Ki."=>"1 Kings",
44
- "2 Kings"=>"2 Kings","2Kings"=>"2 Kings","2 Ki."=>"2 Kings","2Ki."=>"2 Kings",
43
+ "1 Kings"=>"1 Kings","1Kings"=>"1 Kings","1 Ki."=>"1 Kings","1Ki."=>"1 Kings","1 Ki"=>"1 Kings","1Ki"=>"1 Kings",
44
+ "2 Kings"=>"2 Kings","2Kings"=>"2 Kings","2 Ki."=>"2 Kings","2Ki."=>"2 Kings","2 Ki"=>"2 Kings","2Ki"=>"2 Kings",
45
45
  "1 Chronicles"=>"1 Chronicles","1 Chr."=>"1 Chronicles","1Chr."=>"1 Chronicles","1Ch"=>"1 Chronicles",
46
46
  "2 Chronicles"=>"2 Chronicles","2 Chron."=>"2 Chronicles","2Chron."=>"2 Chronicles","2 Chr."=>"2 Chronicles","2Chr."=>"2 Chronicles","2 Ch"=>"2 Chronicles",
47
- "Ezra"=>"Ezra","Nehemiah"=>"Nehemiah","Neh."=>"Nehemiah",
48
- "Esther"=>"Esther","Esth."=>"Esther",
47
+ "Ezra"=>"Ezra","Nehemiah"=>"Nehemiah","Neh."=>"Nehemiah","Neh"=>"Nehemiah",
48
+ "Esther"=>"Esther","Esth."=>"Esther","Esth"=>"Esther",
49
49
  "Job"=>"Job",
50
50
  "Psalms"=>"Psalms","Psalm"=>"Psalms","Psa."=>"Psalms","Psa"=>"Psalms","Ps."=>"Psalms","Ps"=>"Psalms",
51
51
  "Proverbs"=>"Proverbs","Prov."=>"Proverbs","Prov"=>"Proverbs","Pr"=>"Proverbs",
52
- "Ecclesiastes"=>"Ecclesiastes","Eccl."=>"Ecclesiastes","Ecc."=>"Ecclesiastes",
52
+ "Ecclesiastes"=>"Ecclesiastes","Eccl."=>"Ecclesiastes","Eccl"=>"Ecclesiastes","Ecc."=>"Ecclesiastes",
53
53
  "Song of Songs"=>"Song of Songs","Song"=>"Song of Songs",
54
54
  "Isaiah"=>"Isaiah","Isa."=>"Isaiah","Isa"=>"Isaiah","Is"=>"Isaiah",
55
- "Jeremiah"=>"Jeremiah","Jer."=>"Jeremiah","Je"=>"Jeremiah",
55
+ "Jeremiah"=>"Jeremiah","Jer."=>"Jeremiah","Jer"=>"Jeremiah","Je"=>"Jeremiah",
56
56
  "Lamentations"=>"Lamentations","Lam."=>"Lamentations","Lam"=>"Lamentations","La"=>"Lamentations",
57
57
  "Ezekiel"=>"Ezekiel","Ezek."=>"Ezekiel","Ezek"=>"Ezekiel",
58
58
  "Daniel"=>"Daniel","Dan."=>"Daniel","Dan"=>"Daniel",
59
59
  "Hosea"=>"Hosea","Hos."=>"Hosea","Hos"=>"Hosea",
60
60
  "Joel"=>"Joel","Amos"=>"Amos",
61
- "Obadiah"=>"Obadiah","Jonah"=>"Jonah","Jon."=>"Jonah",
62
- "Micah"=>"Micah","Mic."=>"Micah",
63
- "Nahum"=>"Nahum","Nah."=>"Nahum",
61
+ "Obadiah"=>"Obadiah","Jonah"=>"Jonah","Jon."=>"Jonah","Jon"=>"Jonah",
62
+ "Micah"=>"Micah","Mic."=>"Micah","Mic"=>"Micah",
63
+ "Nahum"=>"Nahum","Nah."=>"Nahum","Nah"=>"Nahum",
64
+ "Habakkuk"=>"Habakkuk","Hab."=>"Habakkuk","Hab"=>"Habakkuk",
64
65
  "Haggai"=>"Haggai",
65
- "Zechariah"=>"Zechariah","Zech."=>"Zechariah","Zec"=>"Zechariah","Zc"=>"Zechariah",
66
- "Zephaniah"=>"Zephaniah","Zep."=>"Zephaniah",
67
- "Malachi"=>"Malachi","Mal."=>"Malachi",
66
+ "Zechariah"=>"Zechariah","Zech."=>"Zechariah","Zech"=>"Zechariah","Zec"=>"Zechariah","Zc"=>"Zechariah",
67
+ "Zephaniah"=>"Zephaniah","Zeph."=>"Zephaniah","Zeph"=>"Zephaniah","Zep."=>"Zephaniah","Zep"=>"Zephaniah",
68
+ "Malachi"=>"Malachi","Mal."=>"Malachi","Mal"=>"Malachi",
68
69
  # ── New Testament ────────────────────────────────────────────────────────
69
- "Matthew"=>"Matthew","Matt."=>"Matthew","Mt."=>"Matthew","Mt"=>"Matthew",
70
+ "Matthew"=>"Matthew","Matt."=>"Matthew","Matt"=>"Matthew","Mt."=>"Matthew","Mt"=>"Matthew",
70
71
  "Mark"=>"Mark","Mk."=>"Mark","Mk"=>"Mark",
71
72
  "Luke"=>"Luke","Lk."=>"Luke","Lk"=>"Luke",
72
73
  "John"=>"John","Jn."=>"John","Jn"=>"John","Jo"=>"John",
73
74
  "Acts"=>"Acts","Ac."=>"Acts",
74
- "Romans"=>"Romans","Rom."=>"Romans","Ro"=>"Romans",
75
+ "Romans"=>"Romans","Rom."=>"Romans","Rom"=>"Romans","Ro"=>"Romans",
75
76
  "1 Corinthians"=>"1 Corinthians","1Corinthians"=>"1 Corinthians","1 Cor."=>"1 Corinthians","1Cor."=>"1 Corinthians","1 Cor"=>"1 Corinthians","1Cor"=>"1 Corinthians","1Co."=>"1 Corinthians","1Co"=>"1 Corinthians",
76
77
  "2 Corinthians"=>"2 Corinthians","2Corinthians"=>"2 Corinthians","2 Cor."=>"2 Corinthians","2Cor."=>"2 Corinthians","2 Cor"=>"2 Corinthians","2Co."=>"2 Corinthians","2Co"=>"2 Corinthians",
77
78
  "Galatians"=>"Galatians","Gal."=>"Galatians","Gal"=>"Galatians",
@@ -80,8 +81,8 @@ module MarkdownServer
80
81
  "Colossians"=>"Colossians","Col."=>"Colossians","Col"=>"Colossians",
81
82
  "1 Thessalonians"=>"1 Thessalonians","1 Thess."=>"1 Thessalonians","1Thess."=>"1 Thessalonians","1 Th"=>"1 Thessalonians","1Th"=>"1 Thessalonians",
82
83
  "2 Thessalonians"=>"2 Thessalonians","2Thessalonians"=>"2 Thessalonians","2 Thess."=>"2 Thessalonians","2Thess."=>"2 Thessalonians","2 Th"=>"2 Thessalonians","2Th"=>"2 Thessalonians",
83
- "1 Timothy"=>"1 Timothy","1Timothy"=>"1 Timothy","1 Tim."=>"1 Timothy","1Tim."=>"1 Timothy","1 Ti."=>"1 Timothy","1Ti."=>"1 Timothy",
84
- "2 Timothy"=>"2 Timothy","2Timothy"=>"2 Timothy","2 Tim."=>"2 Timothy","2Tim."=>"2 Timothy","2 Ti."=>"2 Timothy","2Ti."=>"2 Timothy",
84
+ "1 Timothy"=>"1 Timothy","1Timothy"=>"1 Timothy","1 Tim."=>"1 Timothy","1Tim."=>"1 Timothy","1 Tim"=>"1 Timothy","1Tim"=>"1 Timothy","1 Ti."=>"1 Timothy","1Ti."=>"1 Timothy",
85
+ "2 Timothy"=>"2 Timothy","2Timothy"=>"2 Timothy","2 Tim."=>"2 Timothy","2Tim."=>"2 Timothy","2 Tim"=>"2 Timothy","2Tim"=>"2 Timothy","2 Ti."=>"2 Timothy","2Ti."=>"2 Timothy",
85
86
  "Titus"=>"Titus","Tit."=>"Titus","Tit"=>"Titus","Ti."=>"Titus",
86
87
  "Philemon"=>"Philemon","Philem."=>"Philemon",
87
88
  "Hebrews"=>"Hebrews","Hebrew"=>"Hebrews","Heb."=>"Hebrews","Heb"=>"Hebrews","Hb"=>"Hebrews",
@@ -101,6 +102,26 @@ module MarkdownServer
101
102
  # Sorted longest-first for runtime lookup (same order as the regex alternation).
102
103
  BIBLE_BOOK_MAP_SORTED = BIBLE_BOOK_MAP.sort_by { |k, _| -k.length }.freeze
103
104
 
105
+ # Scans +text+ for bare Bible verse citations and yields each one as
106
+ # (canonical_book, verse, raw_citation). Returns the transformed string
107
+ # with each citation replaced by whatever the block returns. Code spans,
108
+ # fenced code blocks, and citations already inside a markdown link are
109
+ # passed through unchanged.
110
+ #
111
+ # MarkdownServer.link_citations("See Rom 12:1.") { |c, v, _| "[#{c} #{v}]" }
112
+ # # => "See [Romans 12:1]."
113
+ def self.link_citations(text)
114
+ text.gsub(BIBLE_CITATION_RE) do |m|
115
+ next m if $1 || $2 || $3 # code span / code fence / existing link
116
+ citation = $4
117
+ entry = BIBLE_BOOK_MAP_SORTED.find { |k, _| citation.start_with?(k) }
118
+ next m unless entry
119
+ abbrev, canonical = entry
120
+ verse = citation[abbrev.length..].sub(/\A\.?[ \t]?/, "")
121
+ yield canonical, verse, citation
122
+ end
123
+ end
124
+
104
125
  _book_alts = BIBLE_BOOK_MAP.keys.sort_by(&:length).reverse
105
126
  .map { |k| Regexp.escape(k) }.join("|")
106
127
  _verse = /\d+[abc]?(?:[–—\-]\d+[abc]?)?(?:,\s*\d+[abc]?(?:[–—\-]\d+[abc]?)?)*(?:ff\.?|f\.)?/
@@ -114,7 +135,7 @@ module MarkdownServer
114
135
  "(`[^`]*?`)" \
115
136
  "|(`{3}[\\s\\S]*?`{3})" \
116
137
  "|(?<!\\!)(\\[[^\\[\\]]*\\]\\([^)]+\\))" \
117
- "|((?:#{_book_alts})\\.?[ \\t]?\\d+:#{_verse.source})",
138
+ "|((?:#{_book_alts})\\.?[ \\t]?\\d+(?::#{_verse.source})?)",
118
139
  Regexp::MULTILINE
119
140
  )
120
141
  end
@@ -1,3 +1,3 @@
1
1
  module MarkdownServer
2
- VERSION = "0.5.14"
2
+ VERSION = "0.5.15"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdownr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.14
4
+ version: 0.5.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dunn