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.