Пример #1
0
        public void RenderDocument(TextReader documentReader, IAdornedReferenceResolver resolver, TextWriter outputTo)
        {
            AdornedProcessor processor = new AdornedProcessor();
            processor.Parse(documentReader);

            RenderProcessor(processor, resolver, outputTo, "document");
        }
        internal void RenderWith(Section document, IAdornedReferenceResolver resolver, AdornedRenderer renderer)
        {
            _documentfileName = CreateTemporaryFilePath("document.html");

            using (StreamWriter writer = new StreamWriter(_documentfileName))
            {
                renderer.RenderDocument(document, resolver, writer);
            }
        }
Пример #3
0
        public void RenderDocument(Section parsedDocument, IAdornedReferenceResolver resolver, TextWriter outputTo)
        {
            AdornedProcessor processor = new AdornedProcessor();
            processor.Assign(parsedDocument);

            RenderProcessor(processor, resolver, outputTo, "document");
        }
Пример #4
0
        public void RenderProcessor(AdornedProcessor processor, IAdornedReferenceResolver resolver, TextWriter outputTo, string resultKind)
        {
            processor.Preprocess(_preprocessor);
            processor.ResolveReferences(resolver);
            XmlDocument document = processor.RenderToXml();

            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddParam("result-kind", "", resultKind);

            _renderer.Write(document, outputTo, arguments);
        }
Пример #5
0
        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;
                }
            }
        }