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

AddStyleSheetIfMissing() public method

public AddStyleSheetIfMissing ( string path ) : void
path string
return void
        public void AddStyleSheetIfMissing(string path)
        {
            // Remember, Linux filenames are case sensitive.
            var pathToCheck = path;
            if(Environment.OSVersion.Platform == PlatformID.Win32NT)
                pathToCheck = pathToCheck.ToLowerInvariant();
            foreach(XmlElement link in _dom.SafeSelectNodes("//link[@rel='stylesheet']"))
            {
                var fileName = link.GetStringAttribute("href");
                if(Environment.OSVersion.Platform == PlatformID.Win32NT)
                    fileName = fileName.ToLowerInvariant();
                if(fileName == pathToCheck)
                    return;
            }
            _dom.AddStyleSheet(path.Replace("file://", ""));
        }

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);
                }
            }
        }
All Usage Examples Of Bloom.Book.HtmlDom::AddStyleSheetIfMissing