public String AsHtml(DocumentLinkResolver linkResolver) { String imgTag = "<img alt=\"" + alt + "\" src=\"" + url + "\" width=\"" + width + "\" height=\"" + height + "\" />"; if (this.linkTo != null) { String u = "about:blank"; if (this.linkTo is WebLink) { u = ((WebLink)this.linkTo).Url; } else if (this.linkTo is ImageLink) { u = ((ImageLink)this.linkTo).Url; } else if (this.linkTo is DocumentLink) { u = ((DocumentLink)this.linkTo).IsBroken ? "#broken" : linkResolver.Resolve((DocumentLink)this.LinkTo); } return("<a href=\"" + u + "\">" + imgTag + "</a>"); } else { return(imgTag); } }
public String AsHtml(IList <Block> blocks, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { IList <BlockGroup> blockGroups = new List <BlockGroup>(); foreach (Block block in blocks) { BlockGroup lastOne = blockGroups.Count == 0 ? null : blockGroups[blockGroups.Count - 1]; if (lastOne != null && "ul" == lastOne.tag && block is ListItem && !((ListItem)block).IsOrdered) { lastOne.blocks.Add(block); } else if (lastOne != null && "ol" == lastOne.tag && block is ListItem && ((ListItem)block).IsOrdered) { lastOne.blocks.Add(block); } else if (block is ListItem && !((ListItem)block).IsOrdered) { BlockGroup newBlockGroup = new BlockGroup("ul", new List <Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } else if (block is ListItem && ((ListItem)block).IsOrdered) { BlockGroup newBlockGroup = new BlockGroup("ol", new List <Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } else { BlockGroup newBlockGroup = new BlockGroup(null, new List <Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } } var html = ""; foreach (BlockGroup blockGroup in blockGroups) { if (blockGroup.tag != null) { html += ("<" + blockGroup.tag + ">"); foreach (Block block in blockGroup.blocks) { html += (asHtml(block, linkResolver, htmlSerializer)); } html += ("</" + blockGroup.tag + ">"); } else { foreach (Block block in blockGroup.blocks) { html += (asHtml(block, linkResolver, htmlSerializer)); } } } return(html); }
public String AsHtml(DocumentLinkResolver linkResolver) { var html = ""; foreach (GroupDoc groupDoc in this.groupDocs) { html += groupDoc.AsHtml(linkResolver); } return(html); }
public string AsHtml(DocumentLinkResolver resolver) { var className = "slice"; if (this.sliceLabel != null) { className += (" " + this.sliceLabel); } return("<div data-slicetype=\"" + this.sliceType + "\" class=\"" + className + "\">" + WithFragments.GetHtml(this.value, resolver, null) + "</div>"); }
public void ShouldParseCompositeSlices() { var document = Fixtures.GetDocument("composite_slices.json"); var resolver = DocumentLinkResolver.For(doc => String.Format("http://localhost/{0}/{1}", doc.Type, doc.Id)); var sliceZone = document.GetSliceZone("page.page_content"); Assert.AreEqual(sliceZone.AsHtml(resolver), "<div data-slicetype=\"text\" class=\"slice levi-label\"><section data-field=\"rich_text\"><p>Here is paragraph 1.</p><p>Here is paragraph 2.</p></section></div>" + "<div data-slicetype=\"image_gallery\" class=\"slice\"><section data-field=\"gallery_title\"><h2>Image Gallery</h2></section>" + "<section data-field=\"image\"><img alt=\"\" src=\"https://prismic-io.s3.amazonaws.com/levi-templeting%2Fdc0bfab3-d222-44a6-82b8-c74f8cdc6a6b_200_s.gif\" width=\"267\" height=\"200\" /></section>" + "<section data-field=\"image\"><img alt=\"\" src=\"https://prismic-io.s3.amazonaws.com/levi-templeting/83c03dac4a604ac2e97e285e60034c641abd73b6_image2.jpg\" width=\"400\" height=\"369\" /></section></div>"); }
private static String serialize(Span span, String content, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { if (htmlSerializer != null) { String customHtml = htmlSerializer.Serialize(span, content); if (customHtml != null) { return(customHtml); } } if (span is Strong) { return("<strong>" + content + "</strong>"); } if (span is Em) { return("<em>" + content + "</em>"); } if (span is LabelSpan) { return("<span class=\"" + ((LabelSpan)span).Label + "\">" + content + "</span>"); } if (span is Hyperlink) { Hyperlink hyperlink = (Hyperlink)span; if (hyperlink.Link is WebLink) { WebLink webLink = (WebLink)hyperlink.Link; return("<a href=\"" + webLink.Url + "\">" + content + "</a>"); } else if (hyperlink.Link is FileLink) { FileLink fileLink = (FileLink)hyperlink.Link; return("<a href=\"" + fileLink.Url + "\">" + content + "</a>"); } else if (hyperlink.Link is ImageLink) { ImageLink imageLink = (ImageLink)hyperlink.Link; return("<a href=\"" + imageLink.Url + "\">" + content + "</a>"); } else if (hyperlink.Link is DocumentLink) { DocumentLink documentLink = (DocumentLink)hyperlink.Link; String url = linkResolver.Resolve(documentLink); return("<a " + (linkResolver.GetTitle(documentLink) == null ? "" : "title=\"" + linkResolver.GetTitle(documentLink) + "\" ") + "href=\"" + url + "\">" + content + "</a>"); } } return("<span>" + content + "</span>"); }
public string AsHtml(DocumentLinkResolver resolver) { String className = "slice"; if (SliceLabel != null && SliceLabel != "null") { className += (" " + SliceLabel); } List <GroupDoc> groupDocs = new List <GroupDoc> { _nonRepeat }; return("<div data-slicetype=\"" + SliceType + "\" class=\"" + className + "\">" + WithFragments.GetHtml(new Group(groupDocs), resolver, null) + WithFragments.GetHtml(_repeat, resolver, null) + "</div>"); }
public String AsHtml(DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { return(AsHtml(getBlocks(), linkResolver, htmlSerializer)); }
private static String serialize(Span span, String content, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { if (htmlSerializer != null) { String customHtml = htmlSerializer.Serialize(span, content); if (customHtml != null) { return customHtml; } } if (span is Strong) { return "<strong>" + content + "</strong>"; } if (span is Em) { return "<em>" + content + "</em>"; } if (span is LabelSpan) { return "<span class=\"" + ((LabelSpan)span).Label + "\">" + content + "</span>"; } if (span is Hyperlink) { Hyperlink hyperlink = (Hyperlink)span; if(hyperlink.Link is WebLink) { WebLink webLink = (WebLink)hyperlink.Link; return "<a href=\""+ webLink.Url + "\">" + content + "</a>"; } else if(hyperlink.Link is FileLink) { FileLink fileLink = (FileLink)hyperlink.Link; return "<a href=\"" + fileLink.Url + "\">" + content + "</a>"; } else if(hyperlink.Link is ImageLink) { ImageLink imageLink = (ImageLink)hyperlink.Link; return "<a href=\""+ imageLink.Url + "\">" + content + "</a>"; } else if(hyperlink.Link is DocumentLink) { DocumentLink documentLink = (DocumentLink)hyperlink.Link; String url = linkResolver.Resolve(documentLink); return "<a " + (linkResolver.GetTitle(documentLink) == null ? "" : "title=\"" + linkResolver.GetTitle(documentLink) + "\" ") + "href=\""+ url+ "\">" + content + "</a>"; } } return "<span>" + content + "</span>"; }
private String insertSpans(String text, IList <Span> spans, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { if (spans.Count == 0) { return(HttpUtility.HtmlEncode(text)); } IDictionary <int, List <Span> > tagsStart = new Dictionary <int, List <Span> >(); IDictionary <int, List <Span> > tagsEnd = new Dictionary <int, List <Span> >(); foreach (Span span in spans) { if (!tagsStart.ContainsKey(span.Start)) { tagsStart.Add(span.Start, new List <Span>()); } if (!tagsEnd.ContainsKey(span.End)) { tagsEnd.Add(span.End, new List <Span>()); } tagsStart[span.Start].Add(span); tagsEnd[span.End].Add(span); } char c; String html = ""; Stack <Tuple <Span, String> > stack = new Stack <Tuple <Span, String> >(); for (int pos = 0, len = text.Length; pos < len; pos++) { if (tagsEnd.ContainsKey(pos)) { foreach (Span span in tagsEnd[pos]) { // Close a tag Tuple <Span, String> tag = stack.Pop(); String innerHtml = serialize(tag.Item1, tag.Item2, linkResolver, htmlSerializer); if (stack.Count == 0) { // The tag was top level html += innerHtml; } else { // Add the content to the parent tag Tuple <Span, String> head = stack.Pop(); stack.Push(new Tuple <Span, String>(head.Item1, head.Item2 + innerHtml)); } } } if (tagsStart.ContainsKey(pos)) { foreach (Span span in tagsStart[pos]) { // Open a tag stack.Push(new Tuple <Span, String>(span, "")); } } c = text[pos]; String escaped = HttpUtility.HtmlEncode(c.ToString()); if (stack.Count == 0) { // Top-level text html += escaped; } else { // Inner text of a span Tuple <Span, String> head = stack.Pop(); stack.Push(new Tuple <Span, String>(head.Item1, head.Item2 + escaped)); } } // Close remaining tags while (stack.Count > 0) { Tuple <Span, String> tag = stack.Pop(); String innerHtml = serialize(tag.Item1, tag.Item2, linkResolver, htmlSerializer); if (stack.Count == 0) { // The tag was top level html += innerHtml; } else { // Add the content to the parent tag Tuple <Span, String> head = stack.Pop(); stack.Push(new Tuple <Span, String>(head.Item1, head.Item2 + innerHtml)); } } return(html); }
public String AsHtml(DocumentLinkResolver linkResolver) { return(AsHtml(linkResolver, null)); }
public String GetUrl(DocumentLinkResolver resolver) { return url; }
public String AsHtml(DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { return AsHtml(getBlocks(), linkResolver, htmlSerializer); }
public String AsHtml(DocumentLinkResolver linkResolver) { String imgTag = "<img alt=\"" + alt + "\" src=\"" + url + "\" width=\"" + width + "\" height=\"" + height + "\" />"; if (this.linkTo != null) { String u = "about:blank"; if (this.linkTo is WebLink) { u = ((WebLink) this.linkTo).Url; } else if (this.linkTo is ImageLink) { u = ((ImageLink) this.linkTo).Url; } else if (this.linkTo is DocumentLink) { u = ((DocumentLink)this.linkTo).IsBroken ? "#broken" : linkResolver.Resolve((DocumentLink) this.LinkTo); } return "<a href=\"" + u + "\">" + imgTag + "</a>"; } else { return imgTag; } }
public String GetUrl(DocumentLinkResolver resolver) { return(resolver.Resolve(this)); }
public String AsHtml(DocumentLinkResolver linkResolver) { return this.slices.Aggregate("", (html, slice) => html + slice.AsHtml(linkResolver)); }
public String AsHtml(DocumentLinkResolver linkResolver) { var html = ""; foreach (GroupDoc groupDoc in this.groupDocs) { html += groupDoc.AsHtml(linkResolver); } return html; }
public string AsHtml(DocumentLinkResolver resolver) { var className = "slice"; if (this.sliceLabel != null) className += (" " + this.sliceLabel); return "<div data-slicetype=\"" + this.sliceType + "\" class=\"" + className + "\">" + WithFragments.GetHtml(this.value, resolver, null) + "</div>"; }
public new String AsHtml(DocumentLinkResolver linkResolver) { return ("<a " + (linkResolver.GetTitle(this) == null ? "" : "title=\"" + linkResolver.GetTitle(this) + "\" ") + "href=\"" + linkResolver.Resolve(this) + "\">" + slug + "</a>"); }
public String GetUrl(DocumentLinkResolver resolver) { return resolver.Resolve (this); }
public String AsHtml(DocumentLinkResolver linkResolver) { return(GetView("main").AsHtml(linkResolver)); }
public String AsHtml(DocumentLinkResolver linkResolver) { return(slices.Aggregate("", (html, slice) => html + slice.AsHtml(linkResolver))); }
public String GetUrl(DocumentLinkResolver resolver) { return(url); }
public String AsHtml(DocumentLinkResolver linkResolver) { return AsHtml(linkResolver, null); }
public new String AsHtml(DocumentLinkResolver linkResolver) { return("<a " + (linkResolver.GetTitle(this) == null ? "" : "title=\"" + linkResolver.GetTitle(this) + "\" ") + "href=\"" + linkResolver.Resolve(this) + "\">" + slug + "</a>"); }
public String AsHtml(DocumentLinkResolver linkResolver) { return GetView("main").AsHtml(linkResolver); }
public String asHtml(Block block, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { String content = ""; if(block is StructuredText.Heading) { StructuredText.Heading heading = (StructuredText.Heading)block; content = insertSpans(heading.Text, heading.Spans, linkResolver, htmlSerializer); } else if(block is StructuredText.Paragraph) { StructuredText.Paragraph paragraph = (StructuredText.Paragraph)block; content = insertSpans(paragraph.Text, paragraph.Spans, linkResolver, htmlSerializer); } else if(block is StructuredText.Preformatted) { StructuredText.Preformatted paragraph = (StructuredText.Preformatted)block; content = insertSpans(paragraph.Text, paragraph.Spans, linkResolver, htmlSerializer); } else if(block is StructuredText.ListItem) { StructuredText.ListItem listItem = (StructuredText.ListItem)block; content = insertSpans(listItem.Text, listItem.Spans, linkResolver, htmlSerializer); } if (htmlSerializer != null) { String customHtml = htmlSerializer.Serialize(block, content); if (customHtml != null) { return customHtml; } } String classCode = block.Label == null ? "" : (" class=\"" + block.Label + "\""); if(block is StructuredText.Heading) { StructuredText.Heading heading = (StructuredText.Heading)block; return ("<h" + heading.Level + classCode + ">" + content + "</h" + heading.Level + ">"); } else if(block is StructuredText.Paragraph) { return ("<p" + classCode + ">" + content + "</p>"); } else if(block is StructuredText.Preformatted) { return ("<pre" + classCode + ">" + content + "</pre>"); } else if(block is StructuredText.ListItem) { return ("<li" + classCode + ">" + content + "</li>"); } else if(block is StructuredText.Image) { StructuredText.Image image = (StructuredText.Image)block; String labelCode = block.Label == null ? "" : (" " + block.Label); return ("<p class=\"block-img" + labelCode + "\">" + image.View.AsHtml(linkResolver) + "</p>"); } else if(block is StructuredText.Embed) { StructuredText.Embed embed = (StructuredText.Embed)block; return (embed.Obj.AsHtml()); } return ""; }
public String asHtml(Block block, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { String content = ""; if (block is StructuredText.Heading) { StructuredText.Heading heading = (StructuredText.Heading)block; content = insertSpans(heading.Text, heading.Spans, linkResolver, htmlSerializer); } else if (block is StructuredText.Paragraph) { StructuredText.Paragraph paragraph = (StructuredText.Paragraph)block; content = insertSpans(paragraph.Text, paragraph.Spans, linkResolver, htmlSerializer); } else if (block is StructuredText.Preformatted) { StructuredText.Preformatted paragraph = (StructuredText.Preformatted)block; content = insertSpans(paragraph.Text, paragraph.Spans, linkResolver, htmlSerializer); } else if (block is StructuredText.ListItem) { StructuredText.ListItem listItem = (StructuredText.ListItem)block; content = insertSpans(listItem.Text, listItem.Spans, linkResolver, htmlSerializer); } if (htmlSerializer != null) { String customHtml = htmlSerializer.Serialize(block, content); if (customHtml != null) { return(customHtml); } } String classCode = block.Label == null ? "" : (" class=\"" + block.Label + "\""); if (block is StructuredText.Heading) { StructuredText.Heading heading = (StructuredText.Heading)block; return("<h" + heading.Level + classCode + ">" + content + "</h" + heading.Level + ">"); } else if (block is StructuredText.Paragraph) { return("<p" + classCode + ">" + content + "</p>"); } else if (block is StructuredText.Preformatted) { return("<pre" + classCode + ">" + content + "</pre>"); } else if (block is StructuredText.ListItem) { return("<li" + classCode + ">" + content + "</li>"); } else if (block is StructuredText.Image) { StructuredText.Image image = (StructuredText.Image)block; String labelCode = block.Label == null ? "" : (" " + block.Label); return("<p class=\"block-img" + labelCode + "\">" + image.View.AsHtml(linkResolver) + "</p>"); } else if (block is StructuredText.Embed) { StructuredText.Embed embed = (StructuredText.Embed)block; return(embed.Obj.AsHtml()); } return(""); }
public String AsHtml(IList<Block> blocks, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { IList<BlockGroup> blockGroups = new List<BlockGroup>(); foreach(Block block in blocks) { BlockGroup lastOne = blockGroups.Count == 0 ? null : blockGroups[blockGroups.Count - 1]; if(lastOne != null && "ul" == lastOne.tag && block is ListItem && !((ListItem)block).IsOrdered) { lastOne.blocks.Add(block); } else if(lastOne != null && "ol" == lastOne.tag && block is ListItem && ((ListItem)block).IsOrdered) { lastOne.blocks.Add(block); } else if(block is ListItem && !((ListItem)block).IsOrdered) { BlockGroup newBlockGroup = new BlockGroup("ul", new List<Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } else if(block is ListItem && ((ListItem)block).IsOrdered) { BlockGroup newBlockGroup = new BlockGroup("ol", new List<Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } else { BlockGroup newBlockGroup = new BlockGroup(null, new List<Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } } var html = ""; foreach(BlockGroup blockGroup in blockGroups) { if(blockGroup.tag != null) { html += ("<" + blockGroup.tag + ">"); foreach(Block block in blockGroup.blocks) { html += (asHtml(block, linkResolver, htmlSerializer)); } html += ("</" + blockGroup.tag + ">"); } else { foreach(Block block in blockGroup.blocks) { html += (asHtml(block, linkResolver, htmlSerializer)); } } } return html; }
private String insertSpans(String text, IList<Span> spans, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { if (spans.Count == 0) { return HttpUtility.HtmlEncode(text); } IDictionary<int, List<Span>> tagsStart = new Dictionary<int, List<Span>>(); IDictionary<int, List<Span>> tagsEnd = new Dictionary<int, List<Span>>(); foreach (Span span in spans) { if (!tagsStart.ContainsKey(span.Start)) { tagsStart.Add(span.Start, new List<Span>()); } if (!tagsEnd.ContainsKey(span.End)) { tagsEnd.Add(span.End, new List<Span>()); } tagsStart[span.Start].Add(span); tagsEnd[span.End].Add(span); } char c; String html = ""; Stack<Tuple<Span, String>> stack = new Stack<Tuple<Span, String>>(); for (int pos = 0, len = text.Length; pos < len; pos++) { if (tagsEnd.ContainsKey(pos)) { foreach (Span span in tagsEnd[pos]) { // Close a tag Tuple<Span, String> tag = stack.Pop(); String innerHtml = serialize(tag.Item1, tag.Item2, linkResolver, htmlSerializer); if (stack.Count == 0) { // The tag was top level html += innerHtml; } else { // Add the content to the parent tag Tuple<Span, String> head = stack.Pop(); stack.Push(new Tuple<Span, String>(head.Item1, head.Item2 + innerHtml)); } } } if (tagsStart.ContainsKey(pos)) { foreach (Span span in tagsStart[pos]) { // Open a tag stack.Push(new Tuple<Span, String>(span, "")); } } c = text[pos]; String escaped = HttpUtility.HtmlEncode(c.ToString()); if (stack.Count == 0) { // Top-level text html += escaped; } else { // Inner text of a span Tuple<Span, String> head = stack.Pop(); stack.Push(new Tuple<Span, String>(head.Item1, head.Item2 + escaped)); } } // Close remaining tags while (stack.Count > 0) { Tuple<Span, String> tag = stack.Pop(); String innerHtml = serialize(tag.Item1, tag.Item2, linkResolver, htmlSerializer); if (stack.Count == 0) { // The tag was top level html += innerHtml; } else { // Add the content to the parent tag Tuple<Span, String> head = stack.Pop(); stack.Push(new Tuple<Span, String>(head.Item1, head.Item2 + innerHtml)); } } return html; }