Apple Script to get the H1 in a Markdown file as String

Can anybody please help me with this.

The code from the link below that @BLUEFROG shared already processes the markdown file. I only need it to get the heading 1 and save it into something like titleText. So that I can use it.

I wrote something like this but didn’t work.

set titleText to (characters 3 thru -1 of paragraph 0 of currentText as string) 
                -- Cache all but the control characters in H1

You can also check out the conversation below to see what i mean.

Can you add more detail to “didn’t work”

I’m thinking paragraph 0 should be paragraph 1
You might want to check if the paragraph is actually a heading; ie begins with **

1 Like

paragraph 1 did the trick! Thanks a lot.

For anyone interested in the resulting solution you can check out both the Applescript and the Javascript solutions in the original topic: