本文整理汇总了C#中MarkdownDeep.Markdown.Transform方法的典型用法代码示例。如果您正苦于以下问题:C# Markdown.Transform方法的具体用法?C# Markdown.Transform怎么用?C# Markdown.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MarkdownDeep.Markdown
的用法示例。
在下文中一共展示了Markdown.Transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Simple
public void Simple()
{
var markdown = new Markdown
{
NewWindowForExternalLinks = true
};
Console.WriteLine(markdown.Transform("##Header"));
Console.WriteLine(markdown.Transform("`<T>`"));
Console.WriteLine(markdown.Transform("[a](http://e1.ru)"));
}
示例2: CompiledContent
public static MvcHtmlString CompiledContent(this IDynamicContent contentItem, bool trustContent)
{
if (contentItem == null) return MvcHtmlString.Empty;
switch (contentItem.ContentType)
{
case DynamicContentType.Markdown:
var md = new Markdown
{
AutoHeadingIDs = true,
ExtraMode = true,
NoFollowLinks = !trustContent,
SafeMode = false,
NewWindowForExternalLinks = true,
};
var contents = contentItem.Body;
contents = CodeBlockFinder.Replace(contents, match => GenerateCodeBlock(match.Groups[1].Value.Trim(), match.Groups[2].Value));
try
{
contents = md.Transform(contents);
}
catch (Exception)
{
contents = string.Format("<pre>{0}</pre>", HttpUtility.HtmlEncode(contents));
}
return MvcHtmlString.Create(contents);
case DynamicContentType.Html:
return trustContent ? MvcHtmlString.Create(contentItem.Body) : MvcHtmlString.Empty;
}
return MvcHtmlString.Empty;
}
示例3: ResolveMarkdown
public static string ResolveMarkdown(this string content, IDocsOutput output, string currentSlug)
{
// http://www.toptensoftware.com/markdowndeep/api
var md = new Markdown
{
AutoHeadingIDs = true,
ExtraMode = true,
NoFollowLinks = false,
SafeMode = false,
HtmlClassTitledImages = "figure",
UrlRootLocation = output.RootUrl,
};
if (!string.IsNullOrWhiteSpace(output.RootUrl))
{
if (!string.IsNullOrWhiteSpace(currentSlug) && !currentSlug.Equals("index"))
md.UrlBaseLocation = output.RootUrl + "/" + currentSlug.Replace('\\', '/');
else
md.UrlBaseLocation = output.RootUrl;
}
////if (!string.IsNullOrWhiteSpace(output.ImagesPath))
// md.QualifyUrl = delegate(string image) { return output.ImagesPath + "/" + image; };
md.PrepareImage = (tag, titledImage) => PrepareImage(output.ImagesPath, tag);
return md.Transform(content);
}
示例4: Main
static void Main(string[] args)
{
Markdown m = new Markdown();
m.SafeMode = false;
m.ExtraMode = true;
m.AutoHeadingIDs = true;
// m.SectionHeader = "<div class=\"header\">{0}</div>\n";
// m.SectionHeadingSuffix = "<div class=\"heading\">{0}</div>\n";
// m.SectionFooter = "<div class=\"footer\">{0}</div>\n\n";
// m.SectionHeader = "\n<div class=\"section_links\"><a href=\"/edit?section={0}\">Edit</a></div>\n";
// m.HtmlClassTitledImages = "figure";
// m.DocumentRoot = "C:\\users\\bradr\\desktop";
// m.DocumentLocation = "C:\\users\\bradr\\desktop\\100D5000";
// m.MaxImageWidth = 500;
string markdown=FileContents("input.txt");
string str = m.Transform(markdown);
Console.Write(str);
var sections = MarkdownDeep.Markdown.SplitSections(markdown);
for (int i = 0; i < sections.Count; i++)
{
Console.WriteLine("---- Section {0} ----", i);
Console.Write(sections[i]);
Console.WriteLine("\n");
}
Console.WriteLine("------------------");
}
示例5: GetDocument
private Negotiator GetDocument(IDocumentFolder documentFolder, string path)
{
var markdown = documentFolder.ReadAllText(path);
var converter = new Markdown();
var html = converter.Transform(markdown);
return View["Index", new { Title = path, Content = html }];
}
示例6: Markdown
public static string Markdown(string text)
{
if (text == null)
return "";
var md = new Markdown();
return md.Transform(text.Trim());
}
示例7: CompiledContent
public static IHtmlString CompiledContent(this IDynamicContent contentItem, bool trustContent = false)
{
if (contentItem == null) return NonEncodedHtmlString.Empty;
switch (contentItem.ContentType)
{
case DynamicContentType.Markdown:
var md = new Markdown
{
AutoHeadingIDs = true,
ExtraMode = true,
NoFollowLinks = !trustContent,
SafeMode = false,
NewWindowForExternalLinks = true,
};
var contents = contentItem.Content;
// TODO contents = CodeBlockFinder.Replace(contents, match => GenerateCodeBlock(match.Groups[1].Value.Trim(), match.Groups[2].Value));
contents = md.Transform(contents);
return new NonEncodedHtmlString(contents);
case DynamicContentType.Html:
return trustContent ? new NonEncodedHtmlString(contentItem.Content) : NonEncodedHtmlString.Empty;
}
return NonEncodedHtmlString.Empty;
}
示例8: Show
public ActionResult Show(string page)
{
if (page == "" || page == null)
page = "README";
string path = string.Concat(HttpContext.Request.PhysicalApplicationPath, "\\Docs\\", page, ".md");
string contents;
try
{
using (StreamReader sr = new StreamReader(path))
{
Markdown md = new Markdown();
contents = md.Transform(sr.ReadToEnd());
}
ViewBag.ConvertedMarkdown = contents;
return View();
}
catch (Exception ex)
{
this.Response.StatusCode = 404;
ViewBag.ConvertedMarkdown = "File not found.";
return View();
}
}
示例9: ShowReleaseNotesDialog_Load
private void ShowReleaseNotesDialog_Load(object sender, EventArgs e)
{
string contents = File.ReadAllText(_path);
var md = new Markdown();
_temp = TempFile.WithExtension("htm"); //enhance: will leek a file to temp
File.WriteAllText(_temp.Path, md.Transform(contents));
_browser.Url = new Uri(_temp.Path);
}
示例10: Markdown
/// <summary>
/// Transforms a string of Markdown into HTML.
/// </summary>
/// <param name="text">The Markdown that should be transformed.</param>
/// <returns>The HTML representation of the supplied Markdown.</returns>
public static IHtmlString Markdown(string text)
{
// Transform the supplied text (Markdown) into HTML.
var markdownTransformer = new Markdown();
var html = markdownTransformer.Transform(text);
// Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :(
return html.ToHtmlString();
}
示例11: ShowReleaseNotesDialog_Load
private void ShowReleaseNotesDialog_Load(object sender, EventArgs e)
{
string contents = File.ReadAllText(_path);
var md = new Markdown();
// Disposed of during dialog Dispose()
_temp = TempFile.WithExtension("htm");
File.WriteAllText(_temp.Path, GetBasicHtmlFromMarkdown(md.Transform(contents)));
_browser.Url = new Uri(_temp.Path);
}
示例12: TransformMarkdown
public void TransformMarkdown()
{
var markdownEngine = new Markdown
{
ExtraMode = true,
AutoHeadingIDs = true,
CodeBlockLanguageAttr = " data-language=\"{0}\""
};
this.Body = markdownEngine.Transform(this.Body);
}
示例13: Markdown
public static string Markdown(this string txt)
{
if (string.IsNullOrEmpty(txt)) return string.Empty;
// spaces in urls will not work with MarkdownDeep
txt = Regex.Replace(txt, @"\(http(.*)\)", match => match.ToString().Replace(" ", "%20"));
// single linebreaks become double linebreaks to conform LeTour markdown
var md = new Markdown();
txt = md.Transform(txt);
txt = Regex.Replace(txt, @"(?<!(</p>))\n(?!\n)", match => "<br/>");
return txt;
}
示例14: Render
public void Render(Document input, Document output)
{
output.Extension = ".html";
var mark = new Markdown();
//set preferences of your markdown
mark.SafeMode = true;
mark.ExtraMode = true;
string mdtext = input.Text;
output.Text = mark.Transform(mdtext);
}
示例15: FormatMessage
public static string FormatMessage(String originalMessage, bool processContent = true)
{
//Test changes to this code against this markdown thread content:
//https://voat.co/v/test/comments/53891
if (processContent && !String.IsNullOrEmpty(originalMessage))
{
originalMessage = ContentProcessor.Instance.Process(originalMessage, ProcessingStage.Outbound, null);
}
var newWindow = false;
if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
newWindow = UserHelper.LinksInNewWindow(System.Web.HttpContext.Current.User.Identity.Name);
}
var m = new Markdown
{
PrepareLink = new Func<HtmlTag, bool>(x =>
{
//Remove [Title](javascript:alter('hello')) exploit
string href = x.attributes["href"];
if (!String.IsNullOrEmpty(href))
{
//I think it needs the javascript: prefix to work at all but there might be more holes as this is just a simple check.
if (href.ToLower().Trim().StartsWith("javascript:"))
{
x.attributes["href"] = "#";
//add it to the output for verification?
x.attributes.Add("data-ScriptStrip", String.Format("/* script detected: {0} */", href));
}
}
return true;
}),
ExtraMode = true,
SafeMode = true,
NewWindowForExternalLinks = newWindow,
NewWindowForLocalLinks = newWindow
};
try
{
return m.Transform(originalMessage);
}
catch (Exception ex)
{
return "Content contains unsafe or unknown tags.";
}
}