public override void VisitSpan(Span span)
        {
            if (span.Kind == SpanKind.Markup && !m_DebugStatusReader.IsDebuggingEnabled())
            {
                string content = m_HtmlPageMinifier.Minify(span.Content, true, true);

                SpanBuilder builder = new SpanBuilder { CodeGenerator = span.CodeGenerator, EditHandler = span.EditHandler, Kind = span.Kind, Start = span.Start };
                MarkupSymbol symbol = new MarkupSymbol { Content = content };
                builder.Accept(symbol);
                span.ReplaceWith(builder);
            }
       
            base.VisitSpan(span);
        }
        public override void VisitSpan(Span span)
        {
            if (span.Kind == SpanKind.Markup)
              {
            string content = span.Content;

            content = _minifier.Minify(content);

            // We replace the content with the minified markup
            // and then let the CSharp/VB generator do their jobs.
            var builder = new SpanBuilder { CodeGenerator = span.CodeGenerator, EditHandler = span.EditHandler, Kind = span.Kind, Start = span.Start };
            var symbol = new MarkupSymbol { Content = content };
            builder.Accept(symbol);
            span.ReplaceWith(builder);
              }

              base.VisitSpan(span);
        }
 protected virtual SpanBuilder UpdateSpan(Span target, TextChange normalizedChange)
 {
     string newContent = normalizedChange.ApplyChange(target);
     SpanBuilder newSpan = new SpanBuilder(target);
     newSpan.ClearSymbols();
     foreach (ISymbol sym in Tokenizer(newContent))
     {
         sym.OffsetStart(target.Start);
         newSpan.Accept(sym);
     }
     if (target.Next != null)
     {
         SourceLocation newEnd = SourceLocationTracker.CalculateNewLocation(target.Start, newContent);
         target.Next.ChangeStart(newEnd);
     }
     return newSpan;
 }
 public SpanConstructor(SpanKind kind, IEnumerable<ISymbol> symbols)
 {
     Builder = new SpanBuilder();
     Builder.Kind = kind;
     Builder.EditHandler = SpanEditHandler.CreateDefault(TestTokenizer);
     foreach (ISymbol sym in symbols)
     {
         Builder.Accept(sym);
     }
 }
        private void MinifyMarkup(BlockBuilder block)
        {
            var codeGenerator = new MarkupCodeGenerator();
            var previousIsWhiteSpace = true;
            var previousTokenEndsWithBlockElement = true;

            for (int i = 0; i < block.Children.Count; i++)
            {
                var node = block.Children[i];
                var span = node as Span;
                if (span == null)
                {
                    // When we have a dynamic markup, we can't know if the last char will be whitespace
                    // => to make it work in all cases, we won't minifiy whitespace just after code.
                    previousIsWhiteSpace = false;
                    previousTokenEndsWithBlockElement = false;
                    continue;
                }

                // There may be several HTML tokens just one after the other.
                // => we concatenate everything in a single token to minify everyting in a single scan
                // (we is better for Javascript minification).
                var sb = new StringBuilder();
                sb.Append(span.Content);
                if (i < block.Children.Count - 1)
                {
                    var markup = block.Children[i + 1] as Span;
                    while ((markup != null) && (markup.Kind == SpanKind.Markup) && ((markup.Next == null) || ((markup.Next != null) && ((markup.Next.Kind == SpanKind.Markup) || ((markup.Next.Kind != SpanKind.Markup) && !markup.Content.EndsWith("\""))))))
                    {
                        block.Children.RemoveAt(i + 1);
                        sb.Append(markup.Content);
                        markup = i + 1 < block.Children.Count ? block.Children[i + 1] as Span : null;
                    }
                }

                var content = sb.ToString();
                if (string.IsNullOrEmpty(content))
                {
                    // Nothing to minify
                    block.Children.RemoveAt(i);
                    continue;
                }

                content = _minifier.Minify(content, previousIsWhiteSpace, previousTokenEndsWithBlockElement);

                _minifier.AnalyseContent(content, ref previousIsWhiteSpace, ref previousTokenEndsWithBlockElement);

                // We replace the content with the minified markup
                // and then let the CSharp/VB generator do their jobs.
                var builder = new SpanBuilder() { CodeGenerator = codeGenerator, EditHandler = span.EditHandler, Kind = span.Kind, Start = span.Start };
                var symbol = new MarkupSymbol() { Content = content };
                builder.Accept(symbol);
                span.ReplaceWith(builder);
            }
        }
        public void AddSpanAddsSpanToCurrentBlockBuilder()
        {
            // Arrange
            var factory = SpanFactory.CreateCsHtml();
            Mock<ParserVisitor> mockListener = new Mock<ParserVisitor>();
            ParserContext context = SetupTestContext("phoo");

            SpanBuilder builder = new SpanBuilder()
            {
                Kind = SpanKind.Code
            };
            builder.Accept(new CSharpSymbol(1, 0, 1, "foo", CSharpSymbolType.Identifier));
            Span added = builder.Build();

            using (context.StartBlock(BlockType.Functions))
            {
                context.AddSpan(added);
            }

            BlockBuilder expected = new BlockBuilder()
            {
                Type = BlockType.Functions,
            };
            expected.Children.Add(added);

            // Assert
            ParserTestBase.EvaluateResults(context.CompleteParse(), expected.Build());
        }