Esempio n. 1
0
        /// <summary>
        /// Convert FB2 internal link
        /// </summary>
        /// <param name="internalLinkItem">item to convert</param>
        /// <param name="compatibility"></param>
        /// <param name="internalLinkConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public List <IHTMLItem> Convert(InternalLinkItem internalLinkItem,
                                        InternalLinkConverterParamsV2 internalLinkConverterParams)
        {
            if (internalLinkItem == null)
            {
                throw new ArgumentNullException("internalLinkItem");
            }
            var list = new List <IHTMLItem>();

            if (!string.IsNullOrEmpty(internalLinkItem.HRef) && internalLinkItem.HRef != "#")
            {
                var  anchor       = new Anchor(HTMLElementType.XHTML11);
                bool internalLink = false;
                if (!ReferencesUtils.IsExternalLink(internalLinkItem.HRef))
                {
                    if (internalLinkItem.HRef.StartsWith("#"))
                    {
                        internalLinkItem.HRef = internalLinkItem.HRef.Substring(1);
                    }
                    internalLinkItem.HRef =
                        internalLinkConverterParams.Settings.ReferencesManager.EnsureGoodId(internalLinkItem.HRef);
                    internalLink = true;
                }
                anchor.HRef.Value = internalLinkItem.HRef;
                if (internalLink)
                {
                    internalLinkConverterParams.Settings.ReferencesManager.AddReference(internalLinkItem.HRef, anchor);
                }
                if (internalLinkItem.LinkText != null)
                {
                    var tempConverter = new SimpleTextElementConverterV2();
                    foreach (var s in tempConverter.Convert(internalLinkItem.LinkText,
                                                            new SimpleTextElementConverterParamsV2
                    {
                        Settings = internalLinkConverterParams.Settings,
                        NeedToInsertDrop = internalLinkConverterParams.NeedToInsertDrop
                    }
                                                            ))
                    {
                        s.Parent = anchor;
                        anchor.Add(s);
                    }
                }
                list.Add(anchor);
                return(list);
            }
            var converter = new SimpleTextElementConverterV2();

            return(converter.Convert(internalLinkItem.LinkText,
                                     new SimpleTextElementConverterParamsV2
            {
                Settings = internalLinkConverterParams.Settings,
                NeedToInsertDrop = internalLinkConverterParams.NeedToInsertDrop
            }));
        }
 /// <summary>
 /// Convert FB2 internal link 
 /// </summary>
 /// <param name="internalLinkItem">item to convert</param>
 /// <param name="compatibility"></param>
 /// <param name="internalLinkConverterParams"></param>
 /// <returns>XHTML representation</returns>
 public List<IHTMLItem> Convert(InternalLinkItem internalLinkItem, 
     InternalLinkConverterParamsV2 internalLinkConverterParams)
 {
     if (internalLinkItem == null)
     {
         throw new ArgumentNullException("internalLinkItem");
     }
     var list = new List<IHTMLItem>();
     if (!string.IsNullOrEmpty(internalLinkItem.HRef) && internalLinkItem.HRef != "#")
     {
         var anchor = new Anchor(HTMLElementType.XHTML11);
         bool internalLink = false;
         if (!ReferencesUtils.IsExternalLink(internalLinkItem.HRef))
         {
             if (internalLinkItem.HRef.StartsWith("#"))
             {
                 internalLinkItem.HRef = internalLinkItem.HRef.Substring(1);
             }
             internalLinkItem.HRef =
                 internalLinkConverterParams.Settings.ReferencesManager.EnsureGoodId(internalLinkItem.HRef);
             internalLink = true;
         }
         anchor.HRef.Value = internalLinkItem.HRef;
         if (internalLink)
         {
             internalLinkConverterParams.Settings.ReferencesManager.AddReference(internalLinkItem.HRef, anchor);
         }
         if (internalLinkItem.LinkText != null)
         {
             var tempConverter = new SimpleTextElementConverterV2();
             foreach (var s in tempConverter.Convert(internalLinkItem.LinkText,
                 new SimpleTextElementConverterParamsV2
                 {
                     Settings = internalLinkConverterParams.Settings,
                     NeedToInsertDrop = internalLinkConverterParams.NeedToInsertDrop
                 }
                 ))
             {
                 s.Parent = anchor;
                 anchor.Add(s);
             }
         }
         list.Add(anchor);
         return list;
     }
     var converter = new SimpleTextElementConverterV2();
     return converter.Convert(internalLinkItem.LinkText,
         new SimpleTextElementConverterParamsV2
         {
             Settings = internalLinkConverterParams.Settings,
             NeedToInsertDrop = internalLinkConverterParams.NeedToInsertDrop
         });
 }
        /// <summary>
        /// Converts FB2 Paragraph to EPUB paragraph
        /// </summary>
        /// <param name="paragraphItem">item to convert</param>
        /// <param name="paragraphConverterParams"></param>
        /// <returns></returns>
        public HTMLItem Convert(ParagraphItem paragraphItem,ParagraphConverterParamsV2 paragraphConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }
            var paragraph = CreateBlock(paragraphConverterParams.ResultType);
            bool needToInsertDrop = paragraphConverterParams.Settings.CapitalDrop && paragraphConverterParams.StartSection;

            foreach (var item in paragraphItem.ParagraphData)
            {
                if (item is SimpleText)
                {
                    var textConverter = new SimpleTextElementConverterV2();
                    foreach (var s in textConverter.Convert(item,
                        new SimpleTextElementConverterParamsV2 { Settings = paragraphConverterParams.Settings, NeedToInsertDrop = needToInsertDrop}))
                    {
                        if (needToInsertDrop)
                        {
                            needToInsertDrop = false;
                            SetClassType(paragraph, ElementStylesV2.CapitalDrop);
                        }
                        paragraph.Add(s);
                    }
                }
                else if (item is InlineImageItem)
                {
                    // if no image data - do not insert link
                    if (paragraphConverterParams.Settings.Images.HasRealImages())
                    {
                        var inlineItem = item as InlineImageItem;
                        if (paragraphConverterParams.Settings.Images.IsImageIdReal(inlineItem.HRef))
                        {
                            var inlineImageConverter = new InlineImageConverterV2();
                            paragraph.Add(inlineImageConverter.Convert(inlineItem,new InlineImageConverterParamsV2{ Settings = paragraphConverterParams.Settings }));
                            paragraphConverterParams.Settings.Images.ImageIdUsed(inlineItem.HRef);
                        }
                        if (needToInsertDrop) // in case this is "drop" image - no need to create a drop
                        {
                            needToInsertDrop = false;
                        }
                    }
                }
                else if (item is InternalLinkItem)
                {
                    var internalLinkConverter = new InternalLinkConverterV2();
                    foreach (var s in internalLinkConverter.Convert(item as InternalLinkItem,
                        new InternalLinkConverterParamsV2{ Settings = paragraphConverterParams.Settings,  NeedToInsertDrop = needToInsertDrop}))
                    {
                        if (needToInsertDrop)
                        {
                            needToInsertDrop = false;
                            SetClassType(paragraph, ElementStylesV2.CapitalDrop);
                        }
                        paragraph.Add(s);
                    }
                }
            }

            //SetClassType(paragraph);
            paragraph.GlobalAttributes.ID.Value =
                paragraphConverterParams.Settings.ReferencesManager.AddIdUsed(paragraphItem.ID, paragraph);

            return paragraph;
        }
Esempio n. 4
0
        /// <summary>
        /// Converts FB2 Paragraph to EPUB paragraph
        /// </summary>
        /// <param name="paragraphItem">item to convert</param>
        /// <param name="paragraphConverterParams"></param>
        /// <returns></returns>
        public HTMLItem Convert(ParagraphItem paragraphItem, ParagraphConverterParamsV2 paragraphConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }
            var  paragraph        = CreateBlock(paragraphConverterParams.ResultType);
            bool needToInsertDrop = paragraphConverterParams.Settings.CapitalDrop && paragraphConverterParams.StartSection;

            foreach (var item in paragraphItem.ParagraphData)
            {
                if (item is SimpleText)
                {
                    var textConverter = new SimpleTextElementConverterV2();
                    foreach (var s in textConverter.Convert(item,
                                                            new SimpleTextElementConverterParamsV2 {
                        Settings = paragraphConverterParams.Settings, NeedToInsertDrop = needToInsertDrop
                    }))
                    {
                        if (needToInsertDrop)
                        {
                            needToInsertDrop = false;
                            SetClassType(paragraph, ElementStylesV2.CapitalDrop);
                        }
                        paragraph.Add(s);
                    }
                }
                else if (item is InlineImageItem)
                {
                    // if no image data - do not insert link
                    if (paragraphConverterParams.Settings.Images.HasRealImages())
                    {
                        var inlineItem = item as InlineImageItem;
                        if (paragraphConverterParams.Settings.Images.IsImageIdReal(inlineItem.HRef))
                        {
                            var inlineImageConverter = new InlineImageConverterV2();
                            paragraph.Add(inlineImageConverter.Convert(inlineItem, new InlineImageConverterParamsV2 {
                                Settings = paragraphConverterParams.Settings
                            }));
                            paragraphConverterParams.Settings.Images.ImageIdUsed(inlineItem.HRef);
                        }
                        if (needToInsertDrop) // in case this is "drop" image - no need to create a drop
                        {
                            needToInsertDrop = false;
                        }
                    }
                }
                else if (item is InternalLinkItem)
                {
                    var internalLinkConverter = new InternalLinkConverterV2();
                    foreach (var s in internalLinkConverter.Convert(item as InternalLinkItem,
                                                                    new InternalLinkConverterParamsV2 {
                        Settings = paragraphConverterParams.Settings, NeedToInsertDrop = needToInsertDrop
                    }))
                    {
                        if (needToInsertDrop)
                        {
                            needToInsertDrop = false;
                            SetClassType(paragraph, ElementStylesV2.CapitalDrop);
                        }
                        paragraph.Add(s);
                    }
                }
            }

            //SetClassType(paragraph);
            paragraph.GlobalAttributes.ID.Value =
                paragraphConverterParams.Settings.ReferencesManager.AddIdUsed(paragraphItem.ID, paragraph);

            return(paragraph);
        }