public static QuirksMode GetQuirksMode(this HtmlDoctypeToken doctype) { if (doctype.IsFullQuirks) { return(QuirksMode.On); } else if (doctype.IsLimitedQuirks) { return(QuirksMode.Limited); } return(QuirksMode.Off); }
/// <summary> /// See 8.2.4.61 Between DOCTYPE public and system identifiers state /// </summary> /// <param name="c">The next input character.</param> /// <param name="doctype">The current doctype token.</param> /// <returns>The emitted token.</returns> HtmlToken DoctypeBetween(Char c, HtmlDoctypeToken doctype) { while (c.IsSpaceCharacter()) c = Next; if (c == Specification.GreaterThan) { _state = HtmlParseMode.PCData; return doctype; } else if (c == Specification.DoubleQuote) { doctype.SystemIdentifier = String.Empty; return DoctypeSystemIdentifierDoubleQuoted(Next, doctype); } else if (c == Specification.SingleQuote) { doctype.SystemIdentifier = String.Empty; return DoctypeSystemIdentifierSingleQuoted(Next, doctype); } else if (c == Specification.EndOfFile) { RaiseErrorOccurred(ErrorCode.EOF); doctype.IsQuirksForced = true; Back(); return doctype; } RaiseErrorOccurred(ErrorCode.DoctypeInvalidCharacter); doctype.IsQuirksForced = true; return BogusDoctype(Next, doctype); }
/// <summary> /// See 8.2.4.54 DOCTYPE name state /// </summary> /// <param name="c">The next input character.</param> /// <param name="doctype">The current doctype token.</param> /// <returns>The emitted token.</returns> HtmlToken DoctypeName(Char c, HtmlDoctypeToken doctype) { while (true) { if (c.IsSpaceCharacter()) { doctype.Name = _stringBuffer.ToString(); _stringBuffer.Clear(); return DoctypeNameAfter(Next, doctype); } else if (c == Specification.GreaterThan) { _state = HtmlParseMode.PCData; doctype.Name = _stringBuffer.ToString(); return doctype; } else if (c.IsUppercaseAscii()) _stringBuffer.Append(Char.ToLower(c)); else if (c == Specification.Null) { RaiseErrorOccurred(ErrorCode.Null); _stringBuffer.Append(Specification.Replacement); } else if (c == Specification.EndOfFile) { RaiseErrorOccurred(ErrorCode.EOF); Back(); doctype.IsQuirksForced = true; doctype.Name = _stringBuffer.ToString(); return doctype; } else _stringBuffer.Append(c); c = Next; } }
/// <summary> /// See 8.2.4.67 Bogus DOCTYPE state /// </summary> /// <param name="c">The next input character.</param> /// <param name="doctype">The current doctype token.</param> /// <returns>The emitted token.</returns> HtmlToken BogusDoctype(Char c, HtmlDoctypeToken doctype) { while (true) { if (c == Specification.EndOfFile) { Back(); return doctype; } else if (c == Specification.GreaterThan) { _state = HtmlParseMode.PCData; return doctype; } c = Next; } }
/// <summary> /// See 8.2.4.65 DOCTYPE system identifier (single-quoted) state /// </summary> /// <param name="c">The next input character.</param> /// <param name="doctype">The current doctype token.</param> /// <returns>The emitted token.</returns> HtmlToken DoctypeSystemIdentifierSingleQuoted(Char c, HtmlDoctypeToken doctype) { while (true) { if (c == Specification.SingleQuote) { doctype.SystemIdentifier = _stringBuffer.ToString(); _stringBuffer.Clear(); return DoctypeSystemIdentifierAfter(Next, doctype); } else if (c == Specification.Null) { RaiseErrorOccurred(ErrorCode.Null); _stringBuffer.Append(Specification.Replacement); } else if (c == Specification.GreaterThan) { _state = HtmlParseMode.PCData; RaiseErrorOccurred(ErrorCode.TagClosedWrong); doctype.IsQuirksForced = true; doctype.SystemIdentifier = _stringBuffer.ToString(); return doctype; } else if (c == Specification.EndOfFile) { RaiseErrorOccurred(ErrorCode.EOF); doctype.IsQuirksForced = true; doctype.SystemIdentifier = _stringBuffer.ToString(); Back(); return doctype; } else _stringBuffer.Append(c); c = Next; } }
/// <summary> /// See 8.2.4.62 After DOCTYPE system keyword state /// </summary> /// <param name="c">The next input character.</param> /// <param name="doctype">The current doctype token.</param> /// <returns>The emitted token.</returns> HtmlToken DoctypeSystem(Char c, HtmlDoctypeToken doctype) { if (c.IsSpaceCharacter()) { _state = HtmlParseMode.PCData; return DoctypeSystemIdentifierBefore(Next, doctype); } else if (c == Specification.DoubleQuote) { RaiseErrorOccurred(ErrorCode.DoubleQuotationMarkUnexpected); doctype.SystemIdentifier = string.Empty; return DoctypeSystemIdentifierDoubleQuoted(Next, doctype); } else if (c == Specification.SingleQuote) { RaiseErrorOccurred(ErrorCode.SingleQuotationMarkUnexpected); doctype.SystemIdentifier = string.Empty; return DoctypeSystemIdentifierSingleQuoted(Next, doctype); } else if (c == Specification.GreaterThan) { RaiseErrorOccurred(ErrorCode.TagClosedWrong); doctype.SystemIdentifier = _stringBuffer.ToString(); doctype.IsQuirksForced = true; return doctype; } else if (c == Specification.EndOfFile) { RaiseErrorOccurred(ErrorCode.EOF); doctype.IsQuirksForced = true; Back(); return doctype; } RaiseErrorOccurred(ErrorCode.DoctypeSystemInvalid); doctype.IsQuirksForced = true; return BogusDoctype(Next, doctype); }
/// <summary> /// See 8.2.4.57 Before DOCTYPE public identifier state /// </summary> /// <param name="c">The next input character.</param> /// <param name="doctype">The current doctype token.</param> /// <returns>The emitted token.</returns> HtmlToken DoctypePublicIdentifierBefore(Char c, HtmlDoctypeToken doctype) { while (c.IsSpaceCharacter()) c = Next; if (c == Specification.DoubleQuote) { _stringBuffer.Clear(); doctype.PublicIdentifier = String.Empty; return DoctypePublicIdentifierDoubleQuoted(Next, doctype); } else if (c == Specification.SingleQuote) { _stringBuffer.Clear(); doctype.PublicIdentifier = String.Empty; return DoctypePublicIdentifierSingleQuoted(Next, doctype); } else if (c == Specification.GreaterThan) { _state = HtmlParseMode.PCData; RaiseErrorOccurred(ErrorCode.TagClosedWrong); doctype.IsQuirksForced = true; return doctype; } else if (c == Specification.EndOfFile) { RaiseErrorOccurred(ErrorCode.EOF); doctype.IsQuirksForced = true; Back(); return doctype; } RaiseErrorOccurred(ErrorCode.DoctypePublicInvalid); doctype.IsQuirksForced = true; return BogusDoctype(Next, doctype); }
/// <summary> /// See 8.2.4.55 After DOCTYPE name state /// </summary> /// <param name="c">The next input character.</param> /// <param name="doctype">The current doctype token.</param> /// <returns>The emitted token.</returns> HtmlToken DoctypeNameAfter(Char c, HtmlDoctypeToken doctype) { while (c.IsSpaceCharacter()) c = Next; if (c == Specification.GreaterThan) { _state = HtmlParseMode.PCData; return doctype; } else if (c == Specification.EndOfFile) { RaiseErrorOccurred(ErrorCode.EOF); Back(); doctype.IsQuirksForced = true; return doctype; } else if (ContinuesWith("public")) { Advance(5); return DoctypePublic(Next, doctype); } else if (ContinuesWith("system")) { Advance(5); return DoctypeSystem(Next, doctype); } RaiseErrorOccurred(ErrorCode.DoctypeUnexpectedAfterName); doctype.IsQuirksForced = true; return BogusDoctype(Next, doctype); }