Skip to content

Commit

Permalink
v1.4 adding --boldwords and --newline options
Browse files Browse the repository at this point in the history
  • Loading branch information
jgclark committed Feb 1, 2021
1 parent ac0df7e commit c318c0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

### v1.4.0, 1.2.2021
- [Change/New] Add `--boldwords` option to turn on Markdown bold for the words of Jesus. This is now off by default.
- [New] Add `--newline` option to start chapters and verses on a new line that starts with an H5 or H6 heading

### v1.3.0, 29.12.2020
- [New] Add ability to parse and show cross-references (or suppress with `-r` option), as seen in NIV and ESV versions, for example.
- [New] Handle the unusual (unique?) multi-verse numbering in the MSG version.
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ The output also gets copied to the clipboard.

When the 'Lord' is shown with small caps (in OT), it is output as 'LORD'.

When the original is shown red letter (i.e. the words of Jesus), this is rendered in bold in the Markdown output.
When the original is shown red letter (i.e. the words of Jesus), this can be rendered in bold in the Markdown output, with the `--boldwords` option.

Chapters and verses can optionally be prefixed with markdown H5 and H6 headers respectively, using the `--newline` option.

## Installation
Check you have installed the `colorize` and `optparse` gems (> `gem install colorize optparse`).
Expand All @@ -35,11 +37,13 @@ The following options are available:

Option | Option (longer form) | Meaning
--------- | ------------ | ---------------------------------
-b | --boldwords | Make the words of Jesus in markdown bold
-c | --copyright | Exclude copyright notice from output
-e | --headers | Exclude editorial headers from output
-f | --footnotes | Exclude footnotes from output
-h | --help | Show help
-i | --info | Show information as I work
-l | --newline | Start chapters and verses on a new line that starts with an H5 or H6 heading
-n | --numbering | Exclude verse and chapter numbers from output
-r | --crossrefs | Exclude cross-refs from output
-t | --test FILENAME | Pass HTML from FILENAME instead of live lookup. 'reference' must still be given, but will be ignored.
Expand Down
32 changes: 24 additions & 8 deletions bg2md.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/ruby
#----------------------------------------------------------------------------------
# BibleGateway passage lookup and parser to Markdown
# - Jonathan Clark, v1.3.0, 29.12.2020
# - Jonathan Clark, v1.4.0, 1.2.2021
#----------------------------------------------------------------------------------
# Uses BibleGateway.com's passage lookup tool to find a passage and turn it into
# Markdown usable in other ways. It passes 'reference' through to the BibleGateway
Expand Down Expand Up @@ -69,7 +69,7 @@
# - You can run this in -test mode, which uses a local file as the HTML input,
# to avoid over-using the BibleGateway service.
#----------------------------------------------------------------------------------
VERSION = '1.3.0'.freeze
VERSION = '1.4.0'.freeze

# require 'uri' # for dealing with URIs
require 'net/http' # for handling URIs and requests. More details at https://ruby-doc.org/stdlib-2.7.1/libdoc/net/http/rdoc/Net/HTTP.html
Expand Down Expand Up @@ -107,6 +107,10 @@
opt_parser = OptionParser.new do |o|
o.banner = 'Usage: bg2md.rb [options] reference'
o.separator ''
opts[:boldwords] = false
o.on('-b', '--boldwords', 'Make the words of Jesus in markdown bold') do
opts[:boldwords] = true
end
opts[:copyright] = true
o.on('-c', '--copyright', 'Exclude copyright notice') do
opts[:copyright] = false
Expand All @@ -127,6 +131,10 @@
o.on('-i', '--info', 'Show information as I work') do
opts[:verbose] = true
end
opts[:newline] = false
o.on('-l', '--newline', 'Start chapters and verses on newline with H5 or H6 heading') do
opts[:newline] = true
end
opts[:numbering] = true
o.on('-n', '--numbering', 'Exclude verse and chapter numbers') do
opts[:numbering] = false
Expand Down Expand Up @@ -333,10 +341,18 @@
passage.gsub!(%r{<hr />}, '')
# simplify verse/chapters numbers (or remove entirely if that option set)
if opts[:numbering]
# Extract the contents of the 'versenum' class (which should just be numbers, but we're not going to be strict)
passage.gsub!(%r{<sup class="versenum">\s*(\d+-?\d?)\s*</sup>}, '\1 ')
# verse number '1' seems to be omitted if start of a new chapter, and the chapter number is given.
passage.gsub!(%r{<span class="chapternum">\s*(\d+)\s*</span>}, '\1:1 ')
# Now see whether to start chapters and verses as H5 or H6
if opts[:newline]
# Extract the contents of the 'versenum' class (which should just be numbers, but we're not going to be strict)
passage.gsub!(%r{<sup class="versenum">\s*(\d+-?\d?)\s*</sup>}, "\n###### \\1 ")
# verse number '1' seems to be omitted if start of a new chapter, and the chapter number is given.
passage.gsub!(%r{<span class="chapternum">\s*(\d+)\s*</span>}, "\n##### Chapter \\1\n###### 1 ")
else
# Extract the contents of the 'versenum' class (which should just be numbers, but we're not going to be strict)
passage.gsub!(%r{<sup class="versenum">\s*(\d+-?\d?)\s*</sup>}, '\1 ')
# verse number '1' seems to be omitted if start of a new chapter, and the chapter number is given.
passage.gsub!(%r{<span class="chapternum">\s*(\d+)\s*</span>}, '\1:1 ')
end
else
passage.gsub!(%r{<sup class="versenum">.*?</sup>}, '')
passage.gsub!(%r{<span class="chapternum">.*?</span>}, '')
Expand All @@ -358,8 +374,8 @@
passage.gsub!(%r{<br />}, " \n") # use two trailling spaces to indicate line break but not paragraph break
# Change the small caps around OT 'Lord' and make caps instead
passage.gsub!(%r{<span style="font-variant: small-caps" class="small-caps">Lord</span>}, 'LORD')
# Change the red text for Words of Jesus to be bold instead
passage.gsub!(%r{<span class="woj">(.*?)</span>}, '**\1**')
# Change the red text for Words of Jesus to be bold instead (if wanted)
passage.gsub!(%r{<span class="woj">(.*?)</span>}, '**\1**') if opts[:boldwords]
# simplify footnotes (or remove if that option set). Complex so do in several stages.
if opts[:footnotes]
passage.gsub!(/<sup data-fn=\'.*?>/, '<sup>')
Expand Down

0 comments on commit c318c0a

Please sign in to comment.