-
-
Notifications
You must be signed in to change notification settings - Fork 604
-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
Filter: Html tags included in results #515
Comments
Thanks for reporting this. If we have a solution there, we might also extend the |
I have a solution. My solution is to use the renderNode event and either strip the In my controller I generate the node title....
then the code for the tree.
I split the highlight title on the first
Note that this is not perfect as there are some orphaned folders. I also have no idea as to how this will impact performance. See this as a starting point. mar10, many thanks for an awesome control. |
Not perfect as searching for S , P, A or N on their own still breaks.... |
Updated the renderNode code. This allows searching for S , P, A or N and fixes js error due to removal of the node. Now just hide it instead.
In my app.css
|
cool if it works for you ;-) For a general solution I'd say we would need an approach that will prevent matching the markup parts. This will be even more difficult, if combined with the For applying the This might be possible, but I don't think it is high priority now. |
i use this workaround: var strip = function(html) {
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
// Default to 'match title substring (not case sensitive)'
if(typeof filter === "string"){
// console.log("rex", filter.split('').join('\\w*').replace(/\W/, ""))
if( filterOpts.fuzzy ) {
// See https://codereview.stackexchange.com/questions/23899/faster-javascript-fuzzy-string-matching-function/23905#23905
// and http://www.quora.com/How-is-the-fuzzy-search-algorithm-in-Sublime-Text-designed
// and http://www.dustindiaz.com/autocomplete-fuzzy-matching
match = filter.split("").reduce(function(a, b) {
return a + "[^" + b + "]*" + b;
});
} else {
match = _escapeRegex(filter); // make sure a '.' is treated literally
}
re = new RegExp(".*" + match + ".*", "i");
re2 = new RegExp(filter, "gi");
filter = function(node){
var res = !!re.test(strip(node.title));
// node.debug("filter res", res, filterOpts.highlight)
if( res && filterOpts.highlight ) {
node.titleWithHighlight = strip(node.title).replace(re2, function(s){
return "<mark>" + s + "</mark>";
});
// } else {
// delete node.titleWithHighlight;
}
return res;
};
} |
That looks promising, thanks! |
Hello @mar10 I was looking at
If we use this in the filter function, the Thanks! |
Does the strip() function that luk156 proposed work better? |
If you search using the filter usually the first letter will include results that have the same letter in the hidden html tags.
This can be clearly seen in the Filter example
http://wwwendt.de/tech/fancytree/demo/#sample-ext-filter.html
and enter "b" as the search term. The
<b>
tag of the html snippet is included. This should not be the case.The text was updated successfully, but these errors were encountered: