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

For evaluation: Implementation of MarkdownDeep.net over Journaley. #129

Merged
merged 6 commits into from
Nov 26, 2015

Conversation

crxtrdude
Copy link
Contributor

Replaced MarkdownSharp with MarkdownDeep.net. Has better compatibility with some Markdown features that Day One supports including Markdown Extra features (tables and footnotes for one), although there are some certain things it doesn't have. That's where fixes comes in, the most important is for single line breaks.

For more information, refer to the commits for details.

- Replaced MarkdownSharp with MarkdownDeep.net. Has better compatibility with some Markdown features that Day One supports
- Added a fix for single line breaks that isn't implemented in MarkdownDeep. Note that this needs some optimization.
string formattedString = string.Format(
"<style type=\"text/css\">\n<!-- Font CSS -->\n{0}\n<!-- Size CSS -->\n{1}\n<!-- Custom CSS -->\n{2}\n</style><html><body><div>{3}</div></body></html>",
"<style type=\"text/css\">\n<!-- Font CSS -->\n{0}\n<!-- Size CSS -->\n{1}\n<!-- Custom CSS -->\n{2}\n</style>\n<html>\n<body>\n<div>\n{3}\n</div>\n</body>\n</html>",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added proper line breaks for the tags.

- Transferred the fix into its own helper class, PostMarkdownParser.
- Added fixes for strikethroughs and backtick code blocks (converting the <p> tagged code into <pre>).
- Added a DOCTYPE on the formatted HTML string to make the HTML parsed HTML 4 strict.
@crxtrdude crxtrdude changed the title Initial implementation of MarkdownDeep.net over Journaley. Implementation of MarkdownDeep.net over Journaley. Nov 24, 2015
@@ -97,7 +97,9 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\StyleCop.MSBuild.4.7.48.2\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\StyleCop.MSBuild.4.7.48.2\build\StyleCop.MSBuild.Targets'))" />
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
Copy link
Owner

Choose a reason for hiding this comment

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

Was there a particular reason to change this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really don't know. I think this was when I enabled Nuget Package Recovery in VS.

Copy link
Owner

Choose a reason for hiding this comment

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

No, you shouldn't enable that in the solution. In fact, it turns out these changes (in Journaley.Core, Journaley, VersionExtractor) broke the build on my side. Please remove these lines from all the affected projects.

You should just go to Tools -> Options... -> NuGet Package Manager -> General and check both the Allow NuGet to download missing packages and Automatically check for missing pakcages during build in Visual Studio options. The solution should build fine after enabling these options. If not, let's troubleshoot that together later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll reset my repo and I'll do this again. I'll message you if it worked with just removing the code first.

- Improved PostMarkdown function as suggested by @yyoon.
- Reverted screwed up csproj files due to Nuget Package Recovery.
- Modified docType string to use HTML5 DOCTYPE standard.
- Minor fixes.
// 2 - stumbles upon a <pre> tag.
var parseState = 0;

string newLineString;
Copy link
Owner

Choose a reason for hiding this comment

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

  1. Declare this variable when its used in line 86. This makes it easier to understand the code, because the scope of this variable is actually within the else if (parseState == 0) block. It is fine for the other variables like builder, paragraphBuilder, and parseState, because their state persists over the loops.
  2. Let's rename this to paragraph, because it is a better name, it comes from the paragraphBuilder, and the name newLineString can be misleading because it usually refers to \r\n or some other platform dependent newline string.

@yyoon
Copy link
Owner

yyoon commented Nov 25, 2015

Another issue I noticed: when playing with your test file, I found that the entry area shows nested scrollbars like this:

image

This happens because now we use the <pre> tag for the fenced code, and it doesn't wrap the line by default. We can fix this behavior by adding the CSS.

pre {
    word-wrap: break-word;
}

Please add this to all three css files (small, medium, large).

@crxtrdude crxtrdude changed the title Implementation of MarkdownDeep.net over Journaley. For evaluation: Implementation of MarkdownDeep.net over Journaley. Nov 25, 2015
@yyoon
Copy link
Owner

yyoon commented Nov 25, 2015

Okay. That makes sense to me.


// 0 - stumbles upon the beginning of a <p> tag/usual parsing.
// 1 - stumbles upon the end of </p> tag.
// 2 - skips check and just dumps the line to builder.
Copy link
Owner

Choose a reason for hiding this comment

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

I think you meant to say -1 here, not 2.

@crxtrdude
Copy link
Contributor Author

The reason for those two lines is because of something like this:
Supposed you got something like this:

~~Line 1
Line 2
Line 3~~

Obviously it's expected like this:

<p><del>Line 1
Line 2
Line 3<del><p>

Which is what GFM and Day One renders:
Line 1
Line 2
Line 3

For this kind of paragraph, that's why I added those 2 lines on this case.

@crxtrdude crxtrdude closed this Nov 25, 2015
@crxtrdude
Copy link
Contributor Author

Why do I always press the first button ...

But anyway, I did agree with passing Strikethrough in paragraph, which did work on my side.

@crxtrdude crxtrdude reopened this Nov 25, 2015
@yyoon
Copy link
Owner

yyoon commented Nov 25, 2015

I understand why you did that, but I still think it was incorrect for a few reasons.

First, it wouldn't necessarily match the opening / closing strikethrough mark pairs.
Take the following example.

~~Line1
Line2
Line3

GitHub renders it as:

~~Line1
Line2
Line3

, because there is no closing ~~ mark at the end.

However, the current code seems like it would just add the opening <del> and then never close it.
Processing the opening / closing mark separately will cause all sorts of this problems.

Second, it seems to me that it would only handle the ~~ marks that appear right after <p> and right before </p> am I right? This may not be able to handle the following case:

Normal text ~~strikethrough
should be applied here~~ and not here.

GitHub renders it as:

Normal text strikethrough
should be applied here
and not here.

, but I think our previous code would probably not handle this correctly.

These are the reasons why I suggested to process at the paragraph level, not at the line level.

@crxtrdude
Copy link
Contributor Author

The code I'm doing (not commited yet) is now processing it on the paragraph level now. I switched every line process over to paragraph level.

Your second example BTW, has not been rendered on Github, but it does render it on Day One and since we need to be as close to day one as possible, I might need to have a intelligent way of doing this.

@crxtrdude crxtrdude closed this Nov 25, 2015
@crxtrdude
Copy link
Contributor Author

Why does the button for closing a PR is the one I always push? It's getting my nerves a bit.

@crxtrdude crxtrdude reopened this Nov 25, 2015
@yyoon
Copy link
Owner

yyoon commented Nov 25, 2015

I guess space between ~~ and the text matters:

Normal text ~~strikethrough
should be applied here~~ and not here.

Normal text strikethrough
should be applied here
and not here.

Normal text ~~ strikethrough
should be applied here~~ and not here.

Normal text ~~ strikethrough
should be applied here~~ and not here.

@crxtrdude
Copy link
Contributor Author

I managed to actually successfully implement it. I will update our Test Syntax to reflect some of these changes. I'll commit it now.

@crxtrdude
Copy link
Contributor Author

On second thought, there are problems that are going on. I'll fix this tomorrow morning.

- Removed strikethrough support for now until we can find a way to do it properly (preferably not using Regex).
- Single line breaks are now properly added.
- Uses StringReader instead of a foreach loop in reading the string.
- Backticked code blocks is now properly parsed into <pre> tags.
@crxtrdude
Copy link
Contributor Author

Here's the (hopefully last) implementation of PostMarkdown. I removed strikethrough support for now, because there are a lot of things to consider, but what I wanted to make sure was the other parts, especially single line breaks, are implemented.

If we commit this now, with little to no changes, we'll just add the strikethrough problem as an issue and then work on it incrementally.

- Since we are doing this upon render time, just replace the backticks into tildes instead to make it properly render HTML tags that might be used (HTML is still considered parsed despite converting the <p> tags to <pre>).
@crxtrdude
Copy link
Contributor Author

Sorry, I need to do a followup for this one. Apparently, parsing backtick fenced code blocks post markdown would not escape HTML tags.

This is like similar to what I said (I think I said it) where <br /> could be used inside a <code> block and it will render a newline.

That's why in this fix, instead of having to fight MarkdownDeep, I'll just convert the backtick fence into a tilde fence, that way it would be transformed properly as it is intended. The user's file of course is not affected by it since I only change it on UpdateWebBrowser only.

I'll find a way to do this programmatically on PostMarkdown properly, but the priority here is making the single line break work.

@yyoon
Copy link
Owner

yyoon commented Nov 26, 2015

Looks good to me. Thanks!

yyoon added a commit that referenced this pull request Nov 26, 2015
Implementation of MarkdownDeep.net over Journaley.
@yyoon yyoon merged commit 85e765d into yyoon:develop Nov 26, 2015
@crxtrdude crxtrdude deleted the feature/markdown_deep_2 branch November 27, 2015 02:22
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.

2 participants