Browse Source

added ids to headings

remy 14 năm trước cách đây
mục cha
commit
3d3207142f
1 tập tin đã thay đổi với 2 bổ sung1 xóa
  1. 2 1
      src/showdown.js

+ 2 - 1
src/showdown.js

@@ -688,7 +688,8 @@ var _DoHeaders = function(text) {
 	text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
 		function(wholeMatch,m1,m2) {
 			var h_level = m1.length;
-			return hashBlock("<h" + h_level + ">" + _RunSpanGamut(m2) + "</h" + h_level + ">");
+			var id = m2.replace(/[^\w]/g, '').toLowerCase();
+			return hashBlock("<h" + h_level + ' id="' + id + '">' + _RunSpanGamut(m2) + "</h" + h_level + ">");
 		});
 
 	return text;