Пример #1
0
        public string CompileForHtml(string text)
        {
            string preprocessedText = PreprocessText(text);

            string[] lines = preprocessedText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

            int?titlePos = null;

            if (_topicCompilerSettings.AddHtmlHeaderFooter)
            {
                _sb.Append(
                    "<html>" +
                    "<head>" +
                    "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">" +
                    "<title>");

                titlePos = _sb.Length;

                _sb.Append("</title>");
                _sb.Append(_topicCompilerSettings.GetTopicStylesheet());
                _sb.Append(
                    "</head>" +
                    "<body>");
            }

            _sb.Append(_topicCompilerSettings.GetStartingHtml(_preprocessedTopic));

            List <string> paragraphs = LinesToParagraphs(lines);

            foreach (string paragraph in paragraphs)
            {
                string html = ProcessParagraph(paragraph);

                if (html.Length > 0)
                {
                    _sb.AppendFormat("<div class=\"paragraph\">{0}</div>\n", html);
                }
            }

            if (_title == null)
            {
                throw new Exception("A title must be specified for the topic.");
            }

            if (titlePos != null)
            {
                _sb.Insert((int)titlePos, _topicCompilerSettings.GetTitle(_title));
            }

            _topicCompilerSettings.Title = _title;

            _sb.Append(_topicCompilerSettings.EndingHtml);

            if (_topicCompilerSettings.AddHtmlHeaderFooter)
            {
                _sb.Append(
                    "</body>" +
                    "</html>");
            }

            return(_sb.ToString());
        }