void RenderParagraphInto(Paragraph paragraph, XmlElement container)
        {
            XmlElement paragraphElement = container.OwnerDocument.CreateElement("paragraph");
            container.AppendChild(paragraphElement);

            container.AppendChild(container.OwnerDocument.CreateTextNode("\n"));

            RenderSpanInto(paragraph.Span, paragraphElement);
        }
        static Section GenerateErrorDocument(Exception ex, LineClassifier classifier)
        {
            ParseErrorSection topSection = new ParseErrorSection();

            Paragraph paragraph = new Paragraph(new FormattedSpan(FormattedSpanKind.Bold, new TextSpan("I can haz fixed?")));
            topSection.Blocks.Add(paragraph);

            LineClassifierContext context = classifier.GetContext();

            List<string> lines = new List<string>();

            foreach (Pair<int, string> pair in context.AllLines)
            {
                lines.Add(string.Format("{0} {1}: {2}",
                    pair.First == context.CurrentLine.First ? ">" : " ",
                    pair.First.ToString().PadLeft(4, ' '),
                    pair.Second));
            }

            VerbatimBlock linesBlock = new VerbatimBlock();
            linesBlock.Lines.AddRange(lines);

            topSection.Blocks.Add(linesBlock);

            return topSection;
        }
示例#3
0
 public virtual void VisitParagraph(Paragraph paragraph)
 {
 }
        public void ResolveReferences(IAdornedReferenceResolver resolver)
        {
            if (_topSection == null) throw new InvalidOperationException(AdornedTextStrings.AdornedProcessorNotParsed);

            // Find all inlines:
            InlineListBuildingVisitor inlineVisitor = new InlineListBuildingVisitor();
            _topSection.Visit(inlineVisitor);

            foreach (InlineBlock inline in inlineVisitor.Inlines)
            {
                Uri replacement = resolver.ResolveInline(inline.ContentType, inline.Text);

                int inlineIndex = inline.Parent.Blocks.IndexOf(inline);

                if (replacement == null)
                {
                    inline.Parent.Blocks.RemoveAt(inlineIndex);
                }
                else
                {
                    Paragraph paragraph = new Paragraph(
                        new ReferenceSpan("image", replacement.ToString(), null));

                    inline.Parent.Blocks[inlineIndex] = paragraph;
                }
            }

            // Find all references within the document:
            ReferenceListBuildingVisitor referenceVisitor = new ReferenceListBuildingVisitor();
            _topSection.Visit(referenceVisitor);

            List<ReferenceSpan> references = referenceVisitor.References;

            foreach (ReferenceSpan reference in references)
            {
                try
                {
                    Uri referenceUri = new Uri(reference.Reference);

                    if (referenceUri.Scheme == "adorned")
                    {
                        Uri newUri = resolver.ResolveReference(referenceUri);

                        if (newUri != null) reference.Reference = newUri.ToString();
                    }
                }
                catch (UriFormatException ex)
                {
                    reference.ResolutionException = ex;
                }
                catch (AdornedReferenceResolutionException ex)
                {
                    reference.ResolutionException = ex;
                }
            }
        }