I have this text to manipulate in AppleScript (e.g. the text of a variable):
Example note exported from Apple.
<ul>
<li>Indent</li>
<ul>
<li>*Further* indent</li>
<ul>
<li>Even **further **indent. With a [link](https://duck.com).</li>
</ul>
</ul>
</ul>
End note.
I'm converting it all to Markdown from HTML. I need to clean up this remaining bit of HTML which is the bullet list, so that the result is (with real tabs as indent space):
Example note exported from Apple.
- Indent
- *Further* indent
- Even **further **indent. With a [link](https://duck.com).
End note.
It has to be able to cater to nested indenting to any 'n' number of levels, and with possibly some rich text inside the items such as this example. I prefer Markdown output to use hyphens and a tab for the indenting.
It also has to be containable inside the applescript – no external .py
files etc, and to not require homebrew
or a third party tool to be installed.
Best Answer
The following example AppleScript code, as coded, is intended to work with bulleted list HTML code as shown in the OP, meaning that what is passed in the variable is just the relevant code to define the bulleted list and not other arbitrary HTML code.
As coded, it will produce the appropriate output for variations of bulleted list HTML code as well, not just the specific example shown herein. This has been tested on a variety of other samples containing just bulleted list HTML code and produces the relevant output for it as does the example herein.
Result:
Which displays as the following in a browser on this web site: