showdown icon indicating copy to clipboard operation
showdown copied to clipboard

maximum nesting of 10 spans reached!!!

Open sem1colon opened this issue 5 years ago • 1 comments

How to fix this?

sem1colon avatar Jun 23 '20 11:06 sem1colon

Try adding the following code at the beginning of your program :

showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
	'use strict';
	text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals);
	
	for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
		var repText = globals.gHtmlSpans[i],
		// limiter to prevent infinite loop (assume 10 as limit for recurse)
		limit = 0;
	
		while (/¨C(\d+)C/.test(repText)) {
			var num = RegExp.$1;
			repText = repText.replace('¨C' + num + 'C', globals.gHtmlSpans[num]);
                        // Whatever limit you want (e.g. 20)
			if (limit === 20) {
				console.error('new limit of 20 spans reached!!!');
				break;
			}
			++limit;
		}
		text = text.replace('¨C' + i + 'C', repText);
	}
	
	text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals);
	return text;
});

It will overwrite the default method and so use your limit instead. P.S. : Yes... I know this post is inactive since 2020 lol

amolinarius avatar Feb 09 '24 19:02 amolinarius