Jump to content

Copy as HTML5


Michael Miles

Recommended Posts

It would be very helpful to be able to copy Bible text as HTML5 in addition to the RTF that is currently programmed into Accordance.

  • Like 1
Link to comment
Share on other sites

I'm not feeling the love on this suggestion/request.  I'm also finding it hard to believe that I'm the only Accordance user that copies Accordance text into web pages.  Hmmm.

 

Maybe I can just do this with applescript and/or bash with some ruby and python and perl for good measure.  It would be cooler if it was built in.  I believe that Logos has this, but that would mean going over to the other side.

  • Like 1
Link to comment
Share on other sites

Michael,

 

I am curious. What would be the advantage of copying an Accordance resources as HTML 5?

 

I am going to assume it's not to post large sections of resources on the internet itself, as that would be a violation of the various copyrights.

Link to comment
Share on other sites

Hi Timothy,

 

I just pasted some text from the KJVS Accordance module on my MacBook Air into my profile signature and you can see that the italicized words come out a bit off when pasting the Rich Text Format that Accordance places in the clipboard.  If the option for HTML5 existed, then this would not be this way.

 

I teach in various places on the internet using the KJV, a Strong's, and the Smith's Bible dictionary and I generally hand code the teachings with a text editor.  It gets very slow and cumbersome to have to go back and forth between Accordance and the text editor to make sure that I have all of the italicized words in italics.  My text editors do not have options to take RTF as input.

 

For example:  http://7seals.net/Studies/Jezebel.Of.Thyatira/index.html

 

If there was an option for HTML5 for copying from Accordance, it would be much easier to use.

 

Thanks!

Michael

  • Like 1
Link to comment
Share on other sites

Thanks, Michael, your explanation helps.

 

Try setting your Preferences>Export>Unicode to "Export all characters with Unicode format." I use "Cardo" and "Regular" and the italics paste beautifully. 

Edited by Timothy Jenney
Link to comment
Share on other sites

Hi Timothy,

 

Thanks for the reply and the help.  In the workflow that I'm using for the HTML pages, my editor is BBEdit, and it will not take that RTF at all, but just converts everything to plain ascii.  What I have been doing as a quick stop-gap is to copy from Accordance and then drop that into TextEdit for OS X and save that as an html file, then I open that html file and cut what I need and paste it into BBEdit.  Then I have to run find & replace to fix all of the junk that TextEdit tossed into the html code.

 

If it is not possible to have Accordance populate the clipboard with ascii formatted as html, then I can either write and run scripts in BBEdit or use applescript to do the job.  Or grep and bash it.  :-)

 

Thanks,

Michael

Edited by Michael Miles
  • Like 2
Link to comment
Share on other sites

Couple thoughts:

 

1. I wonder if you might be well served by an app like Writer Pro [app store link], which would allow pasting in the RTF flavor from Accordance, then export to markdown or HTML.

 

and/or…

 

2. Consider using a Reference List in Accordance [link to help] where you add verses there as you're researching, then paste them all at one time to your word processor > text editor.

  • Like 1
Link to comment
Share on other sites

Hi Rick,

 

Thank you for those ideas.  I just now purchased the Writer Pro and will also be giving the Reference List idea a spin.  I sure do appreciate those pointers.  I'll get back after I have tried both out and let you know how it fares.

 

Thanks again,

Michael

Link to comment
Share on other sites

I was asked to remove my signature on the forum, so the references that I made to it earlier in this exchange are no longer available to see.

Link to comment
Share on other sites

  • 5 months later...

Couple thoughts:

 

1. I wonder if you might be well served by an app like Writer Pro [app store link], which would allow pasting in the RTF flavor from Accordance, then export to markdown or HTML.

 

and/or…

 

2. Consider using a Reference List in Accordance [link to help] where you add verses there as you're researching, then paste them all at one time to your word processor > text editor.

Well, I never got back to you on this, Rick.  With Writer Pro (now IA Writer), you cannot simply paste the copied Rich Text Format material from Accordance into IA Writer and maintain any of the formatting outside of the italicized text.  There is no longer a File/Import menu item in the software, but the docs indicate that it will import a Word .docx file if you drag the word document over to the IA Writer icon, which it will do, but the document is instantly transformed into markdown (as well as the entire application menu structure of IA Writer going AWOL after the import takes place).  If you take the resulting markdown and export it as HTML, it is a very drab and ugly shadow of what you had copied into your clipboard from Accordance.

 

Trying to import an RTF document created in Word 2016 for Mac containing scripture into IA Writer results in a garish collection of odd text and trying to export that from IA Writer as HTML further puts the text into nightmare land.

 

I couldn't get the Reference List idea to fly either.

 

I tried saving the pastings from Accordance into Word 2016 as filtered HTML, and while it has a whole lot less of the proprietary Microsoft "HTML" cruft, it becomes much more than a mere snippet of HTML, which is what I need.  At least I can bang on it in BBEdit this way.

 

By pasting clips from Accordance into Word 2016 and saving the file in RTF format and then going to the terminal to run textutil -convert html filename.rtf I get the most satisfactory results that take the least amount of additional work to make use of, but it is still actually faster to paste the Accordance copy into BBEdit and format the html by hand, referring to Accordance to see where the italicized text is, so that I can match it, and adding superscripts for verse references, as well as other visual HTML/CSS formatting.

 

I even tried pasting from Accordance into a Hype 3 Pro HTML Widget and then taking a copy of that and pasting it into BBEdit.  This was not quite as good as textutil from the command line, but somewhat workable, especially compared to IA Writer.

 

It became obvious that a native way to take the Accordance copied text and paste it as a formatted HTML5 snippet would be the best way to work with this.

 

Because of this hurdle in dealing with copying from Accordance, I'm currently revamping my web sites and testing other methodology to get a clean HTML rendering of the Bible text into the pages.

Edited by Michael Miles
  • Like 1
Link to comment
Share on other sites

Wow!  I actually found a very inexpensive app in the app store that gives essentially the same results as the paste into Word 2016/save as RTF/convert with textutil/ process, which was about the best workflow that I could whittle together and skips me having to open a terminal and run textutil.  Here is a link to the app that is about the best tool that I have found for this task so far:

 

https://itunes.apple.com/us/app/mach-write/id790428201?mt=12

 

If you try to fetch the Bible text with accordance services, it comes in to Mach Write not quite very good, but if you paste a selection copied from Accordance into it and then export as HTML, you are gold.

 

I wonder how hard it would be for Accordance programmers to pipe the clipboard through textutil to offer this transformation on the fly, without need of any additional software.  Maybe I need to put my applescript and automator hats on.

  • Like 1
Link to comment
Share on other sites

Here's an apple script I wrote for the task.  Just save it as an Application using  Applications>Utilities>Script Editor, paste the code in, then Save as or Export as type: Application.  I saved it to my Desktop for ease of use.

 

To use it, highlight any RTF, including Accordance text, then doubleclick the app you just created...

 

It will then open TextEdit, paste the RTF in, save it as html to your desktop, and close TextEdit. Additionally it copies the HTML into your clipboard so it's ready to paste into your favorite code editor (mine is Atom).

 

Thanks,

Ryan

set destFile to (POSIX path of (path to desktop) & "clip.html") as POSIX file

tell application "TextEdit"
	activate
	set newDoc to make new document
	tell application "System Events"
		keystroke "v" using {command down}
	end tell
	save newDoc in destFile
	quit
end tell

set fh to (open for access destFile)
set txt to (read fh for (get eof fh))
close access fh
set the clipboard to txt
  • Like 1
Link to comment
Share on other sites

Good job, R Gustason on thinking in terms of an Applescript solution. Three totally unsolicited suggestions to improve the script:

1. The directory /private/tmp/ is the standard place to save throw-away file like that, so you don't have files junking up the Desktop

2. You don't need to do "open for access" on a file you're just going to read into a variable.

3. A better place to have the script is in the system wide script menu, or couched inside of a Service for easier launching. (You didn't mention that you actually have to copy the selection, then run your script. If you launch one of those ways, the app stays in the front and you can add a copy to clipboard aspect to the script initially.

 

Having said all that, anytime you can avoid scripting a visible app to accomplish something like this, that's a plus. Fortunately you can resort to using the command line utility textutil (instead of TextEdit) to do the conversion, then add some sed magic to copy just the stuff inside the body tag to the clipboard.

tell application "System Events" to keystroke "c" using {command down}
delay 0.1
set s to do shell script "osascript -e 'the clipboard as «class RTF »' | perl -ne 'print chr foreach unpack(\"C*\",pack(\"H*\",substr($_,11,-3)))' | textutil -stdin -stdout -convert html -format rtf | sed -n '/<body>/,/<\\/body>/p' | sed -e '1s/.*<body>//' -e '$s/<\\/body>.*//'"
set the clipboard to s
Edited by Joe Weaks
  • Like 2
Link to comment
Share on other sites

 

Here's an apple script I wrote for the task.  Just save it as an Application using  Applications>Utilities>Script Editor, paste the code in, then Save as or Export as type: Application.  I saved it to my Desktop for ease of use.

 

To use it, highlight any RTF, including Accordance text, then doubleclick the app you just created...

 

It will then open TextEdit, paste the RTF in, save it as html to your desktop, and close TextEdit. Additionally it copies the HTML into your clipboard so it's ready to paste into your favorite code editor (mine is Atom).

 

Thanks,

Ryan

set destFile to (POSIX path of (path to desktop) & "clip.html") as POSIX file

tell application "TextEdit"
	activate
	set newDoc to make new document
	tell application "System Events"
		keystroke "v" using {command down}
	end tell
	save newDoc in destFile
	quit
end tell

set fh to (open for access destFile)
set txt to (read fh for (get eof fh))
close access fh
set the clipboard to txt

 

 

 

Good job, R Gustason on thinking in terms of an Applescript solution. Three totally unsolicited suggestions to improve the script:

1. The directory /private/tmp/ is the standard place to save throw-away file like that, so you don't have files junking up the Desktop

2. You don't need to do "open for access" on a file you're just going to read into a variable.

3. A better place to have the script is in the system wide script menu, or couched inside of a Service for easier launching. (You didn't mention that you actually have to copy the selection, then run your script. If you launch one of those ways, the app stays in the front and you can add a copy to clipboard aspect to the script initially.

 

Having said all that, anytime you can avoid scripting a visible app to accomplish something like this, that's a plus. Fortunately you can resort to using the command line utility textutil (instead of TextEdit) to do the conversion, then add some sed magic to copy just the stuff inside the body tag to the clipboard.

tell application "System Events" to keystroke "c" using {command down}
delay 0.1
set s to do shell script "osascript -e 'the clipboard as «class RTF »' | perl -ne 'print chr foreach unpack(\"C*\",pack(\"H*\",substr($_,11,-3)))' | textutil -stdin -stdout -convert html -format rtf | sed -n '/<body>/,/<\\/body>/p' | sed -e '1s/.*<body>//' -e '$s/<\\/body>.*//'"
set the clipboard to s

Oh man!  Thank you very much, Gentlemen, for these responses.  I'm just about to close up shop for the day, but I know what I'll be looking at tomorrow!  :-)  I got off on a tangent where I'm playing with custom markdown, but this should open up some doors.

  • Like 1
Link to comment
Share on other sites

Hello 

 

How do I this two connect to one script? Do I have simple put one after the another or ....

 

 

Greetings

 

Fabian

Link to comment
Share on other sites

Joe,

 

I thought about using textutil for the conversion, but I assumed Michael wanted to use TextEdit for some reason.  Thanks for the /private/tmp suggestion.  I didn't know that was the default for apple.  I'm a storage administrator for a large corporation and use AIX a lot in my daily job.  It's /tmp off the root for us... but, that being said, I didn't put it there in case some non tech savvy people wanted to view the resulting html file. This way its easy to find for them. My next version was going to sed between the body tags... great minds think alike I guess! LOL.  Anyway, thanks for the suggestions!

 

Fabian,

One quick way to combine the two, replace the last four lines of my script with Joe's set s ... to set the clipboard to s lines.  That should combine the two and work well enough I think... Of course I'm saying this two minutes before heading out the door to church! LOL! So, I haven't fully vetted it yet.

  • Like 1
Link to comment
Share on other sites

Fabian, 

 

Actually just use these two lines in place of my last four.... now I'm really gone for a few... LOL! 

set s to do shell script "osascript -e sed -n '/<body>/,/<\\/body>/p' | sed -e '1s/.*<body>//' -e '$s/<\\/body>.*//'"
set the clipboard to s
  • Like 1
Link to comment
Share on other sites

No coffee yet, so there's that.  No local churches that teach truth, so we just have it here 24/7.

 

Anyway, I came across a bash shell script that does a nifty job of this using my uncoffeefied google-fu:

 

http://hea-www.harvard.edu/~fine/OSX/cliphtml.html

 

The page that the shell script is parked on also has some applescript info pertaining to it.  I just wanted to share.   :)

Edited by Michael Miles
Link to comment
Share on other sites

I made an easy change to the bash shell script so that after all of the conversion takes place, everything is piped back into the clipboard.  Now I just need to clip off everything but the contents of the <p> tags, since I don't need an entire html file for each copy and paste.

#!/bin/sh

   osascript -e 'the clipboard as «class RTF »' | \
    perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | \
    textutil -stdin -stdout -convert html -format rtf | pbcopy

You can man bcopy from the terminal to get more info on this nifty contraption.

 

Would still like to have this as a system service, so I'll look at that more as the day unfolds.

 

 

 

EDIT:  Need that coffee!  Nope..I just edited out that edit.

Edited by Michael Miles
Link to comment
Share on other sites

Michael, that shell script is exactly what I have wrapped in the Applescript I offered.

 

R Gustason, regarding storing temp files, truthfully, the best practice in Applescript is to use is prolly "path to temporary items" which resolves to "/private/var/folders".

But, all the Unix tmp places are also available /tmp (which I belive links to /private/tmp) and /usr/tmp and /var/tmp.

Because I was working on a Unix shell command, I was in store-Unix mode. But, if I were asked what's the best practice though, when doing Applescript, I'd say using "Path to temporary items". FWiW

  • Like 2
Link to comment
Share on other sites

Michael, that shell script is exactly what I have wrapped in the Applescript I offered.

 

R Gustason, regarding storing temp files, truthfully, the best practice in Applescript is to use is prolly "path to temporary items" which resolves to "/private/var/folders".

But, all the Unix tmp places are also available /tmp (which I belive links to /private/tmp) and /usr/tmp and /var/tmp.

Because I was working on a Unix shell command, I was in store-Unix mode. But, if I were asked what's the best practice though, when doing Applescript, I'd say using "Path to temporary items". FWiW

 

Hi Joe,

 

Thanks for the help on this.  You lost me on your comments to R. Gustason.  I'm going to have to do some homework.  I do appreciate you leading me in the right direction.

Link to comment
Share on other sites

R Gustason, regarding storing temp files, truthfully, the best practice in Applescript is to use is prolly "path to temporary items" which resolves to "/private/var/folders".

But, all the Unix tmp places are also available /tmp (which I belive links to /private/tmp) and /usr/tmp and /var/tmp.

Because I was working on a Unix shell command, I was in store-Unix mode. But, if I were asked what's the best practice though, when doing Applescript, I'd say using "Path to temporary items". FWiW

Joe, Thanks for the info!

Link to comment
Share on other sites

Michael,

 

Joe is saying you can use 'path to temporary items' in place of 'path to desktop' in my original script.

I copied the line from the original script below.  If making throw away files (such as clip.html) you'd generally want to save them in the tmp (temporary) folder, which usually is cleaned out via cronjob scripts or other methods...

(POSIX path of (path to desktop) & "clip.html") as POSIX file

I did not do this on the original script because I assumed people might want to view the outputted html file.

Edited by R Gustason
  • Like 1
Link to comment
Share on other sites

Michael,

 

Joe is saying you can use 'path to temporary items' in place of 'path to desktop' in my original script.

I copied the line from the original script below.  If making throw away files (such as clip.html) you'd generally want to save them in the tmp (temporary) folder, which usually is cleaned out via cronjob scripts or other methods...

(POSIX path of (path to desktop) & "clip.html") as POSIX file

I did not do this on the original script because I assumed people might want to view the outputted html file.

Thank you very much for that information.  I still have not had an opportunity to stare at all of this with any sort of focus, but I do hope to be able to do that soon.

 

I wonder how hard it would be for the programmers at Accordance to add a copy as HTML routine into their code.  I'd need minimally the italics and superscripts for my purposes.  BBEdit is my primary editing tool.  Maybe I need to see if I can approach this problem from the pasting side there as well as looking at the copy side here.

 

All of this after i get some other technical issues squared away.   :)

Link to comment
Share on other sites

  • 2 weeks later...

If the Accordance programmers are looking for something to do, maybe they could have copied text in Accordance go into the clipboard as HTML as an option.  That would be the bomb, as the kids say.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...