示例#1
0
            public override bool VisitElementBefore(markdown.Element element)
            {
                string tag = element.tag;

                if (_isBlockTag(tag))
                {
                    //                    Debug.Log("tag---> " + tag);
                    _addAnonymousBLockIfNeeded(styleSheet.styles(tag));
                    if (_isListTag(tag))
                    {
                        _listIndents.Add(tag);
                    }

                    _blocks.Add(new _BlockElement(tag));
                }
                else
                {
                    _addParentInlineIfNeeded(_blocks.last().tag);
                    TextStyle parentStyle = _inlines.last().style;

                    _inlines.Add(new _InlineElement(tag, parentStyle.merge(styleSheet.styles(tag))));
                }

                if (tag == "a")
                {
                    _linkHandlers.Add(myDelegate.createLink(element.attributes["href"]));
                }

                return(true);
            }
示例#2
0
            public override void VisitElementAfter(markdown.Element element)
            {
                string tag = element.tag;

                if (_isBlockTag(tag))
                {
                    _addAnonymousBLockIfNeeded(styleSheet.styles(tag));

                    _BlockElement current = _blocks.removeLast();
                    Widget        child;

                    if (current.children.isNotEmpty())
                    {
                        child = new Column(null, null, null, MainAxisAlignment.start, MainAxisSize.max,
                                           CrossAxisAlignment.stretch, VerticalDirection.down, current.children);
                    }
                    else
                    {
                        child = new SizedBox();
                    }

                    if (_isListTag(tag))
                    {
                        Debug.Assert(_listIndents.isNotEmpty(), "_listIndents.isNotEmpty()");
                        _listIndents.removeLast();
                    }
                    else if (tag == "li")
                    {
                        if (_listIndents.isNotEmpty())
                        {
                            child = new Row(
                                null,
                                null,
                                null,
                                MainAxisAlignment.start,
                                MainAxisSize.max,
                                CrossAxisAlignment.start,
                                VerticalDirection.down,
                                new List <Widget>()
                            {
                                new SizedBox(null, styleSheet.listIndent, null, _buildBullet(_listIndents.last())),
                                new Expanded(null, 1, child)
                            });
                        }
                    }
                    else if (tag == "blockquote")
                    {
                        child = new DecoratedBox(
                            null,
                            styleSheet.blockquoteDecoration,
                            DecorationPosition.background,
                            new Padding(
                                null,
                                EdgeInsets.all(styleSheet.blockquotePadding),
                                child));
                    }
                    else if (tag == "pre")
                    {
                        child = new DecoratedBox(
                            null,
                            styleSheet.codeblockDecoration,
                            DecorationPosition.background,
                            new Padding(
                                null,
                                EdgeInsets.all(styleSheet.codeblockPadding),
                                child));
                    }
                    else if (tag == "hr")
                    {
                        child = new DecoratedBox(
                            null,
                            styleSheet.horizontalRuleDecoration,
                            DecorationPosition.background,
                            child);
                    }

                    _addBlockChild(child);
                }
                else
                {
                    _InlineElement current = _inlines.removeLast();
                    _InlineElement parent  = _inlines.last();

                    if (tag == "img")
                    {
                        current.children.Add(_buildImage(element.attributes["src"]));
                    }
                    else if (tag == "a")
                    {
                        _linkHandlers.removeLast();
                    }

                    if (current.children.isNotEmpty())
                    {
                        parent.children.AddRange(current.children);
                    }
                }
            }