protected override bool IsValidSubType(IHTMLItem item) { if (!base.IsValidSubType(item)) { return(false); } if (item is Image || item is SmallText || item is Sub || item is Sup) { return(false); } if (item.SubElements().FindAll(x => x is Image).Count > 0) { return(false); } if (item.SubElements().FindAll(x => x is SmallText).Count > 0) { return(false); } if (item.SubElements().FindAll(x => x is Sub).Count > 0) { return(false); } if (item.SubElements().FindAll(x => x is Sup).Count > 0) { return(false); } return(true); }
/// <summary> /// Remove sub-item /// </summary> /// <param name="item"></param> public virtual void Remove(IHTMLItem item) { if (Subitems.Remove(item)) { item.Parent = null; } }
protected override bool IsValidSubType(IHTMLItem item) { if (!base.IsValidSubType(item)) { return false; } if (item is Image || item is SmallText || item is Sub || item is Sup) { return false; } if (item.SubElements().FindAll(x => x is Image).Count > 0) { return false; } if (item.SubElements().FindAll(x => x is SmallText).Count > 0) { return false; } if (item.SubElements().FindAll(x => x is Sub).Count > 0) { return false; } if (item.SubElements().FindAll(x => x is Sup).Count > 0) { return false; } return true; }
private ulong SplitBlockHTMLItem(IHTMLItem item, Div content, IList <IHTMLItem> resList, ulong documentSize) { ulong docSize = documentSize; ulong itemSize = item.EstimateSize(); if (_checker.ExceedSizeLimit(documentSize + itemSize)) { var oldContent = content; resList.Add(content); content = new Div(HTMLElementType.HTML5); content.GlobalAttributes.Class.Value = oldContent.GlobalAttributes.Class.Value; content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value; docSize = 0; } if (!_checker.ExceedSizeLimit(itemSize)) // if we can "fit" element into a max size XHTML document { docSize += itemSize; content.Add(item); } else { var div = item as Div; if (div != null) // if the item that bigger than max size is Div block { foreach (var splitedItem in SplitDiv(div, documentSize)) { documentSize = SplitSimpleHTMLItem(splitedItem, content, resList, documentSize); } } } return(docSize); }
protected override bool IsValidSubType(IHTMLItem item) { // may appear only once and only as first element if (item is TableCaption) { if (Subitems.Count > 0) { return(false); } IHTMLItem seekItem = Subitems.Find(x => x is TableCaption); if (seekItem != null) { return(false); } return(item.IsValid()); } if (item is ColElement) { return(item.IsValid()); } if (item is ColGroup) { return(item.IsValid()); } if (item is TableBody) { IHTMLItem seekItem = Subitems.Find(x => x is TableBody); if (seekItem != null) { return(false); } seekItem = Subitems.Find(x => x is TableRow); if (seekItem != null) { return(false); } return(item.IsValid()); } if (item is TableRow) { IHTMLItem seekItem = Subitems.Find(x => x is TableBody); if (seekItem != null) { return(false); } seekItem = Subitems.Find(x => x is TableHead); if (seekItem != null) { return(false); } seekItem = Subitems.Find(x => x is TableFooter); if (seekItem != null) { return(false); } return(item.IsValid()); } return(false); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is IBlockElement) { return item.IsValid(); } return false; }
protected override bool IsValidSubType(IHTMLItem item) { if (item is SimpleHTML5Text) { return(item.IsValid()); } return(false); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is ColElement) { return(item.IsValid()); } return(false); }
private BaseXHTMLFileV3 GetIDParentDocument(EPubFileV3 file, IHTMLItem value) { if ((file.AnnotationPage != null) && file.AnnotationPage.PartOfDocument(value)) { return(file.AnnotationPage); } return(file.GetIDOfParentDocument(value) as BaseXHTMLFileV3); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is Frame) { return true; } return false; }
protected override bool IsValidSubType(IHTMLItem item) { if (item is Option) { return item.IsValid(); } return false; }
protected override bool IsValidSubType(IHTMLItem item) { if (item is Option) { return(item.IsValid()); } return(false); }
public IBaseXHTMLFile GetIDOfParentDocument(IHTMLItem value) { return(_sections.FirstOrDefault(document => { var baseXHTMLFileV3 = document as BaseXHTMLFileV3; return baseXHTMLFileV3 != null && baseXHTMLFileV3.PartOfDocument(value); })); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is Frame) { return(true); } return(false); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is SimpleHTML5Text) { return item.IsValid(); } return false; }
protected override bool IsValidSubType(IHTMLItem item) { // TODO: full check for ruby sequence if (item is IRubyItem) { return(item.IsValid()); } return(false); }
protected override bool IsValidSubType(IHTMLItem item) { // TODO: full check for ruby sequence if (item is IRubyItem) { return item.IsValid(); } return false; }
private IEnumerable <Anchor> GetAllContainedAnchors(IHTMLItem linkItem) { if (linkItem.SubElements() == null) // if no sub elements - simple text item can't be anchor, so return empty list { return(new List <Anchor>()); } IEnumerable <Anchor> containedAnchors = linkItem.SubElements().OfType <Anchor>(); return(linkItem.SubElements().Aggregate(containedAnchors, (current, subElement) => current.Concat(GetAllContainedAnchors(subElement)))); }
private IEnumerable <Anchor> GetAllFirstLevelContainedAnchors(IHTMLItem linkItem) { if (linkItem.SubElements() == null) // if no sub elements - simple text item can't be anchor, so return empty list { return(new List <Anchor>()); } IEnumerable <Anchor> containedAnchors = linkItem.SubElements().OfType <Anchor>(); return(containedAnchors); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is IInlineItem || item is IBlockElement || item is SimpleHTML5Text) { return item.IsValid(); } return false; }
protected override bool IsValidSubType(IHTMLItem item) { if (item is IInlineItem || item is IBlockElement || item is SimpleHTML5Text) { return(item.IsValid()); } return(false); }
private static ulong EstimateSize(IHTMLItem item) { var stream = new MemoryStream(); XNode node = item.Generate(); using (var writer = XmlWriter.Create(stream)) { node.WriteTo(writer); } return((ulong)stream.Length); }
/// <summary> /// Adds sub-item to the item , only if /// allowed by the rules and element can accept content /// </summary> /// <param name="item">sub-item to add</param> public virtual void Add(IHTMLItem item) { if ((item != null) && IsValidSubType(item)) { Subitems.Add(item); item.Parent = this; } else { throw new HTML5ViolationException(); } }
/// <summary> /// Detect parent container of the element /// </summary> /// <param name="referencedItem"></param> /// <returns></returns> private static IHTMLItem DetectParentContainer(IHTMLItem referencedItem) { if (referencedItem is IBlockElement) { return(referencedItem); } if (referencedItem.Parent is IBlockElement) { return(referencedItem.Parent); } return(null); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is TableData) { return(item.IsValid()); } if (item is TableHeaderCell) { return(item.IsValid()); } return(false); }
public LinkReMapperV2(KeyValuePair <string, List <Anchor> > link, Dictionary <string, IHTMLItem> ids, BookStructureManager structureManager) { _link = link; _structureManager = structureManager; _idString = ReferencesUtils.GetIdFromLink(link.Key); // Get ID of a link target; _linkTargetItem = ids[_idString]; // get object targeted by link _linkTargetDocument = GetIDParentDocument(structureManager, _linkTargetItem); // get parent document (file) containing targeted object if (_linkTargetDocument != null) { _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item } }
public LinkReMapperV2(KeyValuePair<string, List<Anchor>> link, Dictionary<string, IHTMLItem> ids, BookStructureManager structureManager) { _link = link; _structureManager = structureManager; _idString = ReferencesUtils.GetIdFromLink(link.Key); // Get ID of a link target; _linkTargetItem = ids[_idString]; // get object targeted by link _linkTargetDocument = GetIDParentDocument(structureManager, _linkTargetItem); // get parent document (file) containing targeted object if (_linkTargetDocument != null) { _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item } }
protected override bool IsValidSubType(IHTMLItem item) { if (item is DefinitionDescription) { return(item.IsValid()); } if (item is DefinitionTerms) { return(item.IsValid()); } return(false); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is DefinitionDescription) { return item.IsValid(); } if (item is DefinitionTerms) { return item.IsValid(); } return false; }
/// <summary> /// Extends IHTMLItem class to evaluate the size of generated output /// </summary> /// <param name="item">item to evaluate</param> /// <returns></returns> public static ulong EstimateSize(this IHTMLItem item) { var stream = new MemoryStream(); var node = item.Generate(); var doc = new XDocument(); doc.Add(node); using (var writer = XmlWriter.Create(stream)) { doc.WriteTo(writer); } return((ulong)stream.Length); }
public LinkReMapperV3(KeyValuePair<string, List<Anchor>> link, IDictionary<string, HTMLItem> ids, BookStructureManager structureManager, IEPubV3Settings v3Settings) { _link = link; _ids = ids; _v3Settings = v3Settings; _structureManager = structureManager; _idString = ReferencesUtils.GetIdFromLink(link.Key); // Get ID of a link target; _linkTargetItem = ids[_idString]; // get object targeted by link _linkTargetDocument = GetItemParentDocument(_linkTargetItem); // get parent document (file) containing targeted object if (_linkTargetDocument != null) // if link target container document (document containing item with ID we jump to) found { _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item } }
public LinkReMapperV3(KeyValuePair <string, List <Anchor> > link, IDictionary <string, HTMLItem> ids, BookStructureManager structureManager, IEPubV3Settings v3Settings) { _link = link; _ids = ids; _v3Settings = v3Settings; _structureManager = structureManager; _idString = ReferencesUtils.GetIdFromLink(link.Key); // Get ID of a link target; _linkTargetItem = ids[_idString]; // get object targeted by link _linkTargetDocument = GetItemParentDocument(_linkTargetItem); // get parent document (file) containing targeted object if (_linkTargetDocument != null) // if link target container document (document containing item with ID we jump to) found { _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item } }
protected override bool IsValidSubType(IHTMLItem item) { if (item is Title || item is Base || item is Link || item is Meta || item is Script || item is Style || item is NoScript ) { return item.IsValid(); } return false; }
protected override bool IsValidSubType(IHTMLItem item) { if (item is Title || item is Base || item is Link || item is Meta || item is Script || item is Style || item is NoScript ) { return(item.IsValid()); } return(false); }
protected override bool IsValidSubType(IHTMLItem item) { if ( !(item is Input) && !(item is TextArea) && !(item is Button) && !(item is Select) && !(item is Option) && !(item is OptionGroup) && !(item is Label) && !(item is FieldSet)) { return(false); } return(item.IsValid()); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is IInlineItem) { if (item is Anchor) { return(false); } return(item.IsValid()); } if (item is SimpleHTML5Text) { return(true); } return(false); }
/// <summary> /// Checks if XHTML element is part of current document /// </summary> /// <param name="value">elemenrt to check</param> /// <returns>true idf part of this document, false otherwise</returns> public override bool PartOfDocument(IHTMLItem value) { if (BookAnnotation == null) { return false; } IHTMLItem parent = value; while (parent.Parent != null) { parent = parent.Parent; } if (parent == BookAnnotation) { return true; } return false; }
protected override bool IsValidSubType(IHTMLItem item) { if (item is IInlineItem) { // TODO: check for label presence at depth if (item is Label) { return(false); } return(item.IsValid()); } if (item is SimpleHTML5Text) { return(item.IsValid()); } return(false); }
protected override bool IsValidSubType(IHTMLItem item) { if (item is IInlineItem) { // TODO: check for label presence at depth if (item is Label) { return false; } return item.IsValid(); } if (item is SimpleHTML5Text) { return item.IsValid(); } return false; }
/// <summary> /// Checks if XHTML element is part of current document /// </summary> /// <param name="value">element to check</param> /// <returns>true if part of this document, false otherwise</returns> public virtual bool PartOfDocument(IHTMLItem value) { if (Content == null) { return(false); } IHTMLItem parent = value; while (parent.Parent != null) { parent = parent.Parent; } if (parent == Content) { return(true); } return(false); }
/// <summary> /// Add used ID to the list /// </summary> /// <param name="id">Id to list as used</param> /// <param name="item">item that ID belong to</param> /// <returns>returns and registers the id if available, empty string if ID already exists</returns> public string AddIdUsed(string id,IHTMLItem item) { if (string.IsNullOrEmpty(id)) { return id; } string newid = EnsureGoodId(id); if (_ids.ContainsKey(newid)) { // we get here if in file same ID used twice // The assumption here that since the text located in FB2 main body we should not have same ID used more than once // otherwise we would not know how (and where to) go back Logger.Log.InfoFormat("item with ID {0} already defined, ignoring to avoid inconsistences", newid); return string.Empty; } _ids.Add(newid, item); return newid; }
/// <summary> /// Checks if XHTML element is part of current document /// </summary> /// <param name="value">elemenrt to check</param> /// <returns>true idf part of this document, false otherwise</returns> public override bool PartOfDocument(IHTMLItem value) { if (BookAnnotation == null) { return(false); } IHTMLItem parent = value; while (parent.Parent != null) { parent = parent.Parent; } if (parent == BookAnnotation) { return(true); } return(false); }
/// <summary> /// Add used ID to the list /// </summary> /// <param name="id">Id to list as used</param> /// <param name="item">item that ID belong to</param> /// <returns>returns and registers the id if available, empty string if ID already exists</returns> public string AddIdUsed(string id, IHTMLItem item) { if (string.IsNullOrEmpty(id)) { return(id); } string newid = EnsureGoodId(id); if (_ids.ContainsKey(newid)) { // we get here if in file same ID used twice // The assumption here that since the text located in FB2 main body we should not have same ID used more than once // otherwise we would not know how (and where to) go back Logger.Log.InfoFormat("item with ID {0} already defined, ignoring to avoid inconsistences", newid); return(string.Empty); } _ids.Add(newid, item); return(newid); }
/// <summary> /// Loads an element and it's data from a node /// </summary> /// <param name="xNode"></param> public virtual void Load(XNode xNode) { if (xNode.NodeType != XmlNodeType.Element) { throw new ArgumentException("xNode is not of element type", "xNode"); } string currentObjectElementName = GetObjectElementName(); var xElement = (XElement)xNode; // check that we got a element of matching (to us) type/name if (string.CompareOrdinal(xElement.Name.LocalName, currentObjectElementName) != 0) { throw new ArgumentException(string.Format("xNode is not {0} element, it's {1}", currentObjectElementName, xElement.Name.LocalName), "xNode"); } // load attributes ReadAttributes(xElement); // load sub-items Subitems.Clear(); IEnumerable <XNode> descendants = xElement.Nodes(); foreach (var node in descendants) { IHTMLItem item = ElementFactory.CreateElement(node, _htmlStandard); if ((item != null) && IsValidSubType(item)) { try { item.Load(node); } catch (Exception) { continue; } Subitems.Add(item); } } if (TextContent != null) // need to be created in constructor of derived class { TextContent.Load(xElement); } }
/// <summary> /// Detect parent container of the element /// </summary> /// <param name="referencedItem"></param> /// <returns></returns> private IHTMLItem DetectItemParentContainer(IHTMLItem referencedItem) { if (referencedItem is IBlockElement) // if item itself is container - return it { return referencedItem; } if (referencedItem.Parent != null) { if (referencedItem.Parent is IBlockElement) // if item is located inside container { return referencedItem.Parent; } if (referencedItem.Parent is TextBasedElement) // if parent is text, i's ok for container { return referencedItem.Parent; } return DetectItemParentContainer(referencedItem.Parent); // go up the inclusion chain } return null; }
protected override bool IsValidSubType(IHTMLItem item) { if (Subitems.Count >= 2) // no more than two sub elements { return false; } if (Subitems.Count == 0) // head have to be first { if (!(item is Head) ) { return false; } } if (Subitems.Count == 1) // body have to be second { if (!(item is Body) ) { return false; } } return item.IsValid(); }
/// <summary> /// Checks if XHTML element is part of current document /// </summary> /// <param name="value">element to check</param> /// <returns>true if part of this document, false otherwise</returns> public virtual bool PartOfDocument(IHTMLItem value) { if (Content == null) { return false; } IHTMLItem parent = value; while (parent.Parent != null) { parent = parent.Parent; } if (parent == Content) { return true; } return false; }
private ulong SplitSimpleHTMLItem(IHTMLItem splitedItem, Div content, IList<IHTMLItem> resList, ulong documentSize) { ulong docSize = documentSize; ulong itemSize = splitedItem.EstimateSize(); if (_checker.ExceedSizeLimit(documentSize + itemSize)) { var oldContent = content; resList.Add(content); content = new Div(HTMLElementType.HTML5); content.GlobalAttributes.Class.Value = oldContent.GlobalAttributes.Class.Value; content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value; docSize = 0; } if (!_checker.ExceedSizeLimit(itemSize)) // if we can "fit" element into a max size XHTML document { docSize += itemSize; content.Add(splitedItem); } return docSize; }
private ulong SplitBlockHTMLItem(IHTMLItem item, Div content, IList<IHTMLItem> resList, ulong documentSize) { ulong docSize = documentSize; ulong itemSize = item.EstimateSize(); if (_checker.ExceedSizeLimit(documentSize + itemSize)) { var oldContent = content; resList.Add(content); content = new Div(HTMLElementType.HTML5); content.GlobalAttributes.Class.Value = oldContent.GlobalAttributes.Class.Value; content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value; docSize = 0; } if (!_checker.ExceedSizeLimit(itemSize)) // if we can "fit" element into a max size XHTML document { docSize += itemSize; content.Add(item); } else { var div = item as Div; if (div != null) // if the item that bigger than max size is Div block { foreach (var splitedItem in SplitDiv(div, documentSize)) { documentSize = SplitSimpleHTMLItem(splitedItem, content, resList, documentSize); } } } return docSize; }
/// <summary> /// Detect parent container of the element /// </summary> /// <param name="referencedItem"></param> /// <returns></returns> private static IHTMLItem DetectParentContainer(IHTMLItem referencedItem) { if (referencedItem is IBlockElement) { return referencedItem; } if (referencedItem.Parent is IBlockElement) { return referencedItem.Parent; } return null; }
protected override bool IsValidSubType(IHTMLItem item) { if (item is IInlineItem) { if (item is Anchor) { return false; } return item.IsValid(); } if (item is SimpleHTML5Text) { return true; } return false; }
/// <summary> /// Check if item passed is valid to be inserted as a sub-item /// Need to be overridden in extensions to provide proper check /// </summary> /// <param name="item"></param> /// <returns></returns> protected virtual bool IsValidSubType(IHTMLItem item) { return false; // by default nothing valid - means nothing added as subtype }
private BaseXHTMLFileV2 GetIDParentDocument(EPubFileV2 file, IHTMLItem value) { if ((file.AnnotationPage != null) && file.AnnotationPage.PartOfDocument(value)) { return file.AnnotationPage; } return file.GetIDOfParentDocument(value) as BaseXHTMLFileV2; }
protected override bool IsValidSubType(IHTMLItem item) { if (item is TableData) { return item.IsValid(); } if (item is TableHeaderCell) { return item.IsValid(); } return false; }
/// <summary> /// Adds sub item to the item , only if /// allowed by the rules and element can accept content /// simple text can't have sub-items so it will always return false /// </summary> /// <param name="item">sub item to add</param> public override void Add(IHTMLItem item) { throw new Exception("This element does not contain or obtain sub items"); }
public IBaseXHTMLFile GetIDOfParentDocument(IHTMLItem value) { return _sections.FirstOrDefault(document => { var baseXHTMLFileV2 = document as BaseXHTMLFileV2; return baseXHTMLFileV2 != null && baseXHTMLFileV2.PartOfDocument(value); }); }
private static ulong EstimateSize(IHTMLItem item) { var stream = new MemoryStream(); XNode node = item.Generate(); using (var writer = XmlWriter.Create(stream)) { node.WriteTo(writer); } return (ulong)stream.Length; }
private BaseXHTMLFileV2 GetIDParentDocument(BookStructureManager structureManager, IHTMLItem value) { return structureManager.GetItemParentDocument(value) as BaseXHTMLFileV2; }