Пример #1
0
        public static void ProcessStage2(Syntax.Block document, PandocMarkSettings settings = null)
        {
            if (document is null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (document.Tag != Syntax.BlockTag.Document)
            {
                throw new ArgumentException("The block element passed to this method must represent a top level document.", nameof(document));
            }

            if (settings is null)
            {
                settings = PandocMarkSettings.Default;
            }

            try
            {
                BlockMethods.ProcessInlines(document, document.Document, settings);
            }
            catch (PandocMarkException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new PandocMarkException("An error occurred during inline parsing.", ex);
            }
        }
Пример #2
0
        public static void ProcessStage3(Syntax.Block document, TextWriter target, PandocMarkSettings settings = null)
        {
            if (document is null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (target is null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (document.Tag != Syntax.BlockTag.Document)
            {
                throw new ArgumentException("The block element passed to this method must represent a top level document.", nameof(document));
            }

            if (settings is null)
            {
                settings = PandocMarkSettings.Default;
            }

            try
            {
                switch (settings.OutputFormat)
                {
                case OutputFormat.Html:
                    HtmlFormatterSlim.BlocksToHtml(target, document, settings);
                    break;

                case OutputFormat.SyntaxTree:
                    Printer.PrintBlocks(target, document, settings);
                    break;

                case OutputFormat.CustomDelegate:
                    if (settings.OutputDelegate is null)
                    {
                        throw new PandocMarkException("If `settings.OutputFormat` is set to `CustomDelegate`, the `settings.OutputDelegate` property must be populated.");
                    }
                    settings.OutputDelegate(document, target, settings);
                    break;

                default:
                    throw new PandocMarkException("Unsupported value '" + settings.OutputFormat + "' in `settings.OutputFormat`.");
                }
            }
            catch (PandocMarkException)
            {
                throw;
            }
            catch (IOException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new PandocMarkException("An error occurred during formatting of the document.", ex);
            }
        }