private bool TryStartCodeParser(bool isSingleLineMarkup = false, bool documentLevel = false) { if (CurrentCharacter == RazorParser.TransitionCharacter) { if (CheckForCodeBlockAndSkipIfNotCode()) { // Get the correct span factory SpanFactory spanFactory = null; if (isSingleLineMarkup) { spanFactory = SingleLineMarkupSpan.Create; } else { spanFactory = context => { var span = MarkupSpan.Create(context); span.DocumentLevel = documentLevel; return(span); }; } ParseBlockWithOtherParser(spanFactory, collectTransitionToken: true); return(true); } } return(false); }
private void ParseEndPsuedoTag(Stack <TagInfo> tags, TagInfo tag, bool inDocument) { Debug.Assert(tag.IsEndTag, "ParseEndPsuedoTag requires an end tag"); // Collect what we've seen so far, since the "</text>" is not a markup span, it's a transition span Span prev = null; if (HaveContent) { prev = MarkupSpan.Create(Context); Context.ResetBuffers(); } // Accept the "</text>" Context.Expect("<"); Context.AcceptWhiteSpace(includeNewLines: true); Context.Expect("/text"); bool complete = CurrentCharacter == '>'; if (!complete) { OnError(tag.Start, RazorResources.ParseError_TextTagCannotContainAttributes); } else { Context.AcceptCurrent(); } // Remove the tag UpdateTagStack(tags, tag, !inDocument); if (tags.Count == 0) { // That was the top-level tag, output the markup then a transition span for the </text> if (prev != null) { Output(prev); } End(TransitionSpan.Create(Context, hidden: false, acceptedCharacters: complete ? AcceptedCharacters.None : AcceptedCharacters.Any)); } else { // Wasn't top-level, so resume the original span Context.ResumeSpan(prev); } }
private void ParseRootBlock(Tuple <string, string> nestingSequences, bool caseSensitive = true) { // We're only document level there are no nesting sequences bool documentLevel = nestingSequences == null; // Start a markup block using (StartBlock(BlockType.Markup)) { int nesting = 1; do { if (nestingSequences != null && nestingSequences.Item1 != null && Context.Peek(nestingSequences.Item1, caseSensitive: caseSensitive)) { nesting++; Context.Expect(nestingSequences.Item1, outputError: true, errorMessage: null, caseSensitive: caseSensitive); } else if (nestingSequences != null && Context.Peek(nestingSequences.Item2, caseSensitive: caseSensitive)) { nesting--; if (nesting > 0) { Context.Expect(nestingSequences.Item2, outputError: true, errorMessage: null, caseSensitive: caseSensitive); } } else if (!TryStartCodeParser(documentLevel: documentLevel)) { Context.UpdateSeenValidEmailPrefix(); Context.AcceptCurrent(); } } while (!EndOfFile && (nestingSequences == null || nesting > 0)); if (!Context.PreviousSpanCanGrow || HaveContent) { var span = MarkupSpan.Create(Context); span.DocumentLevel = documentLevel; End(span); } } }