-
Notifications
You must be signed in to change notification settings - Fork 19
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
Changes from all commits
dfa5e04
1055b93
5853c58
78a0b5e
0513046
490f222
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,7 @@ div { | |
img { | ||
width: 100%; | ||
} | ||
|
||
pre { | ||
word-wrap: break-word; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,7 @@ div { | |
img { | ||
width: 100%; | ||
} | ||
|
||
pre { | ||
word-wrap: break-word; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,7 @@ div { | |
img { | ||
width: 100%; | ||
} | ||
|
||
pre { | ||
word-wrap: break-word; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
namespace Journaley.Utilities | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// Helper class for fixing MarkdownDeep parsed HTML. | ||
/// </summary> | ||
public class PostMarkdownParser | ||
{ | ||
/// <summary> | ||
/// Perform fixes after MarkdownDeep parsing for publishing | ||
/// to Journaley. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to be more explicit here and say what it fixes.
|
||
/// - automatically adds break tags on single line breaks. | ||
/// - makes the first sentence into a header. | ||
/// - properly parses code blocks enclosed in p tags into pre. | ||
/// </summary> | ||
/// <param name="formattedString">Formatted HTML string</param> | ||
/// <returns>Properly formatted HTML string for publishing.</returns> | ||
public static string PostMarkdown(string formattedString) | ||
{ | ||
StringBuilder builder = new StringBuilder(); | ||
StringBuilder paragraphBuilder = new StringBuilder(); | ||
|
||
// -1 - skips check and just dumps the line to builder. | ||
// 0 - stumbles upon the beginning of a <p> tag/usual parsing. | ||
// 1 - stumbles upon the end of </p> tag. | ||
var parseState = -1; | ||
|
||
string line; | ||
using (StringReader reader = new StringReader(formattedString)) | ||
{ | ||
while ((line = reader.ReadLine()) != null) | ||
{ | ||
if (line.Contains("<p>")) | ||
{ | ||
parseState = 1; | ||
} | ||
else if (line.Contains("</p>")) | ||
{ | ||
parseState = 0; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an else
{
paragraphBuilder.Add(line + "<br />");
} I thought about this for a while, and I think this is the perfect place to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you thought this after I clarified to you about how the regex worked right? |
||
else if (line.Contains("<pre>")) | ||
{ | ||
parseState = -1; | ||
} | ||
|
||
if (parseState == 1) | ||
{ | ||
if (line.Contains("</p>")) | ||
{ | ||
builder.AppendLine(line); | ||
parseState = -1; | ||
} | ||
else | ||
{ | ||
paragraphBuilder.AppendLine(line + "<br />"); | ||
} | ||
} | ||
else if (parseState == 0) | ||
{ | ||
paragraphBuilder.AppendLine(line); | ||
|
||
string paragraph = paragraphBuilder.ToString(); | ||
|
||
builder.Append(paragraph); | ||
paragraphBuilder.Clear(); | ||
parseState = -1; | ||
} | ||
else | ||
{ | ||
builder.AppendLine(line); | ||
} | ||
} | ||
} | ||
|
||
return builder.ToString(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these two options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the website:
Extramode is needed, becuase most of the implementations in Day One uses Markdown Extra stuff like tables and footnotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. We might want to turn on the SafeMode option later for resolving #118. Let's keep this false for now.