public static void WriteStringValue(
            this DocumentWriter writer,
            StringValueNode node)
        {
            if (node.Block)
            {
                writer.Write("\"\"\"");

                var lines = node.Value
                            .Replace("\"\"\"", "\\\"\"\"")
                            .Replace("\r", string.Empty)
                            .Split('\n');

                foreach (var line in lines)
                {
                    writer.WriteLine();
                    writer.WriteIndentation();
                    writer.Write(line);
                }

                writer.WriteLine();
                writer.WriteIndentation();
                writer.Write("\"\"\"");
            }
            else
            {
                writer.Write($"\"{WriteEscapeCharacters(node.Value)}\"");
            }
        }
        public void Indent_WriteIndentation_Unindent_WriteIndentation()
        {
            // arrange
            var stringBuilder = new StringBuilder();
            var writer        = new DocumentWriter(stringBuilder);

            // act
            writer.Indent();
            writer.WriteIndentation();
            writer.WriteLine();
            writer.Unindent();
            writer.WriteIndentation();

            // assert
            Assert.Equal(
                "  " + writer.NewLine + string.Empty,
                stringBuilder.ToString());
        }
Beispiel #3
0
        protected override void VisitDocument(DocumentNode node)
        {
            if (node.Definitions.Any())
            {
                VisitDefinition(node.Definitions.First());

                foreach (IDefinitionNode item in node.Definitions.Skip(1))
                {
                    if (_indent)
                    {
                        _writer.WriteLine();
                        _writer.WriteLine();
                    }
                    else
                    {
                        _writer.WriteSpace();
                    }

                    VisitDefinition(item);
                }
            }
        }