3
$\begingroup$

I tried to add a hyperlink to the text using the shortcut Ctrl+Shit+H to open the Zotero application; enter image description here

but every time MMA notebook adds the "https" prefix by default, and can only be manually remove using the Ctrl+Shift+E shortcut. Is there a way to disable the "https" prefix feature. enter image description here

Any reply is much appreciated!

$\endgroup$

1 Answer 1

3
$\begingroup$

It seems like the front-end, called via MathLink`CallFrontEnd[Hyperlink`InsertHyperlinkPacket[...]], only allows a limited set of URI schemes, namely http, https, file, mailto, ftp, paclet, news, gopher, mail, nntp, wais, telnet, vbscript, javascript, mocca, nfs, about. Since zotero is not among them, https is automatically used. I don't think you can overcome this, since it seems to be hard-coded in the front-end kernel. I am offering two possible workarounds.

Fix existing links

Create links as you would normally do. Then, use the following code to create a palette, which will find all occurences of zotero links in the selected notebook and replace https://zotero:// with zotero://. Warning: I have tested this only on a small notebook, so make sure to save your notebook before using this!

CreatePalette[DynamicModule[{count = ""},
   Column@{Button["Fix zotero links",
      count = 0;
      Table[With[{content = NotebookRead[cell]},
        SelectionMove[cell, All, Cell];
        If[!FreeQ[content, ButtonBox[__, ButtonData -> {URL[s_ /; StringStartsQ[s, 
                 "https://zotero://"]], ___}, ___]],         
         NotebookWrite[cell, 
           content /. b_ButtonBox :> (count++; 
              b /. s_String :> 
                StringReplace[s, "https://zotero://" -> "zotero://"])];
         ]
        ], {cell, Cells[SelectedNotebook[]]}];
      count = StringTemplate["Fixed `` links!"][count]
      ], Dynamic[count]}],
  WindowTitle -> "Fix links", Saveable -> False];

Make new links

The following code will create a dialog which can be used to insert a new link without any processing. The code works only for making links in text.

With[{nb = EvaluationNotebook[]}, 
 DynamicModule[{link}, 
  CreateDialog[{TextCell["Link: "], InputField[Dynamic[link], String],
     Button["Insert Hyperlink", Paste[nb,
      Module[{text = 
         First[FrontEndExecute[
           FrontEnd`ExportPacket[BoxData@NotebookRead[nb], 
            "InputText"]]]}, 
       ToExpression@
        ButtonBox[text, BaseStyle -> "Hyperlink", 
         ButtonData -> {URL[link], None}, ButtonNote -> link]]]]}]]];

animation

$\endgroup$
1
  • $\begingroup$ Thank you for your help $\endgroup$ Commented Apr 23, 2024 at 6:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.