Ejemplo n.º 1
0
        public static void Interpret(ConverterContext context)
        {
            switch (context.Enumerable.Current.Inline.Tag)
            {
            case InlineTag.Strong:
                HandleStrong(context);
                break;

            case InlineTag.Emphasis:
                HandleEmphasis(context);
                break;

            case InlineTag.String:
            case InlineTag.RawHtml:
                HandleText(context);
                break;

            case InlineTag.LineBreak:
            case InlineTag.SoftBreak:
                HandleBreak(context);
                break;

            default:
                throw new InvalidOperationException($"Unable to handle inline tag {context.Enumerable.Current.Inline.Tag}");
            }
        }
        private static Speech Convert(Block block)
        {
            var context = new ConverterContext(block.AsEnumerable().GetEnumerator());

            while (context.Enumerable.MoveNext())
            {
                var element = context.Enumerable.Current;
                if (ConversionHandled?.Invoke(element, context) ?? false)
                {
                    continue;
                }

                if (element.Block != null)
                {
                    BlockInterpreter.Interpret(context);
                }

                if (element.Inline != null)
                {
                    InlineInterpreter.Interpret(context);
                }
            }

            return(context.Speech);
        }
Ejemplo n.º 3
0
        private static void HandleBreak(ConverterContext context)
        {
            context.PopUntil <Paragraph>();
            var sentence = new Sentence();

            context.Add(sentence);
            context.AddStack.Push(sentence);
        }
Ejemplo n.º 4
0
        private static void HandleStrong(ConverterContext context)
        {
            if (!context.Enumerable.Current.IsOpening)
            {
                throw new InvalidOperationException("Closing strong without opening");
            }

            var text = TextUntil(context, InlineTag.Strong);

            context.Add(new Emphasis(text)
            {
                Level = EmphasisLevel.Strong
            });
        }
Ejemplo n.º 5
0
        public static void Interpret(ConverterContext context)
        {
            switch (context.Enumerable.Current.Block.Tag)
            {
            case BlockTag.Document:
                break;

            case BlockTag.Paragraph:
                HandleParagraph(context);
                break;

            default:
                throw new InvalidOperationException($"Unable to handle block tag {context.Enumerable.Current.Block.Tag}");
            }
        }
Ejemplo n.º 6
0
        private static void HandleParagraph(ConverterContext context)
        {
            context.AddStack.Clear();

            if (context.Enumerable.Current.IsOpening)
            {
                var sentence  = new Sentence();
                var paragraph = new Paragraph();
                paragraph.Elements.Add(sentence);
                context.Speech.Elements.Add(paragraph);

                context.AddStack.Push(paragraph);
                context.AddStack.Push(sentence);
            }
        }
Ejemplo n.º 7
0
        private static string TextUntil(ConverterContext context, InlineTag tag)
        {
            var osb = new StringBuilder();

            while (context.Enumerable.MoveNext())
            {
                var element = context.Enumerable.Current;
                if (element.Inline == null || element.Inline.Tag == tag)
                {
                    break;
                }

                osb.Append(element.Inline.LiteralContent);
            }

            return(osb.ToString());
        }
Ejemplo n.º 8
0
        public static void HandleEmphasis(ConverterContext context)
        {
            if (!context.Enumerable.Current.IsOpening)
            {
                throw new InvalidOperationException("Closing emphasis without opening");
            }

            var text = TextUntil(context, InlineTag.Emphasis);

            context.Add(new Prosody
            {
                Elements = new List <ISsml> {
                    new PlainText(text)
                },
                Pitch = ProsodyPitch.ExtraHigh
            });
        }
Ejemplo n.º 9
0
 private static void HandleText(ConverterContext context)
 {
     context.Add(new PlainText(context.Enumerable.Current.Inline.LiteralContent));
 }