[TOOL] Create Live Links in a LibreOffice formatted bibliography
Posted: Thu Dec 03, 2015 1:15 pm
I often include URLs and DOIs in my bibliographies, and by default Bookends does not mark these up as URLs in the bibliography, so one must do this manually. For anyone using Open/LibreOffice, I've written a macro to automatically find all URLs in a document and convert them to live links (aka clickable hyperlinks). The macro code is below, you just need to copy it into your LibreOffice My Macros > Standard as a subroutine and you can then run it on your formatted document. If you remove the REM on line 21, then DOI links have the link text set to "DOI" to reduce the clutter in the bibliography. Hope someone finds it useful.
Code: Select all
Sub makeURLs()
Dim oDocument As Object
Dim oSearch As Object, oFound As Object
Dim oFoundCursor As Object
Dim reURL As String
Dim doistring as String
Dim URL as String
reURL = "(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)"
URL = ""
doistring = "dx.doi.org"
oDocument = ThisComponent
oSearch = oDocument.createSearchDescriptor
oSearch.SearchRegularExpression = TRUE
oSearch.SearchString = reURL
oFound = oDocument.findFirst(oSearch)
While NOT IsNull(oFound)
URL = oFound.String
If InStr(URL, doistring) Then
oFound.HyperlinkName = "DOI"
REM oFound.String = "DOI"
Else
oFound.HyperlinkName = "URL"
End If
oFound.HyperlinkTarget = ""
oFound.HyperlinkURL = URL
oFound = oDocument.findNext(oFound, oSearch)
URL=""
Wend
End Sub