{"size": 1785, "ext": "js", "max_stars_repo_path": "filters/billy-bob-space-trucker.js", "max_stars_repo_name": "PTST/hfy_wiki_to_epub", "max_stars_repo_stars_event_min_datetime": "2018-08-09T02:26:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-13T12:01:05.000Z", "max_issues_repo_path": "filters/billy-bob-space-trucker.js", "max_issues_repo_name": "PTST/hfy_wiki_to_epub", "max_issues_repo_issues_event_min_datetime": "2018-09-15T16:01:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-01T22:30:03.000Z", "max_forks_repo_path": "filters/billy-bob-space-trucker.js", "max_forks_repo_name": "PTST/hfy_wiki_to_epub", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 23.8, "max_line_length": 79, "alphanum_fraction": 0.5619047619}
function apply(params, next)
{
    var chap = params.chap;
	var $ = chap.dom;
	var c_re = /^ *Chapitre [a-z,A-Z,-]*\.*\n*/g;
	var rem = [];
	
	// Remove spurious chapter headings without removing body text that may
	// share an enclosing paragraph with the heading.
	$('p').each(function(i, e)
 	{
		var cont = $(e).contents();
		
		for(var i = 0; i < cont.length; i++)
		{
			var c = cont[i];
			
			if(c.type === 'text' && c.data.search(c_re) > -1)
				c.data = c.data.replace(c_re, '');
		}
 	});
 		
	// Harmonize catch-phrase formatting.
	if(chap.title === 'Un' || chap.title === 'Deux')
		$('pre').replaceWith($('<p><strong>Billy-Bob Space Trucker</strong></p>\n'));
	else if(chap.title === 'Trois')
		$.root().find('p strong').text('Billy-Bob Space Trucker');
	else if(chap.title === 'Dix-sept')
		rem.push($($('p:contains("Edit I hates they spelling yarr")')[0]));
	else if(chap.title === 'Dix-huit')
	{
		rem.push($($('p:contains("Edit fix: Got overzealous with copy paste")')[0]));
		rem.push($($('p:contains("Edit. Thought and FLT")')[0]));
	}
	else if(chap.title === 'Falling from on high')
	{
		var fp = $('p').first();
		
		fp.text(fp.text().replace(/Falling from on high\n/, ''));
	}
	
	// Filter various pre- and postamble paragraphs.
	var prune = {
		'Dix-sept': [0, 1],
		'Dix-neuf': [0, 1],
		'Vingt-et-un': [1, 0],
		'Vingt-deux': [1, 0],
		'Vingt-Six': [0, 1],
		'Vingt-Sept': [4, 1],
		'Trente-Cinq première partie': [0, 1],
		'Trente-cinq deuxième partie': [1, 0]
	};
	
	if(chap.title in prune)
	{
		var pr = prune[chap.title];
		var ps = $('p');
	
		for(var i = 0; i < pr[0]; i++)
			rem.push($(ps[i]));
		
		for(var i = ps.length - pr[1]; i < ps.length; i++)
			rem.push($(ps[i]));
	}
	
	params.purge(rem);
	
	next();
}

module.exports =
{
    apply: apply
};
