BUG Fix: use HTML value to replace HTML - #97
Conversation
|
Hi @JoshuaFortriede - thanks for the PR. It also partly obscures the commit/blame history of the file. If you want to re-format the file in a follow-up commit, perhaps you can add that commit to a file as described in https://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/ Thanks |
480d377 to
3854f1c
Compare
|
Yes, sorry about that. I saved without my linting and the new commit is there. |
| var _url = location.protocol + "//" + location.host + "{% url 'maprindex' %}" + keys2menu[_key] +"/?value=" + encodeURIComponent(_val); | ||
| $chvalue.html($chvalue.html().replace(_val, '<a href="' + _url + '">' + _val + '</a>')); | ||
| // replace the original HTML value with a link to the internal mapr URL | ||
| $chvalue.html($chvalue.html().replace(_valHTML, '<a href="' + _url + '">' + _val + '</a>')); |
There was a problem hiding this comment.
Thanks for that.
Since _valHTML is the same as $chvalue.html(), this is equivalent to
_valHTML.replace(_valHTML, '<a href="' + _url + '">' + _val + '</a>')
which is equivalent to
'<a href="' + _url + '">' + _val + '</a>'
Maybe I'm just missing something in the reading of this (without running it)?
I need to get omero-mapr set up on our test server so we can test this and #98..
The original code used the text value of the element when replacing within the HTML. This causes problems when the value contains symbols such as "&" or ">". In these cases .text() != .html(). As such, the replacement won't work.
For instance, if I have a key of "Stain" and a value of "Hematoxylin & Eosin", the .text() of the value is "Hematoxylin & Eosin", but the .html() is "Hematoxylin & Eosin". As such running the replace will not work, and thus will not create the MAPR url.
Note: I do not believe this is the best fix. I think a cleaner approach is to rebuild the HTML entirely in coordination with the iconify function, but that is a bigger refactor.