Exemple #1
0
        private static Inline HandleLeftSquareBracket(Subject subj, bool isImage)
        {
            Inline inlText;

            if (isImage)
            {
                inlText = new Inline("![", subj.Position - 1, subj.Position + 1);
            }
            else
            {
                inlText = new Inline("[", subj.Position, subj.Position + 1);
            }

            // move past the '['
            subj.Position++;

            var istack = new InlineStack();

            istack.Delimeter      = '[';
            istack.StartingInline = inlText;
            istack.StartPosition  = subj.Position;
            istack.Priority       = InlineStack.InlineStackPriority.Links;
            istack.Flags          = InlineStack.InlineStackFlags.Opener | (isImage ? InlineStack.InlineStackFlags.ImageLink : InlineStack.InlineStackFlags.None);

            InlineStack.AppendStackEntry(istack, subj);

            return(inlText);
        }
Exemple #2
0
        private static Inline HandleTilde(Subject subj)
        {
            bool canOpen, canClose;
            var  numdelims = ScanEmphasisDelimeters(subj, '~', out canOpen, out canClose);

            if (numdelims == 1)
            {
                return(new Inline("~", subj.Position - 1, subj.Position));
            }

            if (canClose)
            {
                // walk the stack and find a matching opener, if there is one
                var istack = InlineStack.FindMatchingOpener(subj.LastPendingInline, InlineStack.InlineStackPriority.Emphasis, '~', out canClose);
                if (istack != null)
                {
                    MatchInlineStack(istack, subj, numdelims, null, null, InlineTag.Strikethrough);

                    // if the closer was not fully used, move back a char or two and try again.
                    if (numdelims > 2)
                    {
                        subj.Position = subj.Position - numdelims + 2;

                        // use recursion only if it will not be very deep.
                        if (numdelims < 10)
                        {
                            return(HandleTilde(subj));
                        }
                    }

                    return(null);
                }
            }

            var inlText = new Inline(subj.Buffer, subj.Position - numdelims, numdelims,
                                     subj.Position - numdelims, subj.Position);

            if (canOpen || canClose)
            {
                var istack = new InlineStack();
                istack.DelimeterCount = numdelims;
                istack.Delimeter      = '~';
                istack.StartingInline = inlText;
                istack.Priority       = InlineStack.InlineStackPriority.Emphasis;
                istack.Flags          = (canOpen ? InlineStack.InlineStackFlags.Opener : 0)
                                        | (canClose ? InlineStack.InlineStackFlags.Closer : 0);

                InlineStack.AppendStackEntry(istack, subj);
            }

            return(inlText);
        }
        private static Inline HandleOpenerCloser(Subject subj, InlineTag singleCharTag, InlineTag doubleCharTag)
        {
            bool canOpen, canClose;
            var  c         = subj.Buffer[subj.Position];
            var  numdelims = ScanEmphasisDelimiters(subj, c, out canOpen, out canClose);

            if (canClose)
            {
                // walk the stack and find a matching opener, if there is one
                var istack = InlineStack.FindMatchingOpener(subj.LastPendingInline, InlineStack.InlineStackPriority.Emphasis, c, numdelims, canOpen, out canClose);
                if (istack != null)
                {
                    var useDelims = MatchInlineStack(istack, subj, numdelims, null, singleCharTag, doubleCharTag);

                    if (useDelims > 0)
                    {
                        // if the closer was not fully used, move back a char or two and try again.
                        if (useDelims < numdelims)
                        {
                            subj.Position = subj.Position - numdelims + useDelims;

                            // use recursion only if it will not be very deep.
                            // however it cannot be used if the single char will not be parsed.
                            if (numdelims < 10)
                            {
                                return(HandleOpenerCloser(subj, singleCharTag, doubleCharTag));
                            }
                        }

                        return(null);
                    }
                }
            }

            var inlText = new Inline(subj.Buffer, subj.Position - numdelims, numdelims, subj.Position - numdelims, subj.Position, c);

            if (canOpen || canClose)
            {
                var istack = new InlineStack();
                istack.DelimiterCount = numdelims;
                istack.Delimiter      = c;
                istack.StartingInline = inlText;
                istack.Priority       = InlineStack.InlineStackPriority.Emphasis;
                istack.Flags          = (canOpen ? InlineStack.InlineStackFlags.Opener : 0)
                                        | (canClose ? (InlineStack.InlineStackFlags.Closer | InlineStack.InlineStackFlags.CloserOriginally) : 0);

                InlineStack.AppendStackEntry(istack, subj);
            }

            return(inlText);
        }