This isn't a new post per-se, but a few refinements to our existing project, including added comments in the new classes, before proceeding further. I pretty much rushed through to getting content.
What? Markdown in your Razor code? Yeah…and it was totally easy to build too.
Generates HTML from Markdown, compiles to both Clojure and ClojureScript. Creates web pages or presentation slides. C# (CSharp) MarkdownSharp MarkdownOptions - 30 examples found. These are the top rated real world C# (CSharp) examples of MarkdownSharp.MarkdownOptions extracted from open source projects. You can rate examples to help us improve the quality of examples. Export a git repo as a markdown based html wiki. This will stop MarkdownSharp from re-encoding text in blocks of code. Just remember that HTML encodes your input before you pass it to markdown, not after. Virtualbox alternative for m1 mac. Another solution is to whitelist HTML tags such as Stack Overflow. You would do it AFTER you transfer your content to markdown.
Taylor Mullen demoed the idea of a Markdown Tag Helper idea at Orchard Harvest and I thought it would be nice to include this in my Tag Helper Samples project.
This tag helper allows you to write Markdown directly in Razor and have that automatically converted to HTML at runtime. There are 2 options for how to use this tag helper. The first option is to use a <markdown>
element.
The tag helper will take this and convert it to the following HTML:
The other option is to use a <p>
element that has the markdown attribute:
The tag helper uses MarkdownSharp, which supports most of the markdown syntax supported by Stack Overflow.
The implementation of this tag helper is surprisingly simple. All we do is grab the contents of the tag and use MarkdownSharp to convert that to HTML.
You can grab the code from GitHub or install the package using Nuget.
Install-Package TagHelperSamples.Markdown
Give it a try and let me know what you think.
Compatible
MarkdownDeep implements all the features defined by Markdown, and includes a comprehensive set of unit test cases to ensure this compatiblity is maintained.
Although MarkdownDeep produces equivalent HTML to other Markdown implementations, it makes noattempt to match the whitespace of those implementations. Also, it may escape some HTML entitiesdifferently (eg: "
instead of actual quote characters), but in the end the outputis equivalent.
Fast
The .NET version of MarkdownDeep is fast - typically 15x faster than MarkdownSharp.
The following benchmarks compare MarkdownDeep and MarkdownSharp. The same input files and iterations counts were used in both cases. The benchmark program and input files are included in the MarkdownDeep source code repository.
These tests are the same as those included in the MarkdownSharp code base however the iterations counts have been increased on the larger tests to get a more accurate measure. Also, an even larger, plain text (no markdown syntax) file has been added to the test.
Test | Input Length (chars) | MarkdownSharp (ms) | MarkdownDeep (ms) | Factor |
---|---|---|---|---|
markdown-example-short-1.text | 475 | 0.721 | 0.071 | x10.1 |
markdown-example-medium-1.text | 2,356 | 2.755 | 0.164 | x16.8 |
markdown-example-long-2.text | 27,737 | 30.2 | 1.58 | x19.11 |
markdown-readme.text | 11,416 | 14.3 | 1.3 | x11.0 |
markdown-readme.8.text | 91,342 | 114.7 | 6.2 | x18.5 |
markdown-readme.32.text | 365,374 | 450.0 | 26.2 | x17.2 |
long_plain_text.text | 698,880 | 453.8 | 29.1 | x15.6 |
Machine spec: 2009 13' MacBook Pro (Core 2 Duo), 4GB RAM, Windows 7 x64.
JavaScript Edition
C# Markdown
The JavaScript port of MarkdownDeep is 100% compatible with the .NET edition, effectively eliminating the problem of different results on server and client.
Performance of the JavaScript edition is highly dependant on the browser in question. In Chrome, Safara and Firefox performance is comparable to Showdown. In the current release of Internet Explorer, the performance is considerably worse but for typical usage performance is more thanadequate. The technology preview of IE9 addresses these performance issues and initial testingshows MarkdownDeep performs similarly to the other browsers.
The JavaScript edition comes in both full source code and a minifed version at about 30k.
Client Side Editor
In addition to the JavaScript port of the text transformation library, MarkdownDeep also includesa client side editor with real-time preview, toolbar, short-cut keys, help, resizer bar, auto-indentand tab/shift-tab block indent.
The editor comes in two parts:
- MarkdownDeepEditor - the core editor functionality that implements preview generation, editor commands and keyboard shortcuts.
- MarkdownDeepEditorUI - a jQuery based toolbar, popup help and resize bar.
To see the editor in action, click here.
Markdown Extra Enhancements
MarkdownDeep optionally supports all of the PHP Markdown Extra extensions, including:
- Markdown in HTML blocks
- Fenced code blocks
- Header id attributes
- Simple tables
- Definition lists
- Footnotes
- Abbreviations
Safe Mode
MarkdownDeep includes optional built-in support for sanitized HTML output.
Markdown is an excellent format for user entered rich content. Unfortunately allowingcomplete support for Markdown creates security risks and opens one's site to the risk of XSS scripting attacks.
Normally this would be addressed by post-processing the output with a separate HTML sanitizer. With MarkdownDeep, this support is built-in and saves making another pass over the generated content.
MarkdownDeep uses a built-in white list of allowable HTML tags. All other HTML tagswill be automatically escaped.
Relative Link Qualification
Markdown is an excellent format for authoring blog articles. However, generating RSS feeds that work with all readers requires replacing relative URL links withfully qualified links.
By supplying a base URL, MarkdownDeep can automatically qualify these relative links.
Links that Open in a New Window
Markdownsharp Documentation
MarkdownDeep can automatically add target='_blank'
to links so they open in a newwindow or tab.
This can be enabled for fully-qualified links only. In this mode relative links to your own site open in-place whereas links to other sites open in a newwindow.
New window links are also useful when generating previews during editing. By havingall links in a preview open in a new window an author can check her links work withoutactually leaving the page on which she's editing her post.
Support for No-Follow Links
MarkdownDeep can optionally add rel='nofollow'
to all links. Use this when acceptinguser entered Markdown to reduce the benefits comment spam.
Image Size Attributes
C# Markdown Parser
Markdown doesn't provide a way to specify the dimensions of embedded images (at least notwithout resorting to HTML).
MarkdownDeep can automatically get the dimensions of images that are on the local machine - either automatically by providing a folder location in which to look for the images, or by writing a custom handler that supplies image sizes for a specified URL.
Use this to prevent your page's text jumping around while the images load.
Titled Images
Often when authoring content with Markdown it's desirable to embed an image that's centeredand has a caption or title below it. Markdown itself doesn't provide support for this andsimply wraps the img
tag in a regular paragraph that can't be styled with CSS.
MarkdownDeep has a feature where a paragraph that contains just an image can be automatically wrapped in a div
with a specified class name. Also, in this mode if theimage has a title it is displayed in a paragraph below the image.
So this Markdown:
can be rendered as:
and styled with:
Section Splitting
MarkdownDeep can split Markdown content into sections for easier editing. This functionality comes in two parts:
- The ability to split a Markdown document at each heading (and support for rejoining the split content after editing).
- The ability to render additional content before or after each section.
This works as follows:
- When the page is in edit mode, each heading is prefixed by a link to edit that section. The link caninclude a section number that will be calculated by MarkdownDeep as it renders the page.
- The user clicks on the edit link which takes them to a page to edit that section.
- The server uses MarkdownDeep to split the original Markdown content into sections and uses the link'ssection number to extract the Markdown to be edited.
- The user edits the section.
- On saving the section, the original content is split into sections again, and the section being editedis replaced with the new content.
MarkdownDeep creates new sections at top-level h1
, h2
and h3
headings. Headings within otherblock level constructs are not used for section breaks.