/// <summary> /// Create a text with Capital Drop /// </summary> /// <param name="parent">parent container insert into</param> /// <param name="text">text to insert</param> private void AddAsDrop(List<IHTMLItem> parent, SimpleText text) { var span1 = new Span(HTMLElementType.XHTML11); SetClassType(span1, ElementStylesV2.CapitalDrop); int dropEnd = 0; // "pad" the white spaces so drop starts from visible character while (dropEnd < text.Text.Length && UnicodeHelpers.IsSpaceLike(text.Text[dropEnd]) ) { dropEnd++; } if (dropEnd >= text.Text.Length) // in case the text is too short for drop { parent.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); return; } // calculate the initial drop part string dropPart = text.Text.Substring(0, dropEnd + 1); // non-drop part starts from the next character int nondropPosition = dropEnd + 1; // If first character is dash/hyphen like we need to add character to // capital drop so it looks better with next character if (UnicodeHelpers.IsNeedToBeJoinInDrop(dropPart[dropEnd])) { // we need to add to capital drop all spaces if any while (nondropPosition < text.Text.Length && UnicodeHelpers.IsSpaceLike(text.Text[nondropPosition])) { nondropPosition++; } // we need to advance to include one following nonspace character , unless // we already at last character of the text if (nondropPosition < text.Text.Length) { nondropPosition++; } // update drop part with the "string" we calculated dropPart += text.Text.Substring(dropEnd + 1, nondropPosition - dropEnd - 1); } span1.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = dropPart }); parent.Add(span1); string substring = text.Text.Substring(nondropPosition); if (substring.Length > 0) { parent.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = substring }); } }
/// <summary> /// Processes all the references and removes invalid anchors /// Invalid meaning pointing to non-existing IDs /// only "internal" anchors are removed /// </summary> private void RemoveInvalidAnchor(KeyValuePair<string, List<Anchor>> link) { // remove all references to this ID foreach (var element in _references[link.Key]) { // The Anchor element can't have empty reference so // we remove it and in case it has some meaningful content // replace with span that is meaningless non-block element // so contained text etc are kept if (element.SubElements().Count != 0) { var spanElement = new Span(element.HTMLStandard); foreach (var subElement in element.SubElements()) { spanElement.Add(subElement); } if (element.Parent != null) { int index = element.Parent.SubElements().IndexOf(element); if (index != -1) { spanElement.Parent = element.Parent; element.Parent.SubElements().Insert(index, spanElement); } } if (!string.IsNullOrEmpty((string)element.GlobalAttributes.ID.Value)) { spanElement.GlobalAttributes.ID.Value = element.GlobalAttributes.ID.Value; // Copy ID anyway - may be someone "jumps" here _ids[(string)element.GlobalAttributes.ID.Value] = spanElement; // and update the "pointer" to element } spanElement.GlobalAttributes.Class.Value = ElementStylesV2.BadExternalLink; } if (element.Parent != null) { element.Parent.Remove(element); } } }
/// <summary> /// Processes all the references and removes invalid anchors /// Invalid meaning pointing to non-existing IDs /// only "internal" anchors are removed /// </summary> public void RemoveInvalidAnchors() { var listToRemove = new List<string>(); foreach (var reference in _references) { // If reference does not points on one of valid IDs and it's not external reference if (!IsIdUsed(reference.Key) && !ReferencesUtils.IsExternalLink(reference.Key)) { listToRemove.Add(reference.Key); // remove all references to this ID foreach (var element in _references[reference.Key]) { // The Anchor element can't have empty reference so // we remove it and in case it has some meaningful content // replace with span that is meaningless non-block element // so contained text etc are kept if (element.SubElements().Count != 0) { var spanElement = new Span(element.HTMLStandard); foreach (var subElement in element.SubElements()) { spanElement.Add(subElement); } if (element.Parent != null) { int index = element.Parent.SubElements().IndexOf(element); if (index != -1) { spanElement.Parent = element.Parent; element.Parent.SubElements().Insert(index, spanElement); } } if (!string.IsNullOrEmpty((string)element.GlobalAttributes.ID.Value)) { spanElement.GlobalAttributes.ID.Value = element.GlobalAttributes.ID.Value; // Copy ID anyway - may be someone "jumps" here _ids[(string)element.GlobalAttributes.ID.Value] = spanElement; // and update the "pointer" to element } spanElement.GlobalAttributes.Class.Value = ElementStylesV2.BadExternalLink; } if (element.Parent != null) { element.Parent.Remove(element); } } } } // Remove the unused anchor (and their ID if they have one) // from the lists foreach (var toRemove in listToRemove) { _references.Remove(toRemove); } }