// this is where references are stored an executed at public SnippetDocumentControl() { InitializeComponent(); try { References = new Rendering.References(); References.AddDefaults(); _css3SelectorCompletion = new CSSCodeCompletion(txtCSS); _htmlCompletion = new HtmlCodeCompletion(txtHtml); _javascriptCompletion = new JQueryCodeCompletion(txtJavascript); } catch (Exception e) { //todo: Need to improve the error handling!! Debug.WriteLine(e); } txtHtml.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("HTML"); txtJavascript.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("JavaScript"); txtCSS.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("CSS"); htmlTextEditorCaretPositionChangeDelayTimer.Tick += HtmlTextEditorCaretPositionChangeDelayTimer_Tick; txtHtml.TextArea.Caret.PositionChanged += HTMLTextEditorCaret_PositionChanged; txtHtml.TextChanged += HTMLTextEditor_TextChanged; htmlTextEditorTextChangeDelayTimer.Tick += HtmlTextEditorTextChangeDelayTimer_Tick; }
public Snippet(string css, string html, string javascript, Rendering.References references) { CSS = css; Html = html; Javascript = javascript; References = references; }
private static WebPad.Rendering.References GetReferences(HtmlAgilityPack.HtmlDocument doc) { WebPad.Rendering.References references = new Rendering.References(); var cssReferences = doc.DocumentNode.Descendants("link") .Where(node => node.Attributes.Contains("href") && node.Attributes.Contains("type") && string.Equals(node.Attributes["type"].Value, "text/css", StringComparison.OrdinalIgnoreCase) ) .Select(node => new WebPad.Rendering.Reference { Type = Rendering.ReferenceTypes.Css, Url = node.Attributes["href"].Value }) .ToList(); var javascriptReferences = doc.DocumentNode.Descendants("script") .Where(node => node.Attributes.Contains("src") && node.Attributes.Contains("type") && string.Equals(node.Attributes["type"].Value, "text/javascript", StringComparison.OrdinalIgnoreCase) ) .Select(node => new WebPad.Rendering.Reference { Type = Rendering.ReferenceTypes.Javascript, Url = node.Attributes["src"].Value }) .ToList(); foreach (var reference in cssReferences) { references.Add(reference); } foreach (var reference in javascriptReferences) { references.Add(reference); } return(references); }