Creating complex web links

Hello. I know how to create straightforward HTML links of the type “https://www.whatever.co.uk/”, but it would really be helpful if I could create the links with target set like this:

https://www.whatever.co.uk/” target=“_blank” rel=“noopener”

Does anyone have any suggestions as to how to do it. Whatever I’ve tried with and without quote marks, Scrivener tells me it is not a valid URL. I don’t want to simply enter the URLs as part of the text marked “Preserve formatting”.

Many thanks. :smile:

Mark

PS That is the syntax of the Talking of Food website that I manage… built in Joomla!

Just to make sure, you’re talking about compiling?

Oh hi,

Actually, I’m talking about entering the links in Scrivener. I’m writing all new articles in Scrivener and compiling via mmd → html. that’s all working fine. But currently, I’m having to remember to add the target part after compiling, either in a text editor, or on the website editor itself.

If I could enter complex URLs in Scrivener, it would save a lot of to-ing-and-froing.

:smile:

Mark

What if you rather place the extra bits in a custom metadata field and use placeholders instead?

1 Like

If that’s possible then I don’t know how. It certainly belongs to the Compiler, but even there I’m not sure how I would achieve it (without processing the output externally). :thinking:

The placeholder would have to be inside the “Add Link” box in Scrivener, or it wouldn’t compile as part of the final:

<a href="https://www.whatever.co.uk/" target="_blank" rel="noopener">whatever</a>

And if it was in the “Add Link” box, it would again be refused as not a valid URL

:smile:

Mark

And what if you separate them with a space followed by a special character in the editor (so that Scrivener doesn’t think it is a single “thing”) then simply search and remove those after compile.
You wouldn’t have to remember where and what to edit afterwards, just do a global search and remove in whatever other app you’d use after compiling.

I think that would be even more onerous than remembering to add the relevant bit of code afterwards in my text editor (through a snippet in aText!). :laughing:

Mark

Just in case it comes in handy until someone offers a better solution, that’s how I used to pimp my blog links in exported HTML files before publishing, using a RegEx replace:

this:

<a.+?href=([^>]+)>

with that:

<a href=$1 target="_blank" rel="noopener noreferrer">

It’s an extra step, but the upside is: You don’t have to remember to enter those extras or enter them correctly. (And they really only make sense in specific contexts anyways).

1 Like

I’ll have to try that. I haven’t used RegEx in BBEdit, but that might be a solution, if no one comes up with a way to do it in Scrivener.

Many thanks.

Supper time here, so I’ll be gone some time!

:smile:

Mark

Well, now that I think of it, if that would otherwise work (aside from the time required for the search and remove), perhaps it’d still work if you have your compile format do the removal at compile. ?
…replace _۞ with nothing (or with the target, if it is systematically always the same).

At what stage exactly does Scrivener “refuse” your URL ?

Probably in the Scrivener editor: Creating complex web links - #6 by xiamenese

image

Clicked from within the editor:
image

??

image

??

Anyways, I’m far from an expert, but if it is of any help, I obtain the first by editing the link afterwards
image

and the second the same way, but selecting the part that Scrivener refused to include in the link (so the whole thing) first.

If I enter it this way it comes out wrong (as entered and seen in your screenshots), like:

<a href="http://"https://www.whatever.co.uk/" ...

I fixed it (see new screenshots) and both links still open the website.

Could you please screenshot the dialog box where you enter the address?

image

image


image

Yes, that works. And how do you set up the Compiler to not produce:

<a href="http://www.whatever.co.uk/%22%20target=%22_blank%22%20rel=%22noopener%22">

:thinking:

I don’t know. (I haven’t done anything.)
Here is my resulting PDF (both links work) :

image


Compiled to html :

image

Both links still work.

Interesting. I think the PDF viewer tries to make sense of the actual broken URL.

EDIT: Indeed, the link works, but judging from the actual HTML, e.g. <a href="http://www.whatever.co.uk/%22%20target=%22_blank%22%20rel=%22noopener%22"> the attributes (“target” and “rel”) are most likely not acknowledged by the browser. Basically throwing out the very properties that sparked this adventure.