This repository was archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
Code block support #206
Merged
Merged
Code block support #206
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c01232
Code block support
AndreyAkinshin 0e5338f
YamlExtensions.ExcludeHeader refactoring
AndreyAkinshin d6fcbfc
Merge remote-tracking branch 'origin/master' into code-block-support
AndreyAkinshin b0cd24c
YamlExtensions.ExcludeHeader refactoring, part 2
AndreyAkinshin d8b7481
Change Markdown processor: MarkdownDeep -> CommonMark.NET
AndreyAkinshin 614143f
Update markdown tests to CommonMark Spec v0.17
AndreyAkinshin accfb80
Update Luquid and Razor examples to CommonMark Spec v0.17
AndreyAkinshin cbf2abd
Change prettyprint+jQuery to highlightjs via CDN in examples
AndreyAkinshin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using MarkdownDeep; | ||
|
||
namespace Pretzel.Logic.Helpers | ||
{ | ||
public static class MarkdownHelper | ||
{ | ||
public static Markdown CreateMarkdown() | ||
{ | ||
return new Markdown { FormatCodeBlock = FormatCodePrettyPrint }; | ||
} | ||
|
||
// Original code: http://www.toptensoftware.com/Articles/83/MarkdownDeep-Syntax-Highlighting | ||
public static Regex rxExtractLanguage = new Regex("^({{(.+)}}[\r\n])", RegexOptions.Compiled); | ||
|
||
public static string FormatCodePrettyPrint(Markdown m, string code) | ||
{ | ||
// Try to extract the language from the first line | ||
var match = rxExtractLanguage.Match(code); | ||
string language = null; | ||
|
||
if (match.Success) | ||
{ | ||
// Save the language | ||
var g = (Group)match.Groups[2]; | ||
language = g.ToString(); | ||
|
||
// Remove the first line | ||
code = code.Substring(match.Groups[1].Length); | ||
} | ||
|
||
// If not specified, look for a link definition called "default_syntax" and | ||
// grab the language from its title | ||
if (language == null) | ||
{ | ||
var d = m.GetLinkDefinition("default_syntax"); | ||
if (d != null) | ||
language = d.title; | ||
} | ||
|
||
// Common replacements | ||
if (language == "C#") | ||
language = "cs"; | ||
if (language == "C++") | ||
language = "cpp"; | ||
|
||
// Wrap code in pre/code tags and add PrettyPrint attributes if necessary | ||
if (string.IsNullOrEmpty(language)) | ||
return string.Format("<pre><code>{0}</code></pre>\n", code); | ||
else | ||
return string.Format("<pre class=\"prettyprint lang-{0}\"><code>{1}</code></pre>\n", | ||
language.ToLowerInvariant(), code); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,6 @@ | |
</div> | ||
|
||
</div> | ||
<script src="js/run_prettify.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,6 @@ | |
</div> | ||
|
||
</div> | ||
<script src="js/run_prettify.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could this be done in a more LINQ-friendly way?
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.
You can't remove empty line in the middle of the text. My
while
removes only first empty lines. So,SkipWhile
is needed. I will fix it.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.
Good point, 👍 to
SkipWhile
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.
Done (commit 0e5338f)