本文整理汇总了C#中MarkdownSharp.Markdown类的典型用法代码示例。如果您正苦于以下问题:C# Markdown类的具体用法?C# Markdown怎么用?C# Markdown使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Markdown类属于MarkdownSharp命名空间,在下文中一共展示了Markdown类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public string Execute(string source, IDictionary<string, object> arguments)
{
var markdown = new Markdown();
string output = markdown.Transform(source);
return output;
}
示例2: Process
public void Process(RenderFieldArgs args)
{
Assert.ArgumentNotNull(args, "args");
if (!string.IsNullOrEmpty(args.FieldValue))
{
args.Result.FirstPart = args.FieldValue;
}
else
{
args.Result.FirstPart = args.Item[args.FieldName];
}
if (args.FieldTypeKey == "rich text")
{
WordFieldValue wordFieldValue = WordFieldValue.Parse(args.Result.FirstPart);
if (wordFieldValue.BlobId != ID.Null)
{
args.Result.FirstPart = wordFieldValue.GetHtmlWithStyles();
}
}
if (args.FieldTypeKey == "markdownfield")
{
var markdown = new Markdown();
args.Result.FirstPart = markdown.Transform(args.FieldValue);
}
}
示例3: RenderMasterPage
/// <summary>
/// Renders stand alone / master page
/// </summary>
/// <param name="templateContent">Template content</param>
/// <returns>HTML converted to markdown</returns>
public static string RenderMasterPage(string templateContent)
{
var second =
templateContent.Substring(
templateContent.IndexOf("<!DOCTYPE html>", StringComparison.OrdinalIgnoreCase),
templateContent.IndexOf("<body", StringComparison.OrdinalIgnoreCase));
var third = templateContent.Substring(second.Length);
var forth = templateContent.Substring(second.Length, third.IndexOf(">", StringComparison.Ordinal) + 1);
var header = second + forth;
var toConvert = templateContent.Substring(header.Length,
(templateContent.IndexOf("</body>", StringComparison.Ordinal) -
(templateContent.IndexOf(forth, StringComparison.Ordinal) + forth.Length)));
var footer =
templateContent.Substring(templateContent.IndexOf("</body>", StringComparison.OrdinalIgnoreCase));
var parser = new Markdown();
var html = parser.Transform(toConvert.Trim());
var serverHtml = ParagraphSubstitution.Replace(html, "$1");
//TODO: The "Replace" is simply for unit testing HTML/MD strings. Probably needs improving
return string.Concat(header, serverHtml, footer).Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
}
示例4: GetTests
private static IEnumerable<TestCaseData> GetTests()
{
Markdown m = new Markdown();
Assembly assembly = Assembly.GetAssembly(typeof(BaseTest));
string namespacePrefix = String.Concat(assembly.GetName().Name, '.', folder);
string[] resourceNames = assembly.GetManifestResourceNames();
Func<string, string> getResourceFileContent = filename =>
{
using (Stream stream = assembly.GetManifestResourceStream(filename))
{
if (stream == null)
return null;
using (StreamReader streamReader = new StreamReader(stream))
return streamReader.ReadToEnd();
}
};
return from name in resourceNames
// Skip resource names that aren't within the namespace (folder) we want
// and doesn't have the extension '.html'.
where name.StartsWith(namespacePrefix) && name.EndsWith(".html")
let actualName = Path.ChangeExtension(name, "text")
let actualContent = getResourceFileContent(actualName)
let actual = Program.RemoveWhitespace(m.Transform(actualContent))
let expectedContent = getResourceFileContent(name)
let expected = Program.RemoveWhitespace(expectedContent)
select new TestCaseData(actualName, name, actual, expected);
}
示例5: MarkdownReplace
private static string MarkdownReplace(string text) {
if (string.IsNullOrEmpty(text))
return string.Empty;
var markdown = new MarkdownSharp.Markdown(new MarkdownOptions { AutoNewLines = false });
return markdown.Transform(text);
}
示例6: transform
private string transform(string text)
{
if (string.IsNullOrEmpty(text))
return string.Empty;
var parser = new Markdown();
parser.ExtendWith(new StatefulCheckboxPattern());
var t = parser.Transform(text);
//prevent html from being replaced by wikiwords
var htmlTags = new Queue<string>();
t = _htmlTagsRegex.Replace(t, m =>
{
htmlTags.Enqueue(m.Groups[0].Value);
return _emaPlaceholder;
});
//don't extend markdown with this pattern because it will destroy links
t = new WikiWordsPattern().Transform(t);
return _htmlTagsRegex.Replace(t, m =>
{
if (m.Groups[0].Value == _emaPlaceholder)
{
return htmlTags.Dequeue();
}
else
{
//new wikiword link
return m.Groups[0].Value;
}
});
}
示例7: ProcessContent
static HtmlString ProcessContent(string fileContent)
{
var content = new Markdown().Transform(fileContent);
content = CodeHighlightRegex.Replace(content, match =>
{
var highlightOptions = match.Groups["highlightOptions"].Value;
var linesToHighlight = highlightOptions.Split(',').Select(int.Parse);
var codeLines = match.Groups["code"].Value.Split('\n');
foreach (var lineNumber in linesToHighlight)
{
var lineIndex = lineNumber - 1;
if (lineIndex < 0) throw new ArgumentException(string.Format("Tried to highlight a line with index less than 0. The full code block was:\r\n\r\n{0}", match.Value));
if (lineIndex > codeLines.Count() - 1) throw new ArgumentException(string.Format("Tried to highlight a line with index {0}, which doesn't exist. The full code block was:\r\n\r\n{1}", codeLines.Count(), match.Value));
codeLines[lineIndex] = string.Format("<strong>{0}</strong>", codeLines[lineIndex]);
}
return string.Join(Environment.NewLine, codeLines);
});
var contentIncludesASequenceDiagram = false;
content = SequenceDiagramRegex.Replace(content, match =>
{
contentIncludesASequenceDiagram = true;
var sequenceContent = match.Groups["sequenceContent"].Value;
return string.Format("<div class=\"wsd\">{0}</div>", sequenceContent);
});
if (contentIncludesASequenceDiagram)
content += "\r\n<script type=\"text/javascript\" src=\"http://www.websequencediagrams.com/service.js\" async></script>";
return new HtmlString(content);
}
示例8: ProcessRequest
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/html";
var markdown = context.Request.QueryString["markdown"];
var processor = new Markdown();
context.Response.Write(processor.Transform(markdown));
}
示例9: Main
public static void Main(string[] args)
{
Markdown md = new Markdown ();
var markup = File.ReadAllText (args[0]);
var html = md.Transform (markup);
Console.WriteLine (html);
}
示例10: IndexReturnsCorrectViewResult
public void IndexReturnsCorrectViewResult(
HttpContextBase httpContext,
ControllerContext controllerContext,
HomeController sut)
{
// Arrange
controllerContext.HttpContext = httpContext;
sut.ControllerContext = controllerContext;
const string readmeFilePath = "README.md";
Mock.Get(httpContext).Setup(x => x.Server.MapPath("~/bin/README.md")).Returns(readmeFilePath);
string markdown;
using (var reader = new StreamReader(readmeFilePath))
{
markdown = reader.ReadToEnd();
}
var html = new Markdown().Transform(markdown);
// Act
var actual = sut.Index();
// Assert
var viewResult = Assert.IsAssignableFrom<ViewResult>(actual);
Assert.Empty(viewResult.ViewName);
Assert.Equal(html, viewResult.Model);
}
示例11: MarkDownService
public MarkDownService(Manager man)
: base(man)
{
Markdown = new Markdown();
Markdown.AutoHyperlink = true;
Markdown.AutoNewLines = true;
}
示例12: DocumentParser
public DocumentParser(ITemplate template)
{
Ensure.ArgumentNotNull(template, "template");
_template = template;
_markdown = new Markdown();
}
示例13: MarkDownTextBox_Load
private void MarkDownTextBox_Load(object sender, EventArgs e)
{
if(this.DesignModeAtAll())
return;
var markdownTransformer = new Markdown();
_htmlLabel.HTML = markdownTransformer.Transform(_markdown);
}
示例14: GetContent
private string GetContent()
{
var md = new Markdown(new MarkdownOptions { AutoHyperlink = true });
// Code is converted to <pre><code>, I just want the code tag:
var html = md.Transform(_content).Replace("<pre><code>", "<code>").Replace("</code></pre>", "</code>");
return html;
}
示例15: Process
public string Process(string input)
{
var options = new MarkdownOptions();
var markdown = new Markdown();
var output = markdown.Transform(input);
return output;
}