コード例 #1
0
        private static EMElement CreateBracketed(
            IMatch match, EMDocument doc, EMElementOrigin origin, EMElement parent, TransformationData data)
        {
            var taggedMatch = match as EMBracketedImagesAndLinksMatch;

            // Check if image.
            if (taggedMatch.Text.StartsWith("!") && !string.IsNullOrWhiteSpace(taggedMatch.Parameters))
            {
                EMElement outElement = null;

                var fragments = new List <TextFragment>()
                {
                    new TextFragment(origin.Start, match.Text)
                };

                EMParsingHelper.ParseElements(
                    data, doc, parent, fragments, EMImage.GetParser(), element => { outElement = element; });

                if (outElement == null)
                {
                    string imageError = "Could not find image in given text: " + origin.Text;
                    throw new InvalidOperationException(imageError);
                }

                return(outElement);
            }

            // Check if shortcut ref
            if (string.IsNullOrWhiteSpace(taggedMatch.Parameters))
            {
                return(EMLink.CreateFromAnchorRefShortcut(
                           EMLink.AnchorRefShortcut.Match(taggedMatch.Text), doc, origin, parent, data));
            }

            // If not an image and not a shortcut link, then must have been other link.

            // Parse span content for internal elements.
            var span = new EMSpanElements(doc, origin, parent);

            span.Parse(taggedMatch.ContentStart, taggedMatch.Content, data);

            // Check if ref link
            return(taggedMatch.Parameters.StartsWith("[")
                       ? EMLink.CreateFromAnchorRef(doc, origin, parent, data, span, taggedMatch.Parameters)
                       : EMLink.CreateFromInline(doc, origin, parent, data, span, taggedMatch.Parameters));
        }
コード例 #2
0
 protected void ParseElements(TransformationData data, List <TextFragment> fragments, IParser parser)
 {
     EMParsingHelper.ParseElements(data, Document, this, fragments, parser, Add);
 }