mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
7d63a3e635
This commit adds events to all subparsers (that were previously not being watched).
34 lines
951 B
JavaScript
34 lines
951 B
JavaScript
/**
|
|
* Convert all tabs to spaces
|
|
*/
|
|
showdown.subParser('detab', function (text, options, globals) {
|
|
'use strict';
|
|
text = globals.converter._dispatch('detab.before', text, options, globals);
|
|
|
|
// expand first n-1 tabs
|
|
text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
|
|
|
|
// replace the nth with two sentinels
|
|
text = text.replace(/\t/g, '¨A¨B');
|
|
|
|
// use the sentinel to anchor our regex so it doesn't explode
|
|
text = text.replace(/¨B(.+?)¨A/g, function (wholeMatch, m1) {
|
|
var leadingText = m1,
|
|
numSpaces = 4 - leadingText.length % 4; // g_tab_width
|
|
|
|
// there *must* be a better way to do this:
|
|
for (var i = 0; i < numSpaces; i++) {
|
|
leadingText += ' ';
|
|
}
|
|
|
|
return leadingText;
|
|
});
|
|
|
|
// clean up sentinels
|
|
text = text.replace(/¨A/g, ' '); // g_tab_width
|
|
text = text.replace(/¨B/g, '');
|
|
|
|
text = globals.converter._dispatch('detab.after', text, options, globals);
|
|
return text;
|
|
});
|