Exemplo n.º 1
0
        public Section Parse()
        {
            Section section = new Section(null, 0);
            ParseSection(section);

            return section;
        }
Exemplo n.º 2
0
        public void Assign(Section document)
        {
            if (_topSection != null)
            {
                throw new InvalidOperationException(AdornedTextStrings.AdornedProcessorAlreadyParsed);
            }

            _topSection = document;
        }
Exemplo n.º 3
0
        public XmlDocument Render(Section rootSection)
        {
            XmlDocument document = new XmlDocument();
            document.XmlResolver = null;

            XmlElement rootElement = document.CreateElement("document");
            document.AppendChild(rootElement);

            RenderSection(rootSection, rootElement, 0);

            return document;
        }
        public string NavigateTo(Section document, string referencesDirectory, AdornedRenderer renderer,
            IAdornedReferenceResolverFactory referenceResolverFactory)
        {
            if (_currentRendering != null)
            {
                _currentRendering.Dispose();
            }

            _currentRendering = new AdornedBrowserRendering();

            IAdornedReferenceResolver resolver =
                referenceResolverFactory.CreateReferenceResolver(_currentRendering, referencesDirectory);

            _currentRendering.RenderWith(document, resolver, renderer);

            return _currentRendering.DocumentFileName;
        }
 public string NavigateTo(Section document, string referencesDirectory, AdornedRenderer renderer)
 {
     return NavigateTo(document, referencesDirectory, renderer);
 }
Exemplo n.º 6
0
        void RenderSection(Section section, XmlElement container, int parentSections)
        {
            XmlElement sectionElement = container.OwnerDocument.CreateElement(string.Format("section-{0}", parentSections + 1));
            container.AppendChild(sectionElement);

            XmlElement titleElement = container.OwnerDocument.CreateElement(string.Format("heading-{0}", parentSections + 1));

            AddText(titleElement, section.Title);

            sectionElement.AppendChild(titleElement);

            RenderBlockSequenceInto(section, sectionElement, parentSections + 1);
        }
        internal void RenderWith(Section document, IAdornedReferenceResolver resolver, AdornedRenderer renderer)
        {
            _documentfileName = CreateTemporaryFilePath("document.html");

            using (StreamWriter writer = new StreamWriter(_documentfileName))
            {
                renderer.RenderDocument(document, resolver, writer);
            }
        }
Exemplo n.º 8
0
 public virtual void VisitSection(Section section)
 {
 }
Exemplo n.º 9
0
        public void RenderDocument(Section parsedDocument, IAdornedReferenceResolver resolver, TextWriter outputTo)
        {
            AdornedProcessor processor = new AdornedProcessor();
            processor.Assign(parsedDocument);

            RenderProcessor(processor, resolver, outputTo, "document");
        }
Exemplo n.º 10
0
        public void Parse(TextReader reader)
        {
            if (_topSection != null)
            {
                throw new InvalidOperationException(AdornedTextStrings.AdornedProcessorAlreadyParsed);
            }

            LineClassifier classifier = new LineClassifier(reader);
            Parser parser = new Parser(classifier);

            try
            {
                _topSection = parser.Parse();
            }
            catch (AdornedTextParsingException ex)
            {
                _topSection = GenerateErrorDocument(ex, classifier);
            }
        }
Exemplo n.º 11
0
        void RenderSection(Section section, XmlElement container)
        {
            XmlElement sectionElement = container.OwnerDocument.CreateElement("section");
            container.AppendChild(sectionElement);

            if (section.Title != null) sectionElement.SetAttribute("title", section.Title);

            RenderBlockSequenceInto(section, sectionElement);
        }
Exemplo n.º 12
0
        Section ParseSectionStart()
        {
            Line titleLine = _classifier.ReadLine();

            Debug.Assert(titleLine.Classification == LineClassification.Title ||
                         titleLine.Classification == LineClassification.NumberedTitle);

            Section section = new Section(titleLine.Text, titleLine.ClassificationLevel);

            ParseSection(section);

            return section;
        }
Exemplo n.º 13
0
        void ParseSection(Section section)
        {
            while (!_classifier.AtEnd)
            {
                Line line = _classifier.PeekLine();

                switch (line.Classification)
                {
                    case LineClassification.Unclassified:
                        section.Blocks.Add(ParseParagraph());
                        break;

                    case LineClassification.Blank:
                    case LineClassification.Comment:
                        // Blank lines in sections and comments are ignored:
                        _classifier.ReadLine();
                        break;

                    case LineClassification.Title:
                    case LineClassification.NumberedTitle:
                        // A lower or same level section title means this section is ending:
                        if (line.ClassificationLevel <= section.TitleLevel) return;

                        // Otherwise, it's a sub-section:
                        section.Blocks.Add(ParseSectionStart());
                        break;

                    case LineClassification.ListItem:
                    case LineClassification.NumeredListItem:
                        section.Blocks.Add(ParseList());
                        break;

                    case LineClassification.DefinitionListTerm:
                        section.Blocks.Add(ParseDefinitionList());
                        break;

                    case LineClassification.SingleVerbatimBlockLine:
                        section.Blocks.Add(ParseSingleVerbatimLine());
                        break;

                    case LineClassification.VerbatimBlockLine:
                        section.Blocks.Add(ParseVerbatimBlock());
                        break;

                    case LineClassification.TableOpen:
                        section.Blocks.Add(ParseTable());
                        break;

                    case LineClassification.InlineOpen:
                        section.Blocks.Add(ParseInline());
                        break;

                    default:
                        throw new AdornedTextParsingException(AdornedTextStrings.AdornedInternalUnexpected);
                }
            }
        }