Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2429 from vector-im/feature/codeblock
Browse files Browse the repository at this point in the history
Messages with code blocks show other HTML as plain text (#2280)
  • Loading branch information
bmarty committed Jul 16, 2018
2 parents 0d6769f + e5d59c3 commit c0a12c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Bugfix:
- Fix issue when selecting sound for notifications in the settings
- Fix issue when changing device name in the settings (#2416)
- Fix issue on verifying device, update the wording of the description message (#1067)
- Messages with code blocks show other HTML as plain text (#2280)

Translations:
-
Expand Down
23 changes: 14 additions & 9 deletions vector/src/main/java/im/vector/adapters/VectorMessagesAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1336,14 +1336,11 @@ private List<TextView> populateRowTypeCode(final Message message,
String minusTags = block
.substring(VectorMessagesAdapterHelper.START_FENCED_BLOCK.length(),
block.length() - VectorMessagesAdapterHelper.END_FENCED_BLOCK.length())
.replace("\n", "<br/>")
.replace(" ", "&nbsp;");
.trim();
final View blockView = mLayoutInflater.inflate(R.layout.adapter_item_vector_message_code_block, null);
final TextView tv = blockView.findViewById(R.id.messagesAdapter_body);

CharSequence sequence = mHelper.convertToHtml(minusTags);

tv.setText(sequence);
tv.setText(minusTags);

mHelper.highlightFencedCode(tv);

Expand All @@ -1359,14 +1356,22 @@ private List<TextView> populateRowTypeCode(final Message message,

String block2 = block;
if (TextUtils.equals(Message.FORMAT_MATRIX_HTML, message.format)) {
String sanitased = mHelper.getSanitisedHtml(block2);
// Preserve space and new lines
block2 = block2
.trim()
.replace("\n", "<br/>")
.replace(" ", "&nbsp;");

String sanitized = mHelper.getSanitisedHtml(block2);

if (sanitased != null) {
block2 = sanitased;
if (sanitized != null) {
block2 = sanitized;
}
}

CharSequence strBuilder = mHelper.highlightPattern(new SpannableString(block2),
CharSequence sequence = mHelper.convertToHtml(block2);

CharSequence strBuilder = mHelper.highlightPattern(new SpannableString(sequence),
mPattern,
mBackgroundColorSpan,
shouldHighlighted);
Expand Down

0 comments on commit c0a12c8

Please sign in to comment.