public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { var content = MarkdownVisitor.Process(node).Trim('\n', '\r'); // TODO: figure out of this is a problem content = content.Replace("<", "<").Replace(">", ">"); var useBlockFormat = content.IndexOf('\n') > 0; if (useBlockFormat) { // TODO: detect language var attClass = node.Attributes.GetValueOrDefault("class", ""); var language = string.Empty; foreach (var att in attClass.Split(' ')) { if (att.StartsWith("lang:")) { language = att.Replace("lang:", ""); break; } } bodyBuilder.AppendLine().Append("```"); bodyBuilder.AppendLine(language); bodyBuilder.AppendLine(content); bodyBuilder.AppendLine("```"); } else { bodyBuilder.Append("`").Append(content).Append("`"); } return(false); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { Process(node, bodyBuilder); // we need to parse any child return(true); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { bodyBuilder.AppendLine().AppendLine(); // this should never actually happen, but hey... return(true); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { if (node is TextNode) { bodyBuilder.Append(node.ToString()); } return(true); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { //var content = MarkdownVisitor.Process(node); var levels = Int32.Parse(node.Name.Substring(1, 1)); bodyBuilder.AppendLine().AppendLine().Append('#', levels).Append(' '); return(true); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { var content = MarkdownVisitor.Process(node).Trim('\n', '\r', ' '); bodyBuilder.AppendLine().Append(">"); content = content.Replace("\n", "\n>"); bodyBuilder.AppendLine(content).AppendLine(); return(false); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { var src = node.Attributes.GetValueOrDefault("src"); if (string.IsNullOrEmpty(src)) { return(false); } // ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1") bodyBuilder.AppendFormat("![{0}]({1} \"{2}\")", node.Attributes.GetValueOrDefault("alt"), src, node.Attributes.GetValueOrDefault("title")); return(false); }
public override void CloseNode(HtmlParser.Node node, StringBuilder bodyBuilder) { if (node.Name == "li") { return; } if (_lists.Peek() != node.Name) { throw new InvalidOperationException("Mismatch!"); } _lists.Pop(); bodyBuilder.AppendLine(); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { string content = string.Empty; switch (node.Name) { case "ul": case "ol": _lists.Push(node.Name); //if (_lists.Count == 1) { bodyBuilder.AppendLine(); } // this is a weird hack, but we're doing it because HTML is weird // but we only care about the li elements, and we treat the rest as problematic (non-existant) // and if we loose content, so be it... foreach (var child in node.Children) { if (child.GetNameSafely() != "li") { Console.WriteLine("!! Content ignored: " + child.ToString()); continue; } content = MarkdownVisitor.Process(child).Trim('\r', '\n', ' '); if (content.IndexOf('\n') >= 0) { // we need to add a \t at every new line content = content.Replace("\n", "\n\t"); } bodyBuilder.AppendFormat("{0} {1}", node.Name == "ul" ? "*" : "1.", content).AppendLine(); } return(false); case "li": content = MarkdownVisitor.Process(node).Trim('\n', ' '); bodyBuilder.AppendFormat("{0} {1}", _lists.Peek() == "ul" ? "*" : "1.", content).AppendLine(); return(false); } return(true); }
private void Process(HtmlParser.Node node, StringBuilder bodyBuilder) { switch (node.GetNameSafely()) { case "em": case "i": bodyBuilder.Append("_"); break; case "b": case "strong": bodyBuilder.Append("**"); break; default: throw new NotSupportedException("EmphasisConverter was picked for a tag that isn't recognized " + node.GetNameSafely()); } }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { if (!node.Attributes.TryGetValue("ids", out string keys)) { throw new Exception("Gallery had no ids, no idea what to do here."); } var ids = keys.Split(',').Select(x => Int32.Parse(x)).ToArray(); // Ugh... :-( foreach (var id in ids) { var attachment = FileContext.Current.Attachments.SingleOrDefault(x => x.Key == id).Value; if (attachment == null) { // todo: what do to here? continue; } ; // not sure I like this, but again, let's do what we have to var imageNode = new HtmlParser.Node() { Name = "img", Type = HtmlParser.Node.NodeType.SelfClosing, Attributes = new Dictionary <string, string>() { { "src", attachment.AttachmentUrl } } }; // the gallery approach would have likely been better if I decided to play with the // columns, and then split into lines, etc. But this is a good enough start. //bodyBuilder.AppendLine(MarkdownVisitor.Process(imageNode)); node.AddChild(imageNode); } return(true); }
public override void CloseNode(HtmlParser.Node node, StringBuilder bodyBuilder) { // sometimes the emphasis ends with a whitespace character which is slightly // annoying, but valid in HTML - so we move it after our node ending var suffix = bodyBuilder.ToString().Substring(bodyBuilder.Length - 1); if (String.IsNullOrWhiteSpace(suffix)) { bodyBuilder.Remove(bodyBuilder.Length - 1, 1); } else { suffix = null; } Process(node, bodyBuilder); if (suffix != null) { bodyBuilder.Append(suffix); } }
// we rely on the converter being a single instance, which may not be good public override void CloseNode(HtmlParser.Node node, StringBuilder bodyBuilder) { }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { bodyBuilder.AppendLine().AppendLine(); return(true); }
public override void CloseNode(HtmlParser.Node node, StringBuilder bodyBuilder) { bodyBuilder.AppendLine().AppendLine(); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { //[I'm an inline-style link](https://www.google.com) bodyBuilder.Append('['); return(true); }
public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder) { return(true); }
public abstract void CloseNode(HtmlParser.Node node, StringBuilder bodyBuilder);
/// <summary> /// Writes the opening of the node. /// </summary> /// <param name="node"></param> /// <returns>Return true if the caller is expected to handle children separately. </returns> public abstract bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder);
public static MarkdownConverterBase GetConverter(this Dictionary <string, Converters.MarkdownConverterBase> list, HtmlParser.Node node) { var tag = node.Name; if (!string.IsNullOrEmpty(tag) && list.ContainsKey(tag)) { return(list[tag]); } return(new DefaultConverter()); }
public override void CloseNode(HtmlParser.Node node, StringBuilder bodyBuilder) { bodyBuilder.Append("](").Append(node.Attributes.GetValueOrDefault("href", "")).Append(")"); }