/// <summary>
        /// Convert FB2 "notes" and "comments" and other "additional" sections
        /// </summary>
        /// <param name="linkSectionItem">item to convert</param>
        /// <param name="linkSectionConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(SectionItem linkSectionItem, LinkSectionConverterParamsV2 linkSectionConverterParams)
        {
            if (linkSectionItem == null)
            {
                throw new ArgumentNullException("linkSectionItem");
            }
            var content        = new Div(HTMLElementType.XHTML11);
            var a              = new Anchor(HTMLElementType.XHTML11);
            var titleConverter = new TitleConverterV2();

            foreach (var item in titleConverter.Convert(linkSectionItem.Title, new TitleConverterParamsV2 {
                Settings = linkSectionConverterParams.Settings, TitleLevel = 2
            }).SubElements())
            {
                content.Add(item);
            }
            string newId = linkSectionConverterParams.Settings.ReferencesManager.EnsureGoodId(linkSectionItem.ID);

            a.Add(new SimpleHTML5Text(HTMLElementType.XHTML11)
            {
                Text = newId
            });
            a.HRef.Value = string.Format("{0}_back", newId);
            if (((string)a.HRef.Value).StartsWith("_back") == false)
            {
                SetClassType(a, ElementStylesV2.NoteAnchor);
                linkSectionConverterParams.Settings.ReferencesManager.AddBackReference((string)a.HRef.Value, a);
                //content.Add(a);
            }
            SetClassType(content, ElementStylesV2.NoteSection);
            return(content);
        }
 /// <summary>
 /// Convert FB2 "notes" and "comments" and other "additional" sections
 /// </summary>
 /// <param name="linkSectionItem">item to convert</param>
 /// <param name="linkSectionConverterParams"></param>
 /// <returns>XHTML representation</returns>
 public IHTMLItem Convert(SectionItem linkSectionItem,LinkSectionConverterParamsV2 linkSectionConverterParams)
 {
     if (linkSectionItem == null)
     {
         throw new ArgumentNullException("linkSectionItem");
     }
     var content = new Div(HTMLElementType.XHTML11);
     var a = new Anchor(HTMLElementType.XHTML11);
     var titleConverter = new TitleConverterV2();
     foreach (var item in titleConverter.Convert(linkSectionItem.Title,new TitleConverterParamsV2{Settings = linkSectionConverterParams.Settings,TitleLevel = 2}).SubElements())
     {
         content.Add(item);
     }
     string newId = linkSectionConverterParams.Settings.ReferencesManager.EnsureGoodId(linkSectionItem.ID);
     a.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = newId });
     a.HRef.Value = string.Format("{0}_back", newId);
     if (((string)a.HRef.Value).StartsWith("_back") == false)
     {
         SetClassType(a, ElementStylesV2.NoteAnchor);
         linkSectionConverterParams.Settings.ReferencesManager.AddBackReference((string)a.HRef.Value, a);
         //content.Add(a);
     }
     SetClassType(content, ElementStylesV2.NoteSection);
     return content;
 }
Esempio n. 3
0
        /// <summary>
        /// Add and convert generic secondary body section
        /// </summary>
        /// <param name="bookStructureManager"></param>
        /// <param name="bodyItem"></param>
        private void AddSecondaryBody(BookStructureManager bookStructureManager, BodyItem bodyItem)
        {
            string docTitle = string.Empty;

            if (string.IsNullOrEmpty(bodyItem.Name))
            {
                if (bodyItem.Title != null)
                {
                    docTitle = bodyItem.Title.ToString();
                }
            }
            else
            {
                docTitle = bodyItem.Name;
            }
            Logger.Log.DebugFormat("Adding section : {0}", docTitle);
            var sectionDocument = new BaseXHTMLFileV2
            {
                Id                   = docTitle,
                GuideRole            = GuideTypeEnum.Text,
                Type                 = SectionTypeEnum.Text,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                Content              = new Div(BaseXHTMLFileV2.Compatibility),
                NavigationParent     = null,
                NotPartOfNavigation  = false,
                FileName             = string.Format("section{0}.xhtml", ++_sectionCounter)
            };

            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                                                                   new TitleConverterParamsV2 {
                    Settings = converterSettings, TitleLevel = 1
                }));
            }
            bookStructureManager.AddBookPage(sectionDocument);


            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(bookStructureManager, section, sectionDocument, false);
            }
        }
        /// <summary>
        /// Add and convert FBE style generated notes sections
        /// </summary>
        /// <param name="epubFile"></param>
        /// <param name="bodyItem"></param>
        private void AddFbeNotesBody(EPubFileV2 epubFile, BodyItem bodyItem)
        {
            string docTitle = bodyItem.Name;

            Logger.Log.DebugFormat("Adding section : {0}", docTitle);
            var sectionDocument = new BaseXHTMLFileV2
            {
                PageTitle            = docTitle,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                GuideRole            = GuideTypeEnum.Glossary,
                Type                = SectionTypeEnum.Links,
                Content             = new Div(BaseXHTMLFileV2.Compatibility),
                NavigationParent    = null,
                NotPartOfNavigation = true,
                FileName            = string.Format("section{0}.xhtml", ++_sectionCounter),
            };

            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop       = false,
                    Images            = _images,
                    MaxSize           = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                                                                   new TitleConverterParamsV2 {
                    Settings = converterSettings, TitleLevel = 1
                }));
            }
            epubFile.AddXHTMLFile(sectionDocument);

            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(epubFile, section, sectionDocument, true);
            }
        }
Esempio n. 5
0
        public void Convert(EPubFileV2 epubFile, FB2File fb2File)
        {
            // create second title page
            if ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString())))
            {
                string docTitle = fb2File.MainBody.Title.ToString();
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                BaseXHTMLFileV2 addTitlePage = new BaseXHTMLFileV2
                {
                    GuideRole = GuideTypeEnum.TitlePage,
                    Content = new Div(BaseXHTMLFileV2.Compatibility),
                    Type = SectionTypeEnum.Text,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    NavigationParent = null,
                    FileName = string.Format("section{0}.xhtml", ++_sectionCounter),
                    NotPartOfNavigation = true,
                    PageTitle = docTitle,
                };
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title,
                    new TitleConverterParamsV2 { Settings = converterSettings, TitleLevel = 2 }));
                epubFile.AddXHTMLFile(addTitlePage);
            }

            BaseXHTMLFileV2 mainDocument = null;
            if (!string.IsNullOrEmpty(fb2File.MainBody.Name))
            {
                string docTitle = fb2File.MainBody.Name;
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                mainDocument = new BaseXHTMLFileV2
                {
                    PageTitle = docTitle,
                    GuideRole = GuideTypeEnum.Text,
                    Content = new Div(BaseXHTMLFileV2.Compatibility),
                    Type = SectionTypeEnum.Text,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    NavigationParent = null,
                    FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                };
                epubFile.AddXHTMLFile(mainDocument);
            }

            if ((fb2File.MainBody.ImageName != null) && !string.IsNullOrEmpty(fb2File.MainBody.ImageName.HRef))
            {
                if (mainDocument == null)
                {
                    string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main";
                    mainDocument = new BaseXHTMLFileV2
                    {
                        PageTitle = newDocTitle,
                        GuideRole = GuideTypeEnum.Text,
                        Content = new Div(BaseXHTMLFileV2.Compatibility),
                        NavigationParent = null,
                        Type = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                    epubFile.AddXHTMLFile(mainDocument);
                }
                if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef))
                {
                    var enclosing = new Div(HTMLElementType.XHTML11); // we use the enclosing so the user can style center it
                    var converterSettings = new ConverterOptionsV2
                    {
                        CapitalDrop = _commonSettings.CapitalDrop,
                        Images = _images,
                        MaxSize = _maxSize,
                        ReferencesManager = _referencesManager,
                    };

                    var imageConverter = new ImageConverterV2();
                    enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV2 { Settings = converterSettings }));
                    SetClassType(enclosing, ElementStylesV2.BodyImage);
                    mainDocument.Content.Add(enclosing);
                }


            }
            foreach (var ep in fb2File.MainBody.Epigraphs)
            {
                if (mainDocument == null)
                {
                    string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main";
                    mainDocument = new BaseXHTMLFileV2
                    {
                        PageTitle = newDocTitle,
                        GuideRole = GuideTypeEnum.Text,
                        Content = new Div(BaseXHTMLFileV2.Compatibility),
                        NavigationParent = null,
                        Type = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                }
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };

                var epigraphConverter = new MainEpigraphConverterV2();
                mainDocument.Content.Add(epigraphConverter.Convert(ep,
                    new EpigraphConverterParamsV2 { Settings = converterSettings, Level = 1 }));
                epubFile.AddXHTMLFile(mainDocument);
            }

            Logger.Log.Debug("Adding main sections");
            foreach (var section in fb2File.MainBody.Sections)
            {
                AddSection(epubFile, section, mainDocument, false);
            }

            Logger.Log.Debug("Adding secondary bodies");
            foreach (var bodyItem in fb2File.Bodies)
            {
                if (bodyItem == fb2File.MainBody)
                {
                    continue;
                }
                bool fbeNotesSection = FBENotesSection(bodyItem.Name);
                if (fbeNotesSection)
                {
                    AddFbeNotesBody(epubFile, bodyItem);
                }
                else
                {
                    AddSecondaryBody(epubFile, bodyItem);
                }
            }          
        }
Esempio n. 6
0
        /// <summary>
        /// Add and convert generic secondary body section
        /// </summary>
        /// <param name="epubFile"></param>
        /// <param name="bodyItem"></param>
        private void AddSecondaryBody(EPubFileV2 epubFile, BodyItem bodyItem)
        {
            string docTitle = string.Empty;
            if (string.IsNullOrEmpty(bodyItem.Name))
            {
                if (bodyItem.Title != null)
                {
                    docTitle = bodyItem.Title.ToString();
                }
            }
            else
            {
                docTitle = bodyItem.Name;
            }
            Logger.Log.DebugFormat("Adding section : {0}", docTitle);
            var sectionDocument = new BaseXHTMLFileV2
            {
                Id = docTitle,
                GuideRole = GuideTypeEnum.Text,
                Type = SectionTypeEnum.Text,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                Content = new Div(BaseXHTMLFileV2.Compatibility),
                NavigationParent = null,
                NotPartOfNavigation = false,
                FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
            };

            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                    new TitleConverterParamsV2 { Settings = converterSettings, TitleLevel = 1 }));
            }
            epubFile.AddXHTMLFile(sectionDocument);


            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(epubFile, section, sectionDocument, false);
            }
        }
Esempio n. 7
0
        public void Convert(BookStructureManager bookStructureManager, FB2File fb2File)
        {
            // create second title page
            if ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString())))
            {
                string docTitle = fb2File.MainBody.Title.ToString();
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                BaseXHTMLFileV2 addTitlePage = new BaseXHTMLFileV2
                {
                    GuideRole            = GuideTypeEnum.TitlePage,
                    Content              = new Div(BaseXHTMLFileV2.Compatibility),
                    Type                 = SectionTypeEnum.Text,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    NavigationParent     = null,
                    FileName             = string.Format("section{0}.xhtml", ++_sectionCounter),
                    NotPartOfNavigation  = true,
                    PageTitle            = docTitle,
                };
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title,
                                                                new TitleConverterParamsV2 {
                    Settings = converterSettings, TitleLevel = 2
                }));
                bookStructureManager.AddTitlePage(addTitlePage);
            }

            BaseXHTMLFileV2 mainDocument = null;

            if (!string.IsNullOrEmpty(fb2File.MainBody.Name))
            {
                string docTitle = fb2File.MainBody.Name;
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                mainDocument = new BaseXHTMLFileV2
                {
                    PageTitle            = docTitle,
                    GuideRole            = GuideTypeEnum.Text,
                    Content              = new Div(BaseXHTMLFileV2.Compatibility),
                    Type                 = SectionTypeEnum.Text,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    NavigationParent     = null,
                    FileName             = string.Format("section{0}.xhtml", ++_sectionCounter)
                };
                bookStructureManager.AddBookPage(mainDocument);
            }

            if ((fb2File.MainBody.ImageName != null) && !string.IsNullOrEmpty(fb2File.MainBody.ImageName.HRef))
            {
                if (mainDocument == null)
                {
                    string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main";
                    mainDocument = new BaseXHTMLFileV2
                    {
                        PageTitle            = newDocTitle,
                        GuideRole            = GuideTypeEnum.Text,
                        Content              = new Div(BaseXHTMLFileV2.Compatibility),
                        NavigationParent     = null,
                        Type                 = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        FileName             = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                    bookStructureManager.AddBookPage(mainDocument);
                }
                if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef))
                {
                    var enclosing         = new Div(HTMLElementType.XHTML11); // we use the enclosing so the user can style center it
                    var converterSettings = new ConverterOptionsV2
                    {
                        CapitalDrop       = _commonSettings.CapitalDrop,
                        Images            = _images,
                        MaxSize           = _maxSize,
                        ReferencesManager = _referencesManager,
                    };

                    var imageConverter = new ImageConverterV2();
                    enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV2 {
                        Settings = converterSettings
                    }));
                    SetClassType(enclosing, ElementStylesV2.BodyImage);
                    mainDocument.Content.Add(enclosing);
                }
            }
            foreach (var ep in fb2File.MainBody.Epigraphs)
            {
                if (mainDocument == null)
                {
                    string newDocTitle = ((fb2File.MainBody.Title != null) && (!string.IsNullOrEmpty(fb2File.MainBody.Title.ToString()))) ? fb2File.MainBody.Title.ToString() : "main";
                    mainDocument = new BaseXHTMLFileV2
                    {
                        PageTitle            = newDocTitle,
                        GuideRole            = GuideTypeEnum.Text,
                        Content              = new Div(BaseXHTMLFileV2.Compatibility),
                        NavigationParent     = null,
                        Type                 = SectionTypeEnum.Text,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        FileName             = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                }
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _maxSize,
                    ReferencesManager = _referencesManager,
                };

                var epigraphConverter = new MainEpigraphConverterV2();
                mainDocument.Content.Add(epigraphConverter.Convert(ep,
                                                                   new EpigraphConverterParamsV2 {
                    Settings = converterSettings, Level = 1
                }));
                bookStructureManager.AddBookPage(mainDocument);
            }

            Logger.Log.Debug("Adding main sections");
            foreach (var section in fb2File.MainBody.Sections)
            {
                AddSection(bookStructureManager, section, mainDocument, false);
            }

            Logger.Log.Debug("Adding secondary bodies");
            foreach (var bodyItem in fb2File.Bodies)
            {
                if (bodyItem == fb2File.MainBody)
                {
                    continue;
                }
                bool fbeNotesSection = FBENotesSection(bodyItem.Name);
                if (fbeNotesSection)
                {
                    AddFbeNotesBody(bookStructureManager, bodyItem);
                }
                else
                {
                    AddSecondaryBody(bookStructureManager, bodyItem);
                }
            }
        }
        /// <summary>
        /// Add and convert FBE style generated notes sections
        /// </summary>
        /// <param name="bookStructureManager"></param>
        /// <param name="bodyItem"></param>
        private void AddFbeNotesBody(BookStructureManager bookStructureManager, BodyItem bodyItem)
        {
            string docTitle = bodyItem.Name;
            Logger.Log.DebugFormat("Adding section : {0}", docTitle);
            var sectionDocument = new BaseXHTMLFileV2
            {
                PageTitle = docTitle,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                GuideRole = GuideTypeEnum.Glossary,
                Type = SectionTypeEnum.Links,
                Content = new Div(BaseXHTMLFileV2.Compatibility),
                NavigationParent = null,
                NotPartOfNavigation = true,
                FileName = string.Format("section{0}.xhtml", ++_sectionCounter),

            };
            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV2
                {
                    CapitalDrop = false,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV2();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                    new TitleConverterParamsV2 { Settings = converterSettings, TitleLevel = 1 }));
            }
            bookStructureManager.AddBookPage(sectionDocument);

            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(bookStructureManager, section, sectionDocument, true);
            }
        }
        /// <summary>
        /// Converts FB2 section element
        /// </summary>
        /// <param name="sectionItem">item to convert</param>
        /// <returns>XHTML representation</returns>
        public List<IHTMLItem> Convert(SectionItem sectionItem)
        {
            if (sectionItem == null)
            {
                throw new ArgumentNullException("sectionItem");
            }
            var resList = new List<IHTMLItem>();
            Logger.Log.Debug("Converting section");

            var content = new Div(HTMLElementType.XHTML11);
            ulong documentSize = 0;
            _checker.MaxSizeLimit = Settings.MaxSize;

            SetClassType(content, string.Format(ElementStylesV2.SectionItemFormat, RecursionLevel));

            content.GlobalAttributes.ID.Value = Settings.ReferencesManager.AddIdUsed(sectionItem.ID, content);

            if (sectionItem.Lang != null)
            {
                content.GlobalAttributes.Language.Value = sectionItem.Lang;
            }

            // Load Title
            if (sectionItem.Title != null)
            {
                IHTMLItem titleItem;
                if (!LinkSection)
                {
                    var titleConverter = new TitleConverterV2();
                    titleItem = titleConverter.Convert(sectionItem.Title,
                        new TitleConverterParamsV2 { Settings = Settings, TitleLevel = RecursionLevel + 1 });
                }
                else
                {
                    var linkSectionConverter = new LinkSectionConverterV2();
                    titleItem = linkSectionConverter.Convert(sectionItem,
                        new LinkSectionConverterParamsV2{Settings = Settings});
                }
                if (titleItem != null)
                {
                    documentSize = SplitBlockHTMLItem(titleItem, content, resList, documentSize);
                }
            }

            // Load epigraphs
            documentSize = (from epigraph in sectionItem.Epigraphs let epigraphConverter = new EpigraphConverterV2() select epigraphConverter.Convert(epigraph, new EpigraphConverterParamsV2 {Settings = Settings, Level = RecursionLevel + 1})).Aggregate(documentSize, (current, epigraphItem) => SplitBlockHTMLItem(epigraphItem, content, resList, current));

            // Load section image
            if (Settings.Images.HasRealImages())
            {
                documentSize = sectionItem.SectionImages.Aggregate(documentSize, (current, sectionImage) => ConvertSectionImage(sectionImage, content, resList, current));
            }

            // Load annotations
            if (sectionItem.Annotation != null)
            {
                var annotationConverter = new AnnotationConverterV2();
                IHTMLItem annotationItem = annotationConverter.Convert(sectionItem.Annotation,  new AnnotationConverterParamsV2{ Level = RecursionLevel + 1 ,Settings = Settings});
                documentSize = SplitBlockHTMLItem(annotationItem, content, resList, documentSize);
            }

            // Parse all elements only if section has no sub section
            if (sectionItem.SubSections.Count == 0)
            {
                bool startSection = true;
                sectionItem.Content.Aggregate(documentSize, (current, item) => ConvertSimpleSubItem(item, sectionItem, content, resList, ref startSection, current));
            }

            resList.Add(content);
            return resList;
        }
Esempio n. 10
0
        /// <summary>
        /// Converts FB2 section element
        /// </summary>
        /// <param name="sectionItem">item to convert</param>
        /// <returns>XHTML representation</returns>
        public List <IHTMLItem> Convert(SectionItem sectionItem)
        {
            if (sectionItem == null)
            {
                throw new ArgumentNullException("sectionItem");
            }
            var resList = new List <IHTMLItem>();

            Logger.Log.Debug("Converting section");

            var   content      = new Div(HTMLElementType.XHTML11);
            ulong documentSize = 0;

            _checker.MaxSizeLimit = Settings.MaxSize;

            SetClassType(content, string.Format(ElementStylesV2.SectionItemFormat, RecursionLevel));

            content.GlobalAttributes.ID.Value = Settings.ReferencesManager.AddIdUsed(sectionItem.ID, content);

            if (sectionItem.Lang != null)
            {
                content.GlobalAttributes.Language.Value = sectionItem.Lang;
            }


            // Load Title
            if (sectionItem.Title != null)
            {
                IHTMLItem titleItem;
                if (!LinkSection)
                {
                    var titleConverter = new TitleConverterV2();
                    titleItem = titleConverter.Convert(sectionItem.Title,
                                                       new TitleConverterParamsV2 {
                        Settings = Settings, TitleLevel = RecursionLevel + 1
                    });
                }
                else
                {
                    var linkSectionConverter = new LinkSectionConverterV2();
                    titleItem = linkSectionConverter.Convert(sectionItem,
                                                             new LinkSectionConverterParamsV2 {
                        Settings = Settings
                    });
                }
                if (titleItem != null)
                {
                    documentSize = SplitBlockHTMLItem(titleItem, content, resList, documentSize);
                }
            }

            // Load epigraphs
            documentSize = (from epigraph in sectionItem.Epigraphs let epigraphConverter = new EpigraphConverterV2() select epigraphConverter.Convert(epigraph, new EpigraphConverterParamsV2 {
                Settings = Settings, Level = RecursionLevel + 1
            })).Aggregate(documentSize, (current, epigraphItem) => SplitBlockHTMLItem(epigraphItem, content, resList, current));

            // Load section image
            if (Settings.Images.HasRealImages())
            {
                documentSize = sectionItem.SectionImages.Aggregate(documentSize, (current, sectionImage) => ConvertSectionImage(sectionImage, content, resList, current));
            }

            // Load annotations
            if (sectionItem.Annotation != null)
            {
                var       annotationConverter = new AnnotationConverterV2();
                IHTMLItem annotationItem      = annotationConverter.Convert(sectionItem.Annotation, new AnnotationConverterParamsV2 {
                    Level = RecursionLevel + 1, Settings = Settings
                });
                documentSize = SplitBlockHTMLItem(annotationItem, content, resList, documentSize);
            }

            // Parse all elements only if section has no sub section
            if (sectionItem.SubSections.Count == 0)
            {
                bool startSection = true;
                sectionItem.Content.Aggregate(documentSize, (current, item) => ConvertSimpleSubItem(item, sectionItem, content, resList, ref startSection, current));
            }

            resList.Add(content);
            return(resList);
        }