-
Notifications
You must be signed in to change notification settings - Fork 2
Remove html filter #19
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
base: master
Are you sure you want to change the base?
Remove html filter #19
Conversation
|
You need to add parsing to catch open tags. With this change as-is, I can write: <font face="Comic Sans MS">and deliberately not include the closing Alternatively, you could choose the sane option and not remove the HTML filter, which is there for a reason. |
Crystalwarrior
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PLEASE descriptive descriptions I beg
src/aotextarea.cpp
Outdated
| QString result = p_message.toHtmlEscaped() | ||
| .replace("\n", "<br>") | ||
| .replace(url_parser_regex, "<a href='\\1'>\\1</a>"); | ||
| QString result = p_message.replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to close all open HTML tags to prevent the Comic Sans disaster
src/aotextarea.cpp
Outdated
| std::string AOTextArea::closetags(std::string html) | ||
| { | ||
| std::regex opened_regex(R"(<([a-z]+)(?: .*)?(?<![/|/ ])>)", | ||
| std::regex_constants::icase); | ||
| std::regex closed_regex(R"(</([a-z]+)>)", std::regex_constants::icase); | ||
|
|
||
| std::vector<std::string> openedtags; | ||
| std::vector<std::string> closedtags; | ||
| std::smatch match; | ||
|
|
||
| std::string::const_iterator search_start(html.cbegin()); | ||
| while (std::regex_search(search_start, html.cend(), match, opened_regex)) { | ||
| openedtags.push_back(match[1]); | ||
| search_start = match.suffix().first; | ||
| } | ||
|
|
||
| search_start = html.cbegin(); | ||
| while (std::regex_search(search_start, html.cend(), match, closed_regex)) { | ||
| closedtags.push_back(match[1]); | ||
| search_start = match.suffix().first; | ||
| } | ||
|
|
||
| size_t len_opened = openedtags.size(); | ||
|
|
||
| if (closedtags.size() == len_opened) { | ||
| return html; | ||
| } | ||
|
|
||
| std::reverse(openedtags.begin(), openedtags.end()); | ||
| for (size_t i = 0; i < len_opened; i++) { | ||
| auto it = std::find(closedtags.begin(), closedtags.end(), openedtags[i]); | ||
| if (it == closedtags.end()) { | ||
| html += "</" + openedtags[i] + ">"; | ||
| } | ||
| else { | ||
| closedtags.erase(it); | ||
| } | ||
| } | ||
| return html; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you rewrite this to use the Qt functions rather than std:: ones? we must be breaking some kind of convention somewhere by doing it this way lol
src/aotextarea.cpp
Outdated
| QString result = p_message.toHtmlEscaped() | ||
| .replace("\n", "<br>") | ||
| .replace(url_parser_regex, "<a href='\\1'>\\1</a>"); | ||
| QString result = QString::fromStdString(this->closetags(p_message.replace("\n", "<br>").toStdString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
funny conversion to std:: moment, doesn't Qt have its own version of regex?
https://doc.qt.io/qt-5/qregexp.html#details
include/aotextarea.h
Outdated
| void append_chatmessage(QString p_name, QString p_message, | ||
| QString p_name_colour, QString p_color = QString()); | ||
| void append_error(QString p_message); | ||
| std::string closetags(std::string html); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use QString instead of std::string?
Crystalwarrior
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, now time to test
| QString result = this->closetags(p_message); | ||
| result = result.replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For url parse regex we'll need to not do that if it's already handled via html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closeTags is not doing its job at least for centering
| html = html + expected_closetag; | ||
| } | ||
| } | ||
| return html; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.


Removing html filter, to allow users to use bold, italic, colors ecc... in ooc message