Ejemplo n.º 1
0
 // Methods
 public Fb2TokenParser(XNamespace ns, XElement root, CSS styleSheet, List<BookChapter> chapters, Dictionary<string, int> anchors)
 {
     _ns = ns;
     _root = root;
     _styleSheet = styleSheet;
     _chapters = chapters;
     _anchors = anchors;
 }
Ejemplo n.º 2
0
        public EpubTokenParser(XDocument opf, EpubPath opfPath, ZipContainer zip, CSS css, Dictionary<string, int> anchors)
        {
            _opf = opf;
            _opfPath = opfPath;
            _zip = zip;
            _css = css;
            _anchors = anchors;
            _opfns = XNamespace.Get("http://www.idpf.org/2007/opf");

            _opfRoot = _opf.Root;
            if (_opfRoot == null)
                throw new DataException("Invalid epub meta info.");
        }
 public static TextVisualProperties Update(this TextVisualProperties properties, HtmlNode element, CSS css)
 {
     var list = new List<string>
                {
                    element.Name
                };
     string attributeValue = element.GetAttributeValue("class", string.Empty);
     if (!string.IsNullOrEmpty(attributeValue))
     {
         list.Add(element.Name + "." + attributeValue);
         list.Add("." + attributeValue);
     }
     return properties.UpdateCss(css, list.ToArray());
 }
Ejemplo n.º 4
0
        public override IEnumerable<TokenBase> GetTokens()
        {
            _css = new CSS();

            var html = new HtmlDocument
                            {
                                OptionOutputAsXml = true,
                                OptionReadEncoding = false
                            };
            html.Load(_reader);
            var root  = html.DocumentNode.SelectSingleNode("//body");
            
            var cssNode = html.DocumentNode.SelectSingleNode("//style");
            if (cssNode != null)
            {
                _css.Analyze(cssNode.InnerText);
            }

            var stack = new Stack<TextVisualProperties>();
            var item = new TextVisualProperties();
            stack.Push(item);

            return ParseTokens(root, stack, new TokenIndex());
        }
Ejemplo n.º 5
0
 private CSS GetCss()
 {
     CSS sheet = new CSS();
     sheet.Analyze(DefaultFb2Css);
     return sheet;
 }
 private static TextVisualProperties UpdateCss(this TextVisualProperties properties, CSS css, string[] selectors)
 {
     css.ApplyProperties(selectors, properties);
     return(properties);
 }
        public static TextVisualProperties Update(this TextVisualProperties properties, XElement element, CSS css)
        {
            string localName = element.Name.LocalName;

            string[] selectors = { localName };
            return(properties.UpdateCss(css, selectors));
        }
        public static TextVisualProperties Update(this TextVisualProperties properties, HtmlNode element, CSS css)
        {
            var list = new List <string>
            {
                element.Name
            };
            string attributeValue = element.GetAttributeValue("class", string.Empty);

            if (!string.IsNullOrEmpty(attributeValue))
            {
                list.Add(element.Name + "." + attributeValue);
                list.Add("." + attributeValue);
            }
            return(properties.UpdateCss(css, list.ToArray()));
        }
Ejemplo n.º 9
0
        private CSS GetCss()
        {
            var sheet = new CSS();
            sheet.Analyze(DefaultEpubCss);
            
            var hrefs = _opfRoot
                .Elements(_opfns + "manifest")
                .Elements(_opfns + "item")
                .Where(e =>
                           {
                               var mediaType = e.Attribute("media-type");
                               return mediaType != null && mediaType.Value == "text/css";
                           })
                .Attributes("href").Select(h => h.Value);

            foreach (var href in hrefs)
            {
                Stream stream = _zip.GetFileStream(_opfPath + href, false, true);
                if (stream != null)
                {
                    sheet.Analyze(new StreamReader(stream).ReadToEnd());
                }
            }
            return sheet;
        }
 private static TextVisualProperties UpdateCss(this TextVisualProperties properties, CSS css, string[] selectors)
 {
     css.ApplyProperties(selectors, properties);
     return properties;
 }
 public static TextVisualProperties Update(this TextVisualProperties properties, XElement element, CSS css)
 {
     string localName = element.Name.LocalName;
     string[] selectors = {localName};
     return properties.UpdateCss(css, selectors);
 }