mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
Extend remy's addition of heading id attributes to apply to Setext-style headings as well.
This commit is contained in:
parent
053b830e88
commit
55d2f65350
|
@ -661,10 +661,10 @@ var _DoHeaders = function(text) {
|
|||
// --------
|
||||
//
|
||||
text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
|
||||
function(wholeMatch,m1){return hashBlock("<h1>" + _RunSpanGamut(m1) + "</h1>");});
|
||||
function(wholeMatch,m1){return hashBlock('<h1 id="' + headerId(m1) + '">' + _RunSpanGamut(m1) + "</h1>");});
|
||||
|
||||
text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
|
||||
function(matchFound,m1){return hashBlock("<h2>" + _RunSpanGamut(m1) + "</h2>");});
|
||||
function(matchFound,m1){return hashBlock('<h2 id="' + headerId(m1) + '">' + _RunSpanGamut(m1) + "</h2>");});
|
||||
|
||||
// atx-style headers:
|
||||
// # Header 1
|
||||
|
@ -688,10 +688,12 @@ var _DoHeaders = function(text) {
|
|||
text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
|
||||
function(wholeMatch,m1,m2) {
|
||||
var h_level = m1.length;
|
||||
var id = m2.replace(/[^\w]/g, '').toLowerCase();
|
||||
return hashBlock("<h" + h_level + ' id="' + id + '">' + _RunSpanGamut(m2) + "</h" + h_level + ">");
|
||||
return hashBlock("<h" + h_level + ' id="' + headerId(m2) + '">' + _RunSpanGamut(m2) + "</h" + h_level + ">");
|
||||
});
|
||||
|
||||
function headerId(m) {
|
||||
return m.replace(/[^\w]/g, '').toLowerCase();
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user