# How to run Javascript on Markdown "summarize highlights" output?

**URL:** <https://discourse.devontechnologies.com/t/how-to-run-javascript-on-markdown-summarize-highlights-output/53375>\
**Category:** Automation\
**Created:** [January 29, 2020, 2:54pm UTC](https://discourse.devontechnologies.com/t/how-to-run-javascript-on-markdown-summarize-highlights-output/53375 "2020-01-29T14:54:10Z")\
**Posts on this page:** 1\
**Showing post:** 25

<div class="post-metadata">

**Author:** ![OAL](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/o/e95f7d/32.png) [@OAL](https://discourse.devontechnologies.com/u/OAL)\
**Post date:** [September 20, 2022, 5:57pm UTC](https://discourse.devontechnologies.com/t/how-to-run-javascript-on-markdown-summarize-highlights-output/53375/25 "2022-09-20T17:57:54Z")

</div>

I managed to solve this both in Apple Script and Javascript.  
Now I get the Heading 1 in the parentheses.

This is the Applescript version:

```auto
on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			if (type of theRecord as string) = "markdown" then
				-- Only process Markdown docs
				
				set newText to {}
				-- Set up an empty list to push the paragraphs into)
				
				set currentText to (plain text of theRecord)
				-- Get the current text of the document
				
				set titleText to (characters 3 thru -1 of paragraph 1 of currentText as string) -- Cache all but the control characters in a variable     
				
				repeat with thisLine in (paragraphs of currentText)
					-- Loop through the document, paragraph by paragraph
					
					if thisLine begins with "##" then
						-- If this is an H2 page link
						set cachedText to (characters 4 thru -1 of thisLine as string) -- Cache all but the control characters in a variable
						
					else if thisLine begins with "* " then
						-- If it's just a bulleted paragraph
						
						copy ((characters 3 thru -1 of thisLine as string) & " (" & (titleText) & ": " & (cachedText) & ") " & return) to end of newText
						-- Get all but the control characters and concatenate the cachedText.
						-- Then push it to the newText list
					else
						copy thisLine & return to end of newText
						-- Anything else, including the H1 line at the top, just push into the newText list
					end if
				end repeat
				
				set plain text of theRecord to (newText as string)
				-- Set the text of the document to the new text
				
			end if
		end repeat
	end tell
end performSmartRule

```

---

_[View the full topic](https://discourse.devontechnologies.com/t/how-to-run-javascript-on-markdown-summarize-highlights-output/53375)._
