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

Improved Multi-Line Quoting, you can now separate two quotes. #1974

Merged

Conversation

WilliamABradley
Copy link
Contributor

@WilliamABradley WilliamABradley commented Apr 14, 2018

-Updated InitialContent with some examples.

Issue: #1761

Testing with:

>Quote1

>Quote2.1
>>Quote2.Nest1.1
>>
>>Quote2.Nest1.2
>
>Quote2.3

>Quote3.1
>Quote3.2

>Quote4.1
>
>Quote4.2

>Quote5.1
Quote5.2

>Quote6

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

image

What is the new behavior?

image

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template. (for bug fixes / features)
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

The current implementation is a bit of a selection of different styles, as all Renderers differ in their results, this discussion can be continued to determine a better conformance if need be:

  • StackEdit

    image

  • GitHub

    image

  • CommonMark.js

    image

  • Reddit

    image

  • Dillinger.io

    image

  • VS Code

    image

-Updated InitialContent with some examples.
@WilliamABradley
Copy link
Contributor Author

It is one line away from CommonMark conformance, but it means that a Quote can't go back to indentation 1 after going up to indentation 2.

@Vijay-Nirmal
Copy link
Contributor

I think CommonMark is the expected output.

@WilliamABradley You can come back to outer Quote. Try this

> Quote2.1
>>Quote2.Nest1.1
 >Quote2.Nest1.2
>
> Quote2.2

Output

chrome_2018-04-14_10-04-35

And multiline for nested Quote would be

> Quote2.1
>>Quote2.Nest1.1
 >Quote2.Nest1.2
>>
>>Quote2.Nest1.3
>
>Quote2.2

Output

chrome_2018-04-14_10-07-26

else if (paragraphText.Length > 0 && ((markdown[startOfLine - 2] == '>' || markdown[startOfLine - 1] == '>') || inQuoteNewLine))
{
// If the start of the line is a QuoteBlock, and the Paragraph has already been started, Create a new line.
paragraphText.Append("\r\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Environment.NewLine?

@@ -96,6 +96,9 @@ internal static List<MarkdownBlock> Parse(string markdown, int start, int end, i
int previousStartOfLine = start;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parse method seems really large, do we have a work item to split it up into other methods that we can more easily unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would likely happen if we go through with #1767

@@ -154,7 +157,16 @@ internal static List<MarkdownBlock> Parse(string markdown, int start, int end, i
// But it doesn't matter if this is not the start of a new paragraph.
if (!lineStartsNewParagraph || nonSpaceChar == '\0')
{
break;
// Continue the Quote if the previous line was a quote.
if (((previousStartOfLine - 2) >= 0 && markdown[previousStartOfLine - 2] == '>') || ((previousStartOfLine - 1) >= 0 && markdown[previousStartOfLine - 1] == '>'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are spaces allowed before the >? Or is there a trim somewhere?

@@ -277,6 +289,12 @@ internal static List<MarkdownBlock> Parse(string markdown, int start, int end, i
paragraphText[paragraphText.Length - 2] = '\r';
paragraphText[paragraphText.Length - 1] = '\n';
}
else if (paragraphText.Length > 0 && ((markdown[startOfLine - 2] == '>' || markdown[startOfLine - 1] == '>') || inQuoteNewLine))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a bounds check here as well?

@WilliamABradley
Copy link
Contributor Author

I updated my test markdown, and I have been attempting to mimic CommonMark, it is nearly done, however, I am struggling to get the Parser to go back out of the nest after a nest, as you can see from the new behavior image.

Quote2.3 should be part of the rest of Quote2.

/// <param name="searchString">String to search through</param>
/// <param name="toFind">Substring to find</param>
/// <returns>Number of times the substring occurs</returns>
public static int Occurrences(this string searchString, string toFind)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this method is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure it does what it's being documented. Why are you checking every character in toFind with every character in searchString?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the current logic only works in the single character case (which is how it's used in the PR). If we want a function like this, we should add unit tests and make sure it works for the other scenarios. Though it'd probably be easier/faster to use the built-in IndexOf or Split methods to do this, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@WilliamABradley
Copy link
Contributor Author

@michael-hawker @nmetulev Fixed the CommonMark conformance issue, this is now ready for review.

Copy link
Contributor

@Vijay-Nirmal Vijay-Nirmal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line Break is not working when we have nested quotes.

>> Quote 1

>> Quote 2

This is displayed as

applicationframehost_2018-05-06_14-38-47

But It should be displayed as

chrome_2018-05-06_14-39-25

@WilliamABradley
Copy link
Contributor Author

@Vijay-Nirmal fixed that issue, let me know if you discover any more. It is pretty mind bending logic.

@nmetulev
Copy link
Contributor

@Vijay-Nirmal, up to you now.

@nmetulev nmetulev merged commit da110ef into CommunityToolkit:master May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants