Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow an array for the q parameter instead of a string in the accent_folded_hilite function #5

Open
trifacho opened this issue Feb 19, 2019 · 0 comments

Comments

@trifacho
Copy link

Hi.

I'm using your javascript code in a project and I have make some changes. I paste the top of the function with the changes.

// accent_folded_hilite("Fulanilo López", 'lo')
//	 --> "Fulani<b>lo</b> <b>Ló</b>pez"
//
function accent_folded_hilite(str, q) {
	var str_folded = accent_fold(str).toLowerCase().replace(/[<>]+/g, '');
	// ORIGINAL CODE THAT ONLY ALLOW A STRING
	// var q_folded = accent_fold(q).toLowerCase().replace(/[<>]+/g, '');
	// MODIFIED CODE TO ALLOW AN ARRAY INSTEAD OF A STRING
	var q_folded=[];
	for(var i in q) {
		q_folded[i]=accent_fold(q[i]).toLowerCase().replace(/[<>]+/g, '');
	}

	// create an intermediary string with hilite hints
	// example: fulani<lo> <lo>pez
	// ORIGINAL CODE THAT ONLY ALLOW A STRING
	// var re = new RegExp(q_folded, 'g');
	// var hilite_hints = str_folded.replace(re, '<'+q_folded+'>');
	// MODIFIED CODE TO ALLOW AN ARRAY INSTEAD OF A STRING
	var hilite_hints = str_folded;
	var re = null;
	for(var i in q) {
		re = new RegExp(q_folded[i], 'g');
		hilite_hints=hilite_hints.replace(re, '<'+q_folded[i]+'>');
	}
.
.
.

You can see the project here: https://trifacho.github.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant