Help with a way (script?) to copy DT tags to first line of md file?

A simple script to insert the tags could look like this:

tell application id "DNtp"
	repeat with theRecord in (selection as list)
		if type of theRecord is markdown then
			set theText to plain text of theRecord
			set theTags to ""
			set theTagList to tags of theRecord
			if (count of theTagList) is greater than 0 then
				repeat with theTag in theTagList
					if theTags is not "" then set theTags to theTags & ", "
					set theTags to theTags & "#" & theTag
				end repeat
				set theText to "tag: " & theTags & return & return & theText
				set plain text of theRecord to theText
			end if
		end if
	end repeat
end tell