private static void GenerateSnippets() { var font = new System.Drawing.Font("Consolas", 12); var cfg = XElement.Load(@"..\..\..\Snippets.xml"); var exportElement = new XElement("Snippets"); int index = 0; foreach (var snippet in cfg.Elements("Snippet")) { var code = snippet.Element("Code").Value; Console.WriteLine($"Rendering {code}"); var teXCommentText = $"$${code}$$"; var fullSpan = new Span(0, teXCommentText.Length); var teXCommentBlockSpan = new TeXCommentBlockSpan(fullSpan, fullSpan, 0, 0, 0, "\r\n", 100, null, null, "CSharp"); var result = renderer.Render( new HtmlRenderer.Input( new TeXCommentTag(teXCommentText, teXCommentBlockSpan), 1.3, Colors.Black, Colors.White, font, null, null)); SaveSnippet(result.CachePath, snippet.Element("Group").Value, code, $"{++index}.png", exportElement); } exportElement.Save(Path.Combine(OutputPath, "Snippets.xml")); Console.WriteLine("Done"); }
public TeXCommentTag(string text, TeXCommentBlockSpan span) { Debug.Assert(text != null); TextWithWhitespacesAtStartOfFirstLine = text; Text = text.TrimStart(TextSnapshotTeXCommentBlocks.WhiteSpaces); TeXBlock = span; }
private void MenuItem_InsertSnippet_Click(object sender, RoutedEventArgs e) { var snippet = (sender as MenuItem)?.DataContext as SnippetMenuItem; if (snippet == null) { return; } var caret = textView.Caret; caret.EnsureVisible(); var code = snippet.Snippet; if (!IsCaretInsideMathBlock) { code = $"$${code}$$"; } if (snippet.IsMultiLine) { //we need to corretly indent snippet var indent = TeXCommentBlockSpan.GetMinNumberOfWhitespacesBeforeCommentPrefixes(DataTag.TextWithWhitespacesAtStartOfFirstLine); var indentString = new string(' ', indent); var lines = code.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { if (lines[i].Length > 0) { lines[i] = indentString + lines[i]; } } code = lines.Aggregate((a, b) => $"{a}{Environment.NewLine}{b}"); } textView.TextBuffer.Insert(caret.Position.BufferPosition.Position, code); }