Esempio n. 1
0
		void TransformFormatingSpansToFormatingElements(HtmlNode node) {
			if (false == node.IsAnyTag("span", "p")) { return; }

			var style = ParseStyle(node);
			if (style.Count < 1) { return; }

			var wasTransformed = false;
			var parentChildren = node.ParentNode.ChildNodes;
			Action<string> wrapSpan = (wrapperTagName) => {
				var wrapperNode = HtmlNode.CreateNode("<" + wrapperTagName + "></" + wrapperTagName + ">");
				wrapperNode.InnerHtml = node.InnerHtml;
				node.InnerHtml = wrapperNode.OuterHtml;
				wasTransformed = true;
			};
			Action<string, string, string> wrapSpanByStyle = (key, value, wrapperTagName) => {
				var styleValue = style.Find(key);
				styleValue = null != styleValue ? styleValue.Trim() : string.Empty;

				if (styleValue.InvEquals(value.Trim())) {
					wrapSpan(wrapperTagName);
					style.Remove(key);
				}
			};

			wrapSpanByStyle("font-weight", "bold", "b");
			wrapSpanByStyle("font-style", "italic", "i");
			wrapSpanByStyle("text-decoration", "underline", "u");

			if (false == wasTransformed) { return; }

			if (style.Count < 1) {
				node.Attributes.Remove("style");
			}
			else {
				var finalStyle = ComposeStyle(style);
				node.SetAttributeValue("style", finalStyle);
			}
		}