I have a text file or some text to process via the clipboard. It contains a few lines of HTML code, and I'd like to convert it to pure Markdown.
E.g. from:
This is a link: <a href="https://duck.com">link</a>
to:
This is a link: [link](https://duck.com)
Is there pure AppleScript code (using regex substitution) that can do this?
Alternatively, I am happy with AppleScript calling any CLI tool to process the text via do shell script
if it's an in-built text which doesn't require homebrew
or a third party tool to be installed.
Best Answer
Here is one example:
Result:
This can also be down without the use of the
do shell script
command, as in this example:Result:
If
This is a link: <a href="https://duck.com">link</a>
is in a file or on the clipboard, the escaping is done automatically when assigning it to a variable. You then only need to escape the"
in thesed
command as shown in the example above.Other examples:
If
This is a link: <a href="https://duck.com">link</a>
in in a file:Or, processing the file directly:
If
This is a link: <a href="https://duck.com">link</a>
is on the clipboard:Note: The use of the
findAndReplaceInText()
handler can also be used in place of thedo shell script
command in these other examples.