I have a shortcut which is invoked via an action sheet when sharing a URL.
When invoked, it eventually gets the HTML of the webpage via:
- Accepts URLs
- Get contents of [URL]
-
Make HTML from [Contents of URL]
The HTML at this stage is something like this:
<a href="http://www.example.com">Click here</a>
- Match
<a href="([^"]+)">Click here</a>
in [HTML from Rich Text] - Get [Group At Index] [1] in [Matches]
- Show [Text] in Quick Look
Step 5 is inserted for debugging purposes. However, instead of showing me the URL it was able to parse, it shows me a page saying:
The file name is not valid
To debug the issue, I tried removing steps 1-3, and replacing it with text:
-
Text
<a href="http://www.example.com">Click here</a>
- Match
<a href="([^"]+)">Click here</a>
in [HTML from Rich Text] - Get [Group At Index] [1] in [Matches]
- Show [Text] in Quick Look
Now Quick Look suddenly does work. I.e. it shows me:
What is going on here, and why can I only get it to work with static text and not an action sheet?
Best Answer
Another way I debugged this issue was I changed what it was matching. E.g. instead of matching the URL, I decided to match the "Click here" to see what would happen:
Make HTML from [Contents of URL]
The HTML at this stage is something like this:
<a href="[^"]+">(Click here)</a>
in [HTML from Rich Text]Sure enough, this worked. Quick Look showed me:
This made it clear that there is something going on with text that happens to be in the format of a URL in Quick Look.
The
Get Type
(along with Quick Look right after it) was helpful in debugging and figuring out what the issue was.There were a few non-obvious things going on here:
Rich text
. When testing with the Text action, the type of the text before reaching Quick look wasText
.Text
(even if it looks like a URL), it'll display the URL as plain text.Rich text
, then it will try to display the contents of the URL, as though it's a local file (or something like that). This will most likely result in theThe file name is not valid
error mentioned above.The fix, then, is to force the contents to be converted into plain text by adding an extra step right before the Quick Look:
Make HTML from [Contents of URL]
The HTML at this stage is something like this:
<a href="([^"]+)">Click here</a>
in [HTML from Rich Text]