Bloom.Book.HtmlDom.GetTemplateStyleSheets C# (CSharp) Method

GetTemplateStyleSheets() public method

public GetTemplateStyleSheets ( ) : IEnumerable
return IEnumerable
        public virtual IEnumerable<string> GetTemplateStyleSheets()
        {
            var stylesheetsToIgnore = new List<string>();
            // Remember, Linux filenames are case sensitive!
            stylesheetsToIgnore.Add("basePage.css");
            stylesheetsToIgnore.Add("languageDisplay.css");
            stylesheetsToIgnore.Add("editMode.css");
            stylesheetsToIgnore.Add("editOriginalMode.css");
            stylesheetsToIgnore.Add("previewMode.css");
            stylesheetsToIgnore.Add("settingsCollectionStyles.css");
            stylesheetsToIgnore.Add("customCollectionStyles.css");
            stylesheetsToIgnore.Add("customBookStyles.css");
            stylesheetsToIgnore.Add("XMatter");

            foreach(XmlElement link in _dom.SafeSelectNodes("//link[@rel='stylesheet']"))
            {
                var fileName = link.GetStringAttribute("href");
                var nameToCheck = fileName;
                if(Environment.OSVersion.Platform == PlatformID.Win32NT)
                    nameToCheck = fileName.ToLowerInvariant();
                bool match = false;
                foreach(var nameOrFragment in stylesheetsToIgnore)
                {
                    var nameStyle = nameOrFragment;
                    if(Environment.OSVersion.Platform == PlatformID.Win32NT)
                        nameStyle = nameStyle.ToLowerInvariant();
                    if(nameToCheck.Contains(nameStyle))
                    {
                        match = true;
                        break;
                    }
                }
                if(!match)
                    yield return fileName;
            }
        }

Usage Example

Example #1
0
        public static void AddStylesheetFromAnotherBook(HtmlDom sourceBookDom, HtmlDom targetBookDom)
        {
            var addedModifiedStyleSheets = new List<string>();
            //This was refactored from book, where there was these notes:
            //     NB: at this point this code can't handle the "userModifiedStyles" from children, it'll ignore them (they would conflict with each other)
            //     NB: at this point custom styles (e.g. larger/smaller font rules) from children will be lost.

            //At this point, this addedModifiedStyleSheets is just used as a place to track which stylesheets we already have
            foreach(string sheetName in sourceBookDom.GetTemplateStyleSheets())
            {
                if(!addedModifiedStyleSheets.Contains(sheetName))
                    //nb: if two books have stylesheets with the same name, we'll only be grabbing the 1st one.
                {
                    addedModifiedStyleSheets.Add(sheetName);
                    targetBookDom.AddStyleSheetIfMissing(sheetName);
                }
            }
        }