Heal Your Church WebSite


Teaching, rebuking, correcting & training in righteous web design.

Scripturizer – core engine

All week I’ve been leading you on, telling you that I’d give you some code that would encode your plain text with hyperlinks to the online Bible of your choosing. After some throwing some raw meat out into the comp.lang.perl.misc usenet group, I received fillet-mignon snippet from Jeff ‘japhy’ Pinyan that gave me enough of a match to compress the 400 some odd lines of Steve Lihn’s code into about 40 lines of code (provided you don’t count where I had to split long statements to fit this posting).

This will obviously need to be rolled into a Perl module that might also include some other elements such as slicing and dicing sermons, dealing with acronyms and madding stuff like “Revelations” instead of “Revelation.”
my $volumes = “I+|1st|2nd|3rd|First|Second|Third|1|2|3″;# I chopped these up so they’d stay within the margins of my blog
my $books = “Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|”;
$books .= “Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther|”;
$books .= “Job|Psalm|Proverbs|Ecclesiastes|Song of Solomon|Isaiah|”;
$books .= “Jeremiah|Lamentations|Ezekiel|Daniel|Hosea|Joel|Amos|”;
$books .= “Obadiah|Jonah|Micah|Nahum|Habakkuk|Zephaniah|Haggai|”;
$books .= “Zechariah|Malachi|Matthew|Mark|Luke|John|Acts|Romans|”;
$books .= “Corinthians|Galatians|Ephesians|Philippians|Colossians|”;
$books .= “Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|”;
$books .= “Jude|Revelation”;

my $link = “http://biblegateway.com/cgi-bin/bible?passage=”;

while(<DATA>) {

my $passage;

# this string will sit inside following expression
my $verses = qr{ \d+ (: \d+)* \s* (?: [-&] \s* \d+)* }x;

# replace instances
s/
(?:($volumes)\s*)*
\s*
($books)
\s*
( $verses (?: \s* , \s* $verses)* )
/$passage = ($1 ? “$1 “:”").($2 ? $2:”").($3 ? ” $3″:”");
” <a href=\”$link”.encodePassage($1,$2,$3).”\”>$passage<\/a>”
/gcex;

print $_;
}

# make it validate
sub encodePassage {
my ($vol, $bk, $ver) = @_;
$ver =~ s/:/%3A/gi;
$ver =~ s/[,&;]/%2C/gi;
$ver =~ s/\s*//gi;
my $passage = ($vol ? “$vol+”:”").($bk ? “$bk+”:”").($ver ? “$ver”:”");
return $passage;
}

__DATA__
$Date: October 20, 2002
$Type: Sermon
$Scripture: James 2:1-13, 14 & 15
$Version: NIV
$Title: How Faith Works: “Determining the Worth of a Person”
Foo

$Text:
… what Paul was thinking of when he wrote in Galatians 3 and said, “There is neither Jew nor Greek, SLAVE NOR FREE, male nor female, for you are all ONE in Christ Jesus.” (Galatians 3:28)

Bar
… and they were-it was the rich Sadducees who arrested Peter and John in Acts 4. Acts 13:50 says it was the wealthy “leading men” of the city of Antioch who persecuted Paul and Barnabas. Acts 16 says the wealthy owners of a demon-possessed girl dragged Paul into court and Acts 19 tells of the wealthy silversmiths in Ephesus who very nearly led a mob to kill him. James also says that it was the rich of that day who slandered the name of Jesus.

2 Comments

  1. Very cool Dean. I think I’ll implement this on my own site eventually. Just a suggestion though; seems to me there might be some danger of this system “accidentally” transforming something into a link that it shouldn’t…for instance, if I were writing about “My New Job”, I don’t want “Job” linked to the book of Job. How about using markup to show what text is actually Scripture…something like “In the book of Job, God says…” Then your “Scripturizer” could be set to ignore any matches that were not marked as being Scripture. Just an idea.

  2. Wy dont you just use like Wikipedia you put

    Book uv [[Job]]:

    Or:

    In [[Job 12:5]] you can find…

    That wood prevent the danger. And, I use PHP on mi web-site not Perl.