Example #1
0
        /// <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, LinkSectionConverterParamsV3 linkSectionConverterParams)
        {
            if (linkSectionItem == null)
            {
                throw new ArgumentNullException("linkSectionItem");
            }
            var content = new Div(HTMLElementType.HTML5);
            var a = new Anchor(HTMLElementType.HTML5);
            var titleConverter = new TitleConverterV3();
            foreach (var item in titleConverter.Convert(linkSectionItem.Title, new TitleConverterParamsV3 { Settings = linkSectionConverterParams.Settings, TitleLevel = 2 }).SubElements())
            {
                content.Add(item);
            }
            string newId = linkSectionConverterParams.Settings.ReferencesManager.EnsureGoodId(linkSectionItem.ID);
            a.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = newId });
            a.HRef.Value = string.Format("{0}_back", newId);
            if (((string)a.HRef.Value).StartsWith("_back") == false)
            {
                SetClassType(a, ElementStylesV3.NoteAnchor);
                linkSectionConverterParams.Settings.ReferencesManager.AddBackReference((string)a.HRef.Value, a);
                //content.Add(a);
            }
            SetClassType(content, ElementStylesV3.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, LinkSectionConverterParamsV3 linkSectionConverterParams)
        {
            if (linkSectionItem == null)
            {
                throw new ArgumentNullException("linkSectionItem");
            }
            var content        = new Div(HTMLElementType.HTML5);
            var a              = new Anchor(HTMLElementType.HTML5);
            var titleConverter = new TitleConverterV3();

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

            a.Add(new SimpleHTML5Text(HTMLElementType.HTML5)
            {
                Text = newId
            });
            a.HRef.Value = string.Format("{0}_back", newId);
            if (((string)a.HRef.Value).StartsWith("_back") == false)
            {
                SetClassType(a, ElementStylesV3.NoteAnchor);
                linkSectionConverterParams.Settings.ReferencesManager.AddBackReference((string)a.HRef.Value, a);
                //content.Add(a);
            }
            SetClassType(content, ElementStylesV3.NoteSection);
            return(content);
        }
        /// <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 BaseXHTMLFileV3
            {
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                GuideRole            = GuideTypeEnum.Text,
                Content             = new Div(HTMLElementType.HTML5),
                NavigationParent    = null,
                NotPartOfNavigation = false,
                FileName            = BuildSectionFileName(),
                PageTitle           = docTitle,
            };

            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _v3Settings.HTMLFileMaxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV3();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                                                                   new TitleConverterParamsV3 {
                    Settings = converterSettings, TitleLevel = 1
                }));
            }
            bookStructureManager.AddBookPage(sectionDocument);

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

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

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

            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(epubFile, 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.HTML5);
            ulong documentSize = 0;
            _checker.MaxSizeLimit = Settings.MaxSize;

            SetClassType(content, string.Format(ElementStylesV3.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 TitleConverterV3();
                    titleItem = titleConverter.Convert(sectionItem.Title,
                        new TitleConverterParamsV3 { Settings = Settings, TitleLevel = RecursionLevel + 1 });
                }
                else
                {
                    var linkSectionConverter = new LinkSectionConverterV3();
                    titleItem = linkSectionConverter.Convert(sectionItem,
                        new LinkSectionConverterParamsV3 { Settings = Settings });
                }
                if (titleItem != null)
                {
                    documentSize = SplitBlockHTMLItem(titleItem,content,resList,documentSize);
                }
            }

            // Load epigraphs
            documentSize = (from epigraph in sectionItem.Epigraphs let epigraphConverter = new EpigraphConverterV3() select epigraphConverter.Convert(epigraph, new EpigraphConverterParamsV3 {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 AnnotationConverterV3();
                IHTMLItem annotationItem = annotationConverter.Convert(sectionItem.Annotation, new AnnotationConverterParamsV3 { 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;
        }
        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);
                var addTitlePage = new BaseXHTMLFileV3
                {
                    PageTitle            = docTitle,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    GuideRole            = GuideTypeEnum.TitlePage,
                    Content             = new Div(HTMLElementType.HTML5),
                    NavigationParent    = null,
                    FileName            = BuildSectionFileName(),
                    NotPartOfNavigation = true
                };
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _v3Settings.HTMLFileMaxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV3();
                addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title,
                                                                new TitleConverterParamsV3 {
                    Settings = converterSettings, TitleLevel = 2
                }));

                bookStructureManager.AddTitlePage(addTitlePage);
            }

            BaseXHTMLFileV3 mainDocument = null;

            if (!string.IsNullOrEmpty(fb2File.MainBody.Name))
            {
                string docTitle = fb2File.MainBody.Name;
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                mainDocument = new BaseXHTMLFileV3
                {
                    PageTitle            = docTitle,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    GuideRole            = GuideTypeEnum.Text,
                    Content          = new Div(HTMLElementType.HTML5),
                    NavigationParent = null,
                    FileName         = BuildSectionFileName()
                };
                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 BaseXHTMLFileV3
                    {
                        PageTitle            = newDocTitle,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        GuideRole            = GuideTypeEnum.Text,
                        Content          = new Div(HTMLElementType.HTML5),
                        NavigationParent = null,
                        FileName         = BuildSectionFileName()
                    };
                    bookStructureManager.AddBookPage(mainDocument);
                }
                if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef))
                {
                    var enclosing         = new Div(HTMLElementType.HTML5); // we use the enclosing so the user can style center it
                    var converterSettings = new ConverterOptionsV3
                    {
                        CapitalDrop       = _commonSettings.CapitalDrop,
                        Images            = _images,
                        MaxSize           = _v3Settings.HTMLFileMaxSize,
                        ReferencesManager = _referencesManager,
                    };

                    var imageConverter = new ImageConverterV3();
                    enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV3 {
                        Settings = converterSettings
                    }));
                    SetClassType(enclosing, ElementStylesV3.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 BaseXHTMLFileV3
                    {
                        PageTitle            = newDocTitle,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        GuideRole            = GuideTypeEnum.Text,
                        Content          = new Div(HTMLElementType.HTML5),
                        NavigationParent = null,
                        FileName         = BuildSectionFileName()
                    };
                    bookStructureManager.AddBookPage(mainDocument);
                }
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop       = _commonSettings.CapitalDrop,
                    Images            = _images,
                    MaxSize           = _v3Settings.HTMLFileMaxSize,
                    ReferencesManager = _referencesManager,
                };

                var epigraphConverter = new MainEpigraphConverterV3();
                mainDocument.Content.Add(epigraphConverter.Convert(ep,
                                                                   new EpigraphConverterParamsV3 {
                    Settings = converterSettings, Level = 1
                }));
            }

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

            Logger.Log.Debug("Adding secondary bodies");
            foreach (var bodyItem in fb2File.Bodies)
            {
                if (bodyItem == fb2File.MainBody)
                {
                    continue;
                }
                bool fbeNotesSection = FBENotesSection(bodyItem.Name);
                if (fbeNotesSection)
                {
                    _notesManager.AddNotesBody(bodyItem);
                }
                else
                {
                    AddSecondaryBody(bookStructureManager, bodyItem);
                }
            }
            foreach (var footNotesAdditionalDocument in _notesManager.GetFootNotesAdditionalDocuments())
            {
                bookStructureManager.AddFootnote(footNotesAdditionalDocument);
            }
        }
        private List<FB2NotesPageSectionFile> AddV2StyleFbeNotesBody(BodyItem bodyItem)
        {
            List<FB2NotesPageSectionFile> documents = new List<FB2NotesPageSectionFile>();
            string docTitle = bodyItem.Name;
            Logger.Log.DebugFormat("Adding notes section : {0}", docTitle);
            var sectionDocument = new FB2NotesPageSectionFile
            {
                PageTitle = docTitle,
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                GuideRole = GuideTypeEnum.Glossary,
                Content = new Div(HTMLElementType.HTML5),
                NavigationParent = null,
                NotPartOfNavigation = true,
                FileName = BuildSectionFileName()
            };
            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop = false,
                    Images = _images,
                    MaxSize = _v3Settings.HTMLFileMaxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV3();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                    new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 1 }));
            }
            documents.Add(sectionDocument);

            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                documents.AddRange(AddSection(section, sectionDocument));
            }
            return documents;
        }
Example #8
0
        public void Convert(EPubFileV3 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);
                var addTitlePage = new BaseXHTMLFileV3
                {
                    PageTitle = docTitle,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    GuideRole = GuideTypeEnum.TitlePage,
                    Content = new Div(HTMLElementType.HTML5),
                    NavigationParent = null,
                    FileName = string.Format("section{0}.xhtml", ++_sectionCounter),
                    NotPartOfNavigation = true
                };
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV3();
                addTitlePage.Content.Add(titleConverter.Convert(fb2File.MainBody.Title,
                    new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 2 }));

                epubFile.AddXHTMLFile(addTitlePage);
            }

            BaseXHTMLFileV3 mainDocument = null;
            if (!string.IsNullOrEmpty(fb2File.MainBody.Name))
            {
                string docTitle = fb2File.MainBody.Name;
                Logger.Log.DebugFormat("Adding section : {0}", docTitle);
                mainDocument = new BaseXHTMLFileV3
                {
                    PageTitle = docTitle,
                    FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                    GuideRole = GuideTypeEnum.Text,
                    Content = new Div(HTMLElementType.HTML5),
                    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 BaseXHTMLFileV3
                    {
                        PageTitle = newDocTitle,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        GuideRole = GuideTypeEnum.Text,
                        Content = new Div(HTMLElementType.HTML5),
                        NavigationParent = null,
                        FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                    epubFile.AddXHTMLFile(mainDocument);
                }
                if (_images.IsImageIdReal(fb2File.MainBody.ImageName.HRef))
                {
                    var enclosing = new Div(HTMLElementType.HTML5); // we use the enclosing so the user can style center it
                    var converterSettings = new ConverterOptionsV3
                    {
                        CapitalDrop = _commonSettings.CapitalDrop,
                        Images = _images,
                        MaxSize = _maxSize,
                        ReferencesManager = _referencesManager,
                    };

                    var imageConverter = new ImageConverterV3();
                    enclosing.Add(imageConverter.Convert(fb2File.MainBody.ImageName, new ImageConverterParamsV3 { Settings = converterSettings }));
                    SetClassType(enclosing, ElementStylesV3.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 BaseXHTMLFileV3
                    {
                        PageTitle = newDocTitle,
                        FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                        GuideRole = GuideTypeEnum.Text,
                        Content = new Div(HTMLElementType.HTML5),
                        NavigationParent = null,
                        FileName = string.Format("section{0}.xhtml", ++_sectionCounter)
                    };
                    epubFile.AddXHTMLFile(mainDocument);
                }
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };

                var epigraphConverter = new MainEpigraphConverterV3();
                mainDocument.Content.Add(epigraphConverter.Convert(ep,
                    new EpigraphConverterParamsV3 { Settings = converterSettings, Level = 1 }));
            }

            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);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Add and convert generic secondary body section
        /// </summary>
        /// <param name="epubFile"></param>
        /// <param name="bodyItem"></param>
        private void AddSecondaryBody(EPubFileV3 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 BaseXHTMLFileV3
            {
                FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder),
                GuideRole = GuideTypeEnum.Text,
                Content = new Div(HTMLElementType.HTML5),
                NavigationParent = null,
                NotPartOfNavigation = false,
                FileName = string.Format("section{0}.xhtml", ++_sectionCounter),
                PageTitle = docTitle,
            };
            if (bodyItem.Title != null)
            {
                var converterSettings = new ConverterOptionsV3
                {
                    CapitalDrop = _commonSettings.CapitalDrop,
                    Images = _images,
                    MaxSize = _maxSize,
                    ReferencesManager = _referencesManager,
                };
                var titleConverter = new TitleConverterV3();
                sectionDocument.Content.Add(titleConverter.Convert(bodyItem.Title,
                    new TitleConverterParamsV3 { Settings = converterSettings, TitleLevel = 1 }));
            }
            epubFile.AddXHTMLFile(sectionDocument);

            Logger.Log.Debug("Adding sub-sections");
            foreach (var section in bodyItem.Sections)
            {
                AddSection(epubFile, section, sectionDocument, false);
            }
        }
        /// <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.HTML5);
            ulong documentSize = 0;

            _checker.MaxSizeLimit = Settings.MaxSize;

            SetClassType(content, string.Format(ElementStylesV3.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 TitleConverterV3();
                    titleItem = titleConverter.Convert(sectionItem.Title,
                                                       new TitleConverterParamsV3 {
                        Settings = Settings, TitleLevel = RecursionLevel + 1
                    });
                }
                else
                {
                    var linkSectionConverter = new LinkSectionConverterV3();
                    titleItem = linkSectionConverter.Convert(sectionItem,
                                                             new LinkSectionConverterParamsV3 {
                        Settings = Settings
                    });
                }
                if (titleItem != null)
                {
                    documentSize = SplitBlockHTMLItem(titleItem, content, resList, documentSize);
                }
            }

            // Load epigraphs
            documentSize = (from epigraph in sectionItem.Epigraphs let epigraphConverter = new EpigraphConverterV3() select epigraphConverter.Convert(epigraph, new EpigraphConverterParamsV3 {
                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 AnnotationConverterV3();
                IHTMLItem annotationItem      = annotationConverter.Convert(sectionItem.Annotation, new AnnotationConverterParamsV3 {
                    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);
        }