コード例 #1
0
        private void ReadQuote(TagHelperContent output, StringBuilder builder, SourceReader reader)
        {
            reader.Skip();
            while (reader.Current != SourceReader.NullChar)
            {
                if (reader.Current == '$' && reader.IsNextNonWhiteSpace('{'))
                {//代码块
                    Queue(output, builder);
                    ReadInlineCode(output, reader);
                }

                if (reader.Current == '`')
                {
                    if (reader.IsNext('`'))
                    {
                        reader.Skip();
                    }
                    else
                    {
                        //字符串结束
                        Queue(output, builder, ' ');
                        reader.Skip();
                        reader.MoveNext();
                        return;
                    }
                }

                builder.Append(reader.Current);
                reader.Skip();
            }
        }
コード例 #2
0
        /// <summary>
        /// 初始化类<see cref="BlazorCodeBehindTransfer"/>。
        /// </summary>
        /// <param name="file">当前文件信息。</param>
        public BlazorCodeBehindTransfer(FileInfo file)
            : base(file)
        {
            var source = new StringBuilder();

            using var reader = new SourceReader(Source);
            var index = reader.IndexOf("@code");

            if (index != -1)
            {
                reader.Offset(index + 5);
                reader.EscapeWhiteSpace();
                if (reader.IsNext('{'))
                {
                    source.Append(Source.Substring(0, index));
                    Code = reader.ReadQuoteBlock('{', '}');
                    source.Append(reader.ReadToEnd());
                    Source = source.ToString().Trim();
                }
            }
        }
コード例 #3
0
        private void Process(TagHelperContent output, string source)
        {
            var reader  = new SourceReader(source);
            var builder = new StringBuilder();

            while (reader.MoveNext())
            {
                if (reader.Current == '<' && !reader.IsNext(' '))
                {//读取html标签
                    ReadHtml(output, builder, reader);
                    continue;
                }

                if (reader.Current == '$' && reader.IsNextNonWhiteSpace('{'))
                {//代码块
                    Queue(output, builder);
                    ReadInlineCode(output, reader);
                    continue;
                }

                if (reader.Current == '`')
                {//字符串
                    ReadQuote(output, builder, reader);
                    continue;
                }

                var code = reader.ReadUntil(new[] { '`', '<' }).Trim();
                foreach (var s in code.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (string.IsNullOrWhiteSpace(s))
                    {
                        continue;
                    }
                    output.AppendHtml(s.Trim());
                }
            }
        }