Greetings, folks!
Thank you, again, to KniazidisR for solving this!
Appended below is the AppleScript that I have been using, followed by the HTML template text file, called by the script. (There is a free version of BBEdit available, for those who don’t have a license.)
The details of installing the Mercury Web Parser are at:
https://postlight.com/trackchanges/mercury-goes-open-source
There is a screen shot of the result of converting that very page, as viewed on my iPhone 7 Plus at:
https://i.stack.imgur.com/EkBy3.jpg
I have found the Mercury Web Parser an invaluable means of saving and reading Web pages on my iPhone when offline, and offer this for others who might find it useful as well.
Blessings, and thank you!, to everyone’s efforts to solve this!
Richard Fairbanks
————————
The AppleScript:
global thePage
set theTitle to ""
set theAuthor to "(author not defined)"
set theDate to ""
tell application "Safari" to set pageURL to the URL of document 1
set nodePath to "/Users/<UserName>/.nvm/versions/node/v10.15.3/bin/node "
set mercuryParserPath to "/Users/<UserName>/.yarn/bin/mercury-parser "
set thePage to (do shell script nodePath & mercuryParserPath & pageURL)
delay 1
tell application "BBEdit"
activate
make new text document
tell text window 1
set the last line to thePage
select insertion point before line 1
#### Get the Original Page address, Titie, Author, and Date ####
set theOriginal to characters 11 through -3 of line 9 as text -- get the address of the original page
find "{\"title\":\"(.+)\",\"author" searching in text 1 of text document 1 options {search mode:grep, starting at top:true, case sensitive:true} with selecting match
try
set theTitle to (characters 13 through -3 of line 2 as text)
end try
set theAuthor to characters 13 through -2 of line 3 as text
if theAuthor is "null" then set theAuthor to ""
try
set theDate to (characters 22 through 31 of line 4 as text) & " at " & characters 33 through -8 of line 4 as text
end try
#### Clean up the code for HTML ####
find "\"content\": \"" searching in text 1 of text document 1 options {search mode:grep, starting at top:true, case sensitive:true} with selecting match
select insertion point after the selection
delay 0.1
tell application "System Events" to tell process "BBEdit" to key code 126 using {command down, shift down} -- select everything up to the start of the text
delete the selection
delay 0.1
find "\"next_page_url" searching in text 1 of text document 1 options {search mode:grep, starting at top:true, case sensitive:true} with selecting match
delay 0.1
select insertion point before the selection
tell application "System Events" to tell process "BBEdit" to key code 125 using {command down, shift down} -- select everything after the HTML text
delay 0.1
delete the selection
delay 0.1
copy characters 1 through -6 of the contents
delay 0.1
select insertion point before line 1
end tell
delay 0.1
if window "Readability Template.html" exists then revert document "Readability Template.html"
open file "Path:To:File:Readability Template.html"
delay 0.1
tell text window 1
replace "<TITLE>Readability Template</TITLE>" using ("<TITLE>" & theTitle & "</TITLE>") searching in text document 1 options {search mode:literal, starting at top:true}
delay 0.1
set line 19 to (theTitle & " <a href=" & theOriginal & "> <small>[ORIGINAL PAGE]</small></a><br>" & return & theAuthor & "<br>" & return & theDate & "<br>" & "<br>" & return & return) as text
select insertion point before line 23
paste
-- clean up bad text
-- replace unprocessed HTML characters
-- Not properly processed by Web Parser Code: Unicode Hex Character Code � (called "Replacement Character")
--> as shown parsing http://rense.com/general96/psychotronictech.htm
replace "^�$" using "—" searching in text document 1 options {search mode:grep, starting at top:true} -- single character line marker
replace ">�<" using ">•<" searching in text document 1 options {search mode:literal, starting at top:true} -- single character line marker
replace " �" using "“" searching in text document 1 options {search mode:literal, starting at top:true} -- opening double quote preceded by space
replace "� " using "”" searching in text document 1 options {search mode:literal, starting at top:true} -- closing double quote followed by space
replace "(.)�(.)" using "\\1’\\2" searching in text document 1 options {search mode:grep, starting at top:true} -- apostrophe
-- clean up the last bit of errant code
replace "\\\\\\\"" using "\"" options {search mode:grep, starting at top:true}
replace ">\\\\n" using ">" searching in text 1 of text document "Readability Template.html" options {starting at top:true}
-- break up the text to make it readable (currently not working)
replace "</p><p>" using "</p>
<p>" searching in text document 1 options {search mode:literal, starting at top:true}
select insertion point before line 1
end tell
preview in browser
end tell
and the HTML template called in the script: