Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mamlCommands"></param>
        /// <param name="skipPreambula">Don't include header and footer for xml doc</param>
        /// <returns></returns>
        public string MamlModelToString(IEnumerable <MamlCommand> mamlCommands, bool skipPreambula)
        {
            _stringBuilder.Clear();
            if (!skipPreambula)
            {
                _stringBuilder.AppendLine(XML_PREAMBULA);
            }

            AddCommands(mamlCommands);

            if (!skipPreambula)
            {
                _stringBuilder.AppendLine("</helpItems>");
            }

            return(RenderCleaner.NormalizeWhitespaces(_stringBuilder.ToString()));
        }
Пример #2
0
        public string AboutMarkdownToString(DocumentNode document)
        {
            //ensure that all node types in the about topic are handeled.
            var acceptableNodeTypes = new List <MarkdownNodeType>
            {
                MarkdownNodeType.Heading,
                MarkdownNodeType.Paragraph,
                MarkdownNodeType.CodeBlock
            };

            if (document.Children.Any(c => (!acceptableNodeTypes.Contains(c.NodeType))))
            {
                throw new NotSupportedException("About Topics can only have heading, parapgrah or code block nodes in their Markdown Model.");
            }

            //processes all nodes in order
            foreach (var currentNode in document.Children)
            {
                switch (currentNode.NodeType)
                {
                case MarkdownNodeType.Paragraph:
                    ParagraphNode paragraphNode = currentNode as ParagraphNode;
                    AddAboutParagraph(paragraphNode);
                    break;

                case MarkdownNodeType.Heading:
                    HeadingNode headingNode = currentNode as HeadingNode;
                    AddAboutHeading(headingNode, document);
                    break;

                case MarkdownNodeType.CodeBlock:
                    CodeBlockNode codeblockNode = currentNode as CodeBlockNode;
                    AddAboutCodeBlock(codeblockNode);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(RenderCleaner.FullNormalization(_stringBuilder.ToString()));
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mamlCommands"></param>
        /// <param name="skipPreambula">Don't include header and footer for xml doc</param>
        /// <returns></returns>
        public string MamlModelToString(IEnumerable <MamlCommand> mamlCommands)
        {
            var document = new XDocument(
                new XDeclaration("1.0", "utf-8", null),
                new XElement(mshNS + "helpItems",
                             new XAttribute("schema", "maml"),

                             mamlCommands.Select(CreateCommandElement)));

            var memoryStream = new MemoryStream();

            using (var writer = new StreamWriter(memoryStream, Encoding.UTF8))
            {
                document.Save(writer, SaveOptions.OmitDuplicateNamespaces);
                writer.Flush();

                memoryStream.Seek(0, SeekOrigin.Begin);
                using (var reader = new StreamReader(memoryStream, Encoding.UTF8))
                {
                    return(RenderCleaner.NormalizeWhitespaces(reader.ReadToEnd()));
                }
            }
        }
Пример #4
0
        private string MamlModelToString(MamlCommand mamlCommand, Hashtable yamlHeader, bool skipYamlHeader)
        {
            // clear, so we can re-use this instance
            _stringBuilder.Clear();
            if (!skipYamlHeader)
            {
                if (yamlHeader == null)
                {
                    yamlHeader = new Hashtable();
                }

                // put version there
                yamlHeader["schema"] = "2.0.0";
                AddYamlHeader(yamlHeader);
            }

            AddCommand(mamlCommand);

            // at the end, just normalize all ends
            return(RenderCleaner.NormalizeLineBreaks(
                       RenderCleaner.NormalizeWhitespaces(
                           RenderCleaner.NormalizeQuotesAndDashes(
                               _stringBuilder.ToString()))));
        }