public XElement Parse(Paragraph paragraph)
        {
            Style style = (Style)paragraph.get_Style();

            if (style.NameLocal == DocumentAndParagraphStyles.ImagePreviewStyle)
            {
                IEnumerable <Hyperlink> hs = paragraph.Range.Hyperlinks.Cast <Hyperlink>().ToArray();
                if (hs.Count() == 0)
                {
                    return(null);
                }

                try
                {
                    var hyperline = hs.First();

                    if (!WordUtils.IsHyperlinkValid(hyperline))
                    {
                        return(null);
                    }

                    Uri tempUri = new Uri(hyperline.Address);
                    var src     = tempUri.AbsolutePath;
                    //XElement wrapper = GetImageElement(src, hyperline.ScreenTip);
                    XElement wrapper = GetImageElement(src);
                    return(wrapper);
                }
                catch (WebException e)
                {
                    Globals.SitecoreAddin.LogException("", e);
                    Globals.SitecoreAddin.AlertConnectionFailure();
                }
                catch (Exception e)
                {
                    Globals.SitecoreAddin.LogException("", e);
                    throw;
                }
            }
            if (ImageStyles.Contains(style.NameLocal))
            {
                WordStyleStruct w;
                if (!ParagraphStyles.TryGetValue(style.NameLocal, out w))
                {
                    return(null);
                }
                var element = new XElement("p");
                element.SetAttributeValue("class", w.CssClass);
                element = Transformer.GetCharacterStyledElement(element, paragraph, CharacterStyleFactory.GetCharacterStyles(), false);//new XElement(w.CssElement);

                //var value = Transformer.GetCharacterStylesValue(paragraph).Replace("\a", "");
                string value = element.Value;
                if (value.StartsWith("SOURCE: "))
                {
                    element.Value = value.Remove(0, 8);
                }
                return(element);
            }
            return(null);
        }
Esempio n. 2
0
        public static XElement Generate(List <Paragraph> paragaphs, OptimizedCharacterStyleTransformer transformer)
        {
            var blockquote = new XElement("blockquote");

            blockquote.SetAttributeValue("class", "article-pullquote");
            foreach (Paragraph p in paragaphs)
            {
                var paragraphXml = new XElement("p");
                paragraphXml = transformer.GetCharacterStyledElement(paragraphXml, p, CharacterStyleFactory.GetCharacterStyles(), false);
                blockquote.Add(paragraphXml);
            }
            return(blockquote);
        }