Skip to content

Added markdown string preprocessing to include CRLF carriage returns#2055

Merged
corinagum merged 3 commits intomicrosoft:masterfrom
tdurnford:1429
Jun 5, 2019
Merged

Added markdown string preprocessing to include CRLF carriage returns#2055
corinagum merged 3 commits intomicrosoft:masterfrom
tdurnford:1429

Conversation

@tdurnford
Copy link
Copy Markdown
Contributor

@tdurnford tdurnford commented Jun 5, 2019

Related to #1429

Changelog Entry

  • Fix #1429. Added markdown string preprocessing so the renderer will respect CRLF carriage returns (\r\n) , by @tdurnford in PR #2055

Description

Web Chat's default markdown renderer - Markdown-it - does not respect CRLF carriage returns. So, each time an activity is received with a CRLF carriage return, Web Chat renders it as a newline character instead of as a carriage return.

Current Behavior

renderMarkdown('Same Line.\n\rSame Line.\r\n2nd line.')
<p>Same Line.</p>
<p>Same Line.
2nd line.</p>

Expected Behavior

renderMarkdown('Same Line.\n\rSame Line.\r\n2nd line.')
<p>Same Line.
Same Line.</p>
<p>2nd line.</p>

Specific Changes

I added a boolean value - markdownRespectCRLF - to the default style options and set the value to true so clients can choose between CRLF and LFCR carriage returns.

I also added the style options as a parameter to the render markdown function and logic to respect either LFCR or CRLF carriage returns based on the markdownRespectCRLF value. If the value is false, the function passes the markdown string to renderer because the renderer already respects LFCR carriage returns; otherwise, the function processes the string prior to rendering it.

The preprocessing step takes advantage of the fact that the markdown renderer already respects LFCR carriage returns and disrespect CRLF. Subsequently, to achieve the converse behavior, we can swap CRLF and LFCR so the renderer will respect CRLF carriage returns and disrespect LFCR carriage returns.

if (markdownRespectCRLF) {
  markdown = markdown.replace(/\n\r|\r\n/g, carriageReturn => carriageReturn === '\n\r'? '\r\n': '\n\r');
}

  • Testing Added

@tdurnford tdurnford marked this pull request as ready for review June 5, 2019 21:54
@corinagum corinagum merged commit 1dfcf90 into microsoft:master Jun 5, 2019
@tdurnford tdurnford deleted the 1429 branch June 5, 2019 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown render texts in single paragraph into two lines

2 participants