public IEnumerable <IHtmlElement> Serialize(object o, int lvl, IHtmlSerializer fac) { // Type elementType = GetElementType(o); // Type elementType = GetItemType(o); if (o is IEnumerable) { o = (o as IEnumerable).ToRawList(); } var elementType = o.GetType().GetGenericArguments().Length == 1 ? o.GetType().GetGenericArguments()[0] : o.GetType().GetElementType(); if (elementType == null) { throw new ArgumentException($"Unable to find elementtype for {o.GetType()}"); } var itemType = HtmlSupport.GetItemType(elementType); return(new Ul { Clz = "result-list " + itemType, Itemscope = true, Itemtype = HtmlSupport.Itemtype(o), Subs = ((IEnumerable <object>)o) .SelectMany(item => fac.Serialize(item, lvl - 1, fac)) .Select(elem => new Li(elem)) .OfType <IHtmlElement>() .ToArray(), }.ToArray()); }
public IEnumerable <IHtmlElement> Serialize(object x, int lvl, IHtmlSerializer fac) { // IDictionary dict; // dict = (IDictionary) x; // dict = (IDictionary<string, object>) x; var d = (IDictionary)x; var itemtype = HtmlSupport.Itemtype(x); var subs = d.Keys.ToRawList().Cast <string>() .Select(name => new { Name = name, Val = d[name] }) // .Where(a => a.Val != null) .SelectMany(a => new IHtmlElement[] { new Dt(a.Name), new Dd { Subs = fac.Serialize(a.Val, lvl - 1, fac).ToArray() } }) .ToArray(); return(new Ul { Subs = subs, Itemscope = true, Itemtype = itemtype, }.ToArray()); }
public Td SerializeToTd(MemberInfo prop, object item) { var val = HtmlSupport.TryGetVal(prop, item); if (val is List <Linking> ) { val = (val as List <Linking>).OfType <A>().ToList(); } var element = _rootSerializer.Serialize(val, 2, _rootSerializer); return(element != null ? new Td { Subs = element.ToArray() } : new Td(val?.ToString())); }
public ActionResult Edit(Blogs blogs) { if (ModelState.IsValid) { db.Entry(blogs).State = EntityState.Modified; string[] imgs = HtmlSupport.GetHtmlImageUrlList(blogs.content); string tempStr = ""; foreach (var str in imgs) { tempStr += str + "|"; } blogs.imgurls = (!string.IsNullOrEmpty(tempStr) ? tempStr.Substring(0, tempStr.Length - 1) : "/upload/image/blog/20160101/def.jpg"); blogs.publishTime = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(blogs)); }
public static IEnumerable <IHtmlElement> SerializeProps(object x, int lvl, IHtmlSerializer fac, IEnumerable <MemberInfo> props, bool includeType) { var itemType = HtmlSupport.Itemtype(x); var subs = new List <IHtmlElement>(); if (includeType) { subs.AddRange(new IHtmlElement[] { new Dt("Type"), new Dd { Title = itemType, Text = x.GetType().Name, }, }); } props .Select(mi => new { mi.Name, Val = HtmlSupport.TryGetVal(mi, x) }) .Where(a => a.Val != null) .SelectMany(a => new IHtmlElement[] { new Dt(a.Name), new Dd { Itemprop = PropName(a.Name), Subs = fac.Serialize(a.Val, lvl - 1, fac).ToArray() } }) .ToList().ForEach(e => subs.Add(e)); return(new Dl { Subs = subs.ToArray(), Itemscope = true, Itemtype = itemType, }.ToArray()); }
public ActionResult Create(Blogs blogs) { if (ModelState.IsValid) { var temp = db.Blogs.Select(s => s.orderNum).Max(); string tempStr = ""; string[] imgs = HtmlSupport.GetHtmlImageUrlList(blogs.content); foreach (var str in imgs) { tempStr += str + "|"; } blogs.imgurls = (!string.IsNullOrEmpty(tempStr) ? tempStr.Substring(0, tempStr.Length - 1) : "/upload/image/blog/20160101/def.jpg"); blogs.orderNum = temp + 1; blogs.viewCount = 0; blogs.author = "zuorx"; blogs.publishTime = DateTime.Now; db.Blogs.Add(blogs); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(blogs)); }
public IEnumerable <IHtmlElement> Serialize(object x, int lvl, IHtmlSerializer fac) { var d = (IDictionary <string, object>)x; if (!d.Keys.Any()) { return(new Dl().ToArray()); } if (!d.ContainsKey("type")) { throw new NotSupportedException(); } var itemRef = (string)d["type"]; var itemtype = HtmlSupport.Itemtype(d); var subs = d.Keys.ToRawList().Cast <string>() .Select(name => KeyValuePair.Create(name, d[name])) // .Where(a => a.Val != null) .SelectMany(a => new IHtmlElement[] { new Dt(ColumnToTitle(a.Key)), new Dd { // Itemprop = a.Key, // Subs = fac.Serialize(a.Val, lvl - 1, fac).ToArray() Subs = DbValueToElement(itemRef, d, a).ToArray() } }) .ToArray(); return(new Dl { Subs = subs, Itemscope = true, Itemtype = itemtype, }.ToArray()); }
private void RevertCharFormat() { StringBuilder stringBuilder = null; FlagProperties effectiveFlags = base.GetEffectiveFlags(); if (effectiveFlags.IsDefinedAndOn(PropertyId.Underline)) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("</Underline>"); } if (effectiveFlags.IsDefinedAndOn(PropertyId.Italic)) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("</Italic>"); } if (effectiveFlags.IsDefinedAndOn(PropertyId.FirstFlag)) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("</Bold>"); } PropertyValue value = base.GetEffectiveProperty(PropertyId.FontColor); if (value.IsEnum) { value = HtmlSupport.TranslateSystemColor(value); } if (value.IsColor && value.Color.RGB != 0U) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("</Color>"); } PropertyValue effectiveProperty = base.GetEffectiveProperty(PropertyId.FontFace); PropertyValue effectiveProperty2 = base.GetEffectiveProperty(PropertyId.FontSize); if (!effectiveProperty.IsNull && effectiveProperty.IsString && base.FormatStore.GetStringValue(effectiveProperty).GetString().Equals("Courier New") && !effectiveProperty2.IsNull && effectiveProperty2.IsRelativeHtmlFontUnits && effectiveProperty2.RelativeHtmlFontUnits == -1) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("</Fixed>"); } else { if (!effectiveProperty2.IsNull && !effectiveProperty2.IsAbsLength && !effectiveProperty2.IsHtmlFontUnits && effectiveProperty2.IsRelativeHtmlFontUnits && effectiveProperty2.RelativeHtmlFontUnits != 0) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } if (effectiveProperty2.RelativeHtmlFontUnits > 0) { stringBuilder.Append("</Bigger>"); for (int i = 1; i < effectiveProperty2.RelativeHtmlFontUnits; i++) { stringBuilder.Append("</Bigger>"); } } else { stringBuilder.Append("</Smaller>"); for (int j = -1; j > effectiveProperty2.RelativeHtmlFontUnits; j--) { stringBuilder.Append("</Smaller>"); } } } if (!effectiveProperty.IsNull) { string text = null; if (effectiveProperty.IsMultiValue) { MultiValue multiValue = base.FormatStore.GetMultiValue(effectiveProperty); if (multiValue.Length != 0) { text = multiValue.GetStringValue(0).GetString(); } } else { text = base.FormatStore.GetStringValue(effectiveProperty).GetString(); } if (text != null) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("</FontFamily>"); } } } if (stringBuilder != null && stringBuilder.Length != 0) { this.lineLength += stringBuilder.Length; this.output.Write(stringBuilder.ToString()); } }
private void ApplyCharFormat() { StringBuilder stringBuilder = null; FlagProperties effectiveFlags = base.GetEffectiveFlags(); PropertyValue effectiveProperty = base.GetEffectiveProperty(PropertyId.FontFace); PropertyValue effectiveProperty2 = base.GetEffectiveProperty(PropertyId.FontSize); if (!effectiveProperty.IsNull && effectiveProperty.IsString && base.FormatStore.GetStringValue(effectiveProperty).GetString().Equals("Courier New") && !effectiveProperty2.IsNull && effectiveProperty2.IsRelativeHtmlFontUnits && effectiveProperty2.RelativeHtmlFontUnits == -1) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("<Fixed>"); } else { if (!effectiveProperty.IsNull) { string text = null; if (effectiveProperty.IsMultiValue) { MultiValue multiValue = base.FormatStore.GetMultiValue(effectiveProperty); if (multiValue.Length != 0) { text = multiValue.GetStringValue(0).GetString(); } } else { text = base.FormatStore.GetStringValue(effectiveProperty).GetString(); } if (text != null) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("<FontFamily><Param>"); stringBuilder.Append(text); stringBuilder.Append("</Param>"); } } if (!effectiveProperty2.IsNull && !effectiveProperty2.IsAbsLength && !effectiveProperty2.IsHtmlFontUnits && effectiveProperty2.IsRelativeHtmlFontUnits && effectiveProperty2.RelativeHtmlFontUnits != 0) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } if (effectiveProperty2.RelativeHtmlFontUnits > 0) { stringBuilder.Append("<Bigger>"); for (int i = 1; i < effectiveProperty2.RelativeHtmlFontUnits; i++) { stringBuilder.Append("<Bigger>"); } } else { stringBuilder.Append("<Smaller>"); for (int j = -1; j > effectiveProperty2.RelativeHtmlFontUnits; j--) { stringBuilder.Append("<Smaller>"); } } } } PropertyValue value = base.GetEffectiveProperty(PropertyId.FontColor); if (value.IsEnum) { value = HtmlSupport.TranslateSystemColor(value); } if (value.IsColor && value.Color.RGB != 0U) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } uint num = value.Color.Red << 8; uint num2 = value.Color.Green << 8; uint num3 = value.Color.Blue << 8; if ((num & 256U) != 0U) { num += 255U; } if ((num2 & 256U) != 0U) { num2 += 255U; } if ((num3 & 256U) != 0U) { num3 += 255U; } stringBuilder.Append("<Color><Param>"); stringBuilder.Append(string.Format("{0:X4},{1:X4},{2:X4}", num, num2, num3)); stringBuilder.Append("</Param>"); } if (effectiveFlags.IsDefinedAndOn(PropertyId.FirstFlag)) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("<Bold>"); } if (effectiveFlags.IsDefinedAndOn(PropertyId.Italic)) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("<Italic>"); } if (effectiveFlags.IsDefinedAndOn(PropertyId.Underline)) { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } stringBuilder.Append("<Underline>"); } if (stringBuilder != null && stringBuilder.Length != 0) { this.lineLength += stringBuilder.Length; this.output.Write(stringBuilder.ToString()); } }
private void Process(HtmlTokenId tokenId) { this.token = this.parser.Token; switch (tokenId) { case HtmlTokenId.EndOfFile: if (this.injection != null) { bool haveHead = this.injection.HaveHead; } base.CloseAllContainersAndSetEOF(); if (this.output != null) { this.output.Flush(); } break; case HtmlTokenId.Text: if (!this.insideParam) { this.tagPendingParameter = HtmlNameIndex._NOTANAME; this.OutputText(this.token); return; } if (this.tagPendingParameter != HtmlNameIndex._NOTANAME) { this.scratch.AppendTokenText(this.token, 256); return; } break; case HtmlTokenId.EncodingChange: if (this.output != null && this.output.OutputCodePageSameAsInput) { this.output.OutputEncoding = this.token.TokenEncoding; return; } break; case HtmlTokenId.Tag: if (this.token.IsTagBegin) { if (this.token.IsEndTag) { if (this.token.NameIndex == HtmlNameIndex.Param) { if (this.insideParam) { HtmlNameIndex htmlNameIndex = this.tagPendingParameter; if (htmlNameIndex <= HtmlNameIndex.ParaIndent) { if (htmlNameIndex != HtmlNameIndex.Color) { if (htmlNameIndex == HtmlNameIndex.ParaIndent) { BufferString bufferString = this.scratch.BufferString; bufferString.TrimWhitespace(); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num6; for (int num5 = 0; num5 != bufferString.Length; num5 = num6) { int i = num5; num6 = num5; while (i < bufferString.Length) { if (bufferString[i] == ',') { break; } i++; num6++; } while (i > num5 && ParseSupport.WhitespaceCharacter(ParseSupport.GetCharClass(bufferString[i - 1]))) { i--; } if (num6 < bufferString.Length) { do { num6++; }while (num6 < bufferString.Length && ParseSupport.WhitespaceCharacter(ParseSupport.GetCharClass(bufferString[num6]))); } BufferString bufferString2 = bufferString.SubString(num5, i - num5); if (bufferString2.EqualsToLowerCaseStringIgnoreCase("left")) { num++; } else if (bufferString2.EqualsToLowerCaseStringIgnoreCase("right")) { num2++; } else if (bufferString2.EqualsToLowerCaseStringIgnoreCase("in")) { num3++; } else if (bufferString2.EqualsToLowerCaseStringIgnoreCase("out")) { num4++; } } if (num + num4 != 0) { base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.LeftPadding, new PropertyValue(LengthUnits.Points, 30 * (num + num4) - ((this.indentLevel == 0) ? 12 : 0))); } if (num3 - num4 != 0) { if (num3 - num4 > 0) { base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.FirstLineIndent, new PropertyValue(LengthUnits.Points, 30 * (num3 - num4) - ((this.indentLevel == 0 && num + num4 == 0) ? 12 : 0))); } else { base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.FirstLineIndent, new PropertyValue(LengthUnits.Points, 30 * (num3 - num4) + ((this.indentLevel == 0 && num4 - num3 == num + num4) ? 12 : 0))); } } if (num2 != 0) { base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.RightPadding, new PropertyValue(LengthUnits.Points, 30 * num2)); } if (num + num4 != 0 && this.indentLevel == 0) { this.indentLevel++; } } } else { PropertyValue value = HtmlSupport.ParseColor(this.scratch.BufferString, true, false); if (value.IsColor) { if (value.Color.Red > 250U && value.Color.Green > 250U && value.Color.Blue > 250U) { value = new PropertyValue(PropertyType.Color, 14737632U); } base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.FontColor, value); } } } else if (htmlNameIndex != HtmlNameIndex.Excerpt) { if (htmlNameIndex != HtmlNameIndex.Lang) { if (htmlNameIndex == HtmlNameIndex.FontFamily) { PropertyValue value = HtmlSupport.ParseFontFace(this.scratch.BufferString, this); if (!value.IsNull) { base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.FontFace, value); } } } else { PropertyValue value = HtmlSupport.ParseLanguage(this.scratch.BufferString, null); if (!value.IsNull) { base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.Language, value); } } } this.insideParam = false; } } else if (this.token.NameIndex != HtmlNameIndex.Unknown) { if (this.token.NameIndex == HtmlNameIndex.ParaIndent && this.indentLevel != 0) { this.indentLevel--; } base.CloseContainer(this.token.NameIndex); } this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } HtmlNameIndex nameIndex = this.token.NameIndex; if (nameIndex <= HtmlNameIndex.ParaIndent) { if (nameIndex <= HtmlNameIndex.Param) { if (nameIndex == HtmlNameIndex.Nofill) { base.OpenContainer(FormatContainerType.Block, false, 2, base.GetStyle(14), this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } if (nameIndex == HtmlNameIndex.FlushRight) { base.OpenContainer(FormatContainerType.Block, false, 2, FormatStyle.Null, this.token.NameIndex); base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.TextAlignment, new PropertyValue(TextAlign.Right)); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } if (nameIndex == HtmlNameIndex.Param) { this.insideParam = true; this.scratch.Reset(); return; } } else if (nameIndex <= HtmlNameIndex.Italic) { if (nameIndex == HtmlNameIndex.Color) { base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, FormatStyle.Null, this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex.Color; return; } if (nameIndex == HtmlNameIndex.Italic) { base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, base.GetStyle(4), this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } } else { switch (nameIndex) { case HtmlNameIndex.Center: base.OpenContainer(FormatContainerType.Block, false, 2, base.GetStyle(13), this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; case HtmlNameIndex.Height: break; case HtmlNameIndex.Underline: base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, base.GetStyle(5), this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; case HtmlNameIndex.FlushBoth: base.OpenContainer(FormatContainerType.Block, false, 2, FormatStyle.Null, this.token.NameIndex); base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.TextAlignment, new PropertyValue(TextAlign.Justify)); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; default: if (nameIndex == HtmlNameIndex.ParaIndent) { base.OpenContainer(FormatContainerType.Block, false, 2, FormatStyle.Null, this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex.ParaIndent; if (this.indentLevel != 0) { this.indentLevel++; return; } return; } break; } } } else if (nameIndex <= HtmlNameIndex.FlushLeft) { if (nameIndex == HtmlNameIndex.Fixed) { base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, base.GetStyle(10), this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } if (nameIndex == HtmlNameIndex.Smaller) { base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, FormatStyle.Null, this.token.NameIndex); base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.FontSize, new PropertyValue(PropertyType.RelHtmlFontUnits, -1)); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } switch (nameIndex) { case HtmlNameIndex.Bold: base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, base.GetStyle(1), this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; case HtmlNameIndex.FlushLeft: base.OpenContainer(FormatContainerType.Block, false, 2, FormatStyle.Null, this.token.NameIndex); base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.TextAlignment, new PropertyValue(TextAlign.Left)); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } } else if (nameIndex <= HtmlNameIndex.Lang) { if (nameIndex == HtmlNameIndex.Excerpt) { base.OpenContainer(FormatContainerType.Block, false, 2, FormatStyle.Null, this.token.NameIndex); base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.QuotingLevelDelta, new PropertyValue(PropertyType.Integer, 1)); this.tagPendingParameter = HtmlNameIndex.Excerpt; return; } if (nameIndex == HtmlNameIndex.Lang) { base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, base.GetStyle(6), this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex.Lang; return; } } else { if (nameIndex == HtmlNameIndex.Bigger) { base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, FormatStyle.Null, this.token.NameIndex); base.Last.SetProperty(PropertyPrecedence.InlineStyle, PropertyId.FontSize, new PropertyValue(PropertyType.RelHtmlFontUnits, 1)); this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } if (nameIndex == HtmlNameIndex.FontFamily) { base.OpenContainer(FormatContainerType.PropertyContainer, false, 2, FormatStyle.Null, this.token.NameIndex); this.tagPendingParameter = HtmlNameIndex.FontFamily; return; } } this.tagPendingParameter = HtmlNameIndex._NOTANAME; return; } break; case HtmlTokenId.Restart: case HtmlTokenId.OverlappedClose: case HtmlTokenId.OverlappedReopen: break; default: return; } }
public IEnumerable <IHtmlElement> Serialize(object x, int lvl, IHtmlSerializer fac) => SerializeProps(x, lvl, fac, HtmlSupport.PropsOf(x.GetType()), IncludeType);