Skip to content
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

Added markdown string preprocessing to include CRLF carriage returns #2055

Merged
merged 3 commits into from
Jun 5, 2019

Conversation

tdurnford
Copy link
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