Esempio n. 1
0
        /// <summary>
        /// Renders the mobiledoc using the rendering settings specified for this renderer.
        /// </summary>
        /// <param name="mobileDoc">Mobiledoc instance to render.</param>
        /// <returns>Returns the rendered mobiledoc instance.</returns>
        public string Render(MobileDoc mobileDoc)
        {
            var outputBuffer = new StringBuilder();
            var outputWriter = new StringWriter(outputBuffer);
            var walker       = new MobileDocWalker();

            var listener = new MobileDocHtmlTranslator(_cardRenderers, _atomRenderers, outputWriter);

            walker.Walk(mobileDoc, listener, Enumerable.Empty <ISectionListener>());

            outputWriter.Flush();

            return(outputBuffer.ToString());
        }
        /// <summary>
        /// Serializes a mobile doc to JSON
        /// </summary>
        /// <param name="document">Document to serialize</param>
        /// <returns>Returns the serialized document.</returns>
        public static string Serialize(MobileDoc document)
        {
            var outputBuilder = new StringBuilder();

            using var jsonWriter = new JsonTextWriter(new StringWriter(outputBuilder));

            var documentListener = new MobileDocJsonTranslator(jsonWriter);

            var sectionListeners = new ISectionListener[]
            {
                new MarkupSectionJsonTranslator(jsonWriter),
                new CardSectionJsonTranslator(jsonWriter),
                new ListSectionJsonTranslator(jsonWriter),
                new ImageSectionJsonTranslator(jsonWriter),
            };

            var walker = new MobileDocWalker();

            walker.Walk(document, documentListener, sectionListeners);

            jsonWriter.Flush();

            return(outputBuilder.ToString());
        }