private string FormatCodeBlock(MarkdownDeep.Markdown markdown, string code) { var match = Regex.Match(code, CODE_LANGUAGE_PATTERN, RegexOptions.Compiled | RegexOptions.IgnoreCase); if (match.Success) { // get the language name var language = match.Groups[1].Value; // remove language tag from code code = Regex.Replace(code, WHITESPACE_PATTERN + CODE_LANGUAGE_PATTERN + WHITESPACE_PATTERN, string.Empty, RegexOptions.Compiled | RegexOptions.IgnoreCase); // wrap code in pre and code tags with correct class name return string.Format(CODE_BLOCK_WITH_LANGUAGE, "language-" + language, code); } return string.Format(CODE_BLOCK, code); }
private string FormatCodeBlock(CmsContext context, MarkdownDeep.Markdown markdown, string source) { try { var match = _LanguageExpression.Match(source.Split('\n')[0].Trim()); if (match.Success) { var language = match.Result("${language}"); var contentType = "code/" + language; var codeRenderer = context.GetRenderService(contentType); if (codeRenderer != null) { return codeRenderer.Render(context, new CmsPart(contentType, String.Join("\n", source.Split('\n').Skip(1)))).ToHtml().ToHtmlString(); } } } catch { } return markdown.Transform(source); }
public static string FormatCodePrettyPrint(MarkdownDeep.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 = "csharp"; 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("<textarea class=\"code code-sample data-lang='{0}' \">{1}</textarea>\n", language.ToLowerInvariant(), code); }
public static string FormatCodePrettyPrint(MarkdownDeep.Markdown m, string code) { // Try to extract the language from the first line var match = rxExtractLanguage.Match(code); string language = string.Empty; if (match.Success) { var g = match.Groups[2]; language = g.ToString().Trim().ToLowerInvariant(); code = code.Substring(match.Groups[1].Length); } if (string.IsNullOrEmpty(language)) { var d = m.GetLinkDefinition("default_syntax"); if (d != null) language = d.title; } // Common replacements if (language.Equals("C#", StringComparison.OrdinalIgnoreCase)) language = "cs"; else if (language.Equals("csharp", StringComparison.OrdinalIgnoreCase)) language = "cs"; else if (language.Equals("C++", StringComparison.OrdinalIgnoreCase)) language = "cpp"; if (string.IsNullOrEmpty(language)) { return $"<pre><code>{code}</code></pre>\n"; } else { return $"<pre class=\"prettyprint lang-{language}\"><code>{code}</code></pre>\n"; } }
public RoomViewModelReaderMarkdownDecorator(IRoomViewModelReader @delegate, MarkdownDeep.Markdown markdown) { this.@delegate = @delegate; this.markdown = markdown; }
/// <summary> /// Convert a JSON string into an instance of this class /// </summary> /// <param name="json"></param> /// <returns></returns> public static CodeBlockAnnotation ParseMetadata(string json, MarkdownDeep.Block codeBlock = null) { var response = JsonConvert.DeserializeObject<CodeBlockAnnotation>(json); if (codeBlock != null) { // See if we can infer anything that's missing from response if (response.BlockType == CodeBlockType.Unknown) { response.BlockType = InferBlockType(codeBlock, response.ResourceType); } } return response; }