diff --git a/gh-md-toc b/gh-md-toc
index 35239bf..16e5418 100755
--- a/gh-md-toc
+++ b/gh-md-toc
@@ -269,6 +269,13 @@ gh_toc_grab() {
#
# became: The command foo1
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
+
+ # if opening is on the end of a line, merge it with the next line
+ # for example:
+ # was:
+ # foo1
+ # became:
+ sed -e ':a' -e 'N' -e '$!ba' -e 's/heading-element">\n/heading-element">/g' |
# Sometimes a line can start with . Fix that.
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n