-
Notifications
You must be signed in to change notification settings - Fork 55
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
Escape html special characters in completions #73
Comments
Hi, can I ask you how? I tried putting string like "\\<" but doesn't works. |
You have to replace the special characters by corresponding html entities. For examlpe |
Ok thanks, it works on choices list but the autocomplete string now is "& l t ;" instead of "<" |
Yeah, I doubt I wrote this down anywhere but most/all of the completion cell renderers and popup windows default to HTML input. It's expected that you supply HTML content to the API to facilitate structured content in e.g. the description window (lists, tables, etc.). As for the cell renderers, I believe you can override this HTML behavior. It's been a while but I believe you can supply any CellRenderer you want. One supporting HTML is used by default but in my experience that renderer performs quite poorly for huge completion lists (due to Swing's HTML rendering and sizing calculations). I think I do this somewhere - let me dig up an example. All that said, if there are ways the API can be improved let me know. I'm not necessarily against letting consumers specify a content type for e.g. the description window (text/plain vs. text/html for example), but I don't want to pollute the API unnecessarily. Suggestions welcome. |
My goal is to let the completions (like FunctionCompletion) be a model that just contain the plain text, not the html encoded strings. That way it is easier to build those instances. And one could argue that view stuff (like encoding strings for display) should be done in the UI layer and not in the model/data layer. In my opinion this string encoding is mainly needed for variable types, function parameter types, and function result types. I am already using a CompletionCellRenderer and peeked into its code to check if a custom subclass can do what I want. And the second affected class is the AutoCompleteDescWindow. If the cell renderer auto-encodes model string values for html, that class must do so too. That class and its construction is private and thus I can't create my own subclasses. In the end, I'm not sure what the best solution would be if you do not want to include the html entity encoding into your code in an always-on way. And that solution may not be backwards compatible with the way the classes are currently used in the world. I can live with my workaround. This was mainly meant as a improvement suggestions. Mainly because generating html without escaping special characters in the raw source strings is "an error". |
Yeah I get it, thanks for the suggestions. I'll ponder this when I get some time. |
The cell renderer used for the completion popup window and the code to set the content of the description window should mask/escape characters that are special to html.
I'm using the
RSyntaxTextArea
withAutoComplete
for a Java-like language and created aCompletionProvider
that can return type strings with generic parameters. For example the propertytype
of aVariableCompletion
can beList<String>
or something similar.In such cases, both the cell renderer and the description window, the characters
<
and>
has to be escaped by the corresponding html entities<
and>
. Otherwise the html renderer interprets it as tag and simply does not output the string between those characters.So far I'm working around this by escaping the strings before filling the
VariableCompletion
. But I thing that is something that should be done by the view layer and not by the model elements.Would be nice to add this to those classes - and other places that I might not have found yet.
The text was updated successfully, but these errors were encountered: