Skip to content

Commit

Permalink
Rendering spaces for markdown format. Fixes #596 (#775)
Browse files Browse the repository at this point in the history
* #764 making ja-jp consistent with other langs

#764 making ja-jp consistent with other langs

* Adding spaces directly without markdownIt rendering.

* Implementing text-empty test validation.

* Adding space character.
  • Loading branch information
Carlos Reyes authored and danmarshall committed Nov 17, 2017
1 parent 8c730fa commit dcb3b32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/FormattedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ const renderMarkdown = (
text: string,
onImageLoad: () => void
) => {
const src = text
let __html;

if (text.trim()) {
const src = text
// convert <br> tags to blank lines for markdown
.replace(/<br\s*\/?>/ig, '\r\n\r\n')
// URL encode all links
.replace(/\[(.*?)\]\((.*?)\)/ig, (match, text, url) => `[${text}](${markdownIt.normalizeLink(url)})`);
const __html = markdownIt.render(src);
__html = markdownIt.render(src);
} else {
// replace spaces with non-breaking space Unicode characters
__html = text.replace(/ */, '\u00A0');
}

return <div className="format-markdown" dangerouslySetInnerHTML={{ __html }} />;
}
9 changes: 9 additions & 0 deletions test/commands_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ var commands_map: CommandValuesMap = {
sendActivity(conversationId, server_content.receipt_card);
}
},
"text-empty": {
client: function () {
var last_message = document.querySelectorAll('.wc-message-wrapper:last-child .wc-message.wc-message-from-bot .format-markdown')[0];
return last_message.innerHTML === '&nbsp;';
},
server: function (conversationId, sendActivity) {
sendActivity(conversationId, server_content.text_empty_card);
}
},
"thumbnailcard": {
client: function () {
var source = document.querySelectorAll('img')[0].src;
Expand Down
13 changes: 13 additions & 0 deletions test/server_content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,19 @@ export var receipt_card: dl.Message = {
]
}

/*
* Activity for Text
*
*/
export var text_empty_card: dl.Message = {
type: "message",
from: bot,
timestamp: new Date().toUTCString(),
channelId: "webchat",
textFormat: "markdown",
text: " "
}

/*
* Activity for Thumbnail Card
*
Expand Down

0 comments on commit dcb3b32

Please sign in to comment.