Example #1
0
 protected MarkdownWidget(
     Key key,
     string data,
     MarkdownStyleSheet markdownStyleSheet,
     SyntaxHighlighter syntaxHighlighter1,
     MarkdownTapLinkCallback onTapLink,
     string imageDirectory,
     ExtensionSet extensionSet,
     MarkdownImageBuilder imageBuilder,
     MarkdownCheckboxBuilder checkboxBuilder,
     bool fitContent = false,
     bool selectable = false
     ) : base(key)
 {
     Debug.Assert(data != null);
     this.data              = data;
     this.styleSheet        = markdownStyleSheet;
     this.syntaxHighlighter = syntaxHighlighter1;
     this.onTapLink         = onTapLink;
     this.extensionSet      = extensionSet;
     this.imageDirectory    = imageDirectory;
     this.imageBuilder      = imageBuilder;
     this.checkboxBuilder   = checkboxBuilder;
     this.fitContent        = fitContent;
     this.selectable        = selectable;
 }
Example #2
0
        void _parseMarkdown()
        {
            MarkdownStyleSheet styleSheet =
                this.widget.styleSheet ?? MarkdownStyleSheet.fromTheme(Theme.of(this.context));

            this._disposeRecognizers();
            var lines    = Regex.Split(this.widget.data, "\r?\n");
            var document = new Document(
                extensionSet: this.widget.extensionSet ?? ExtensionSet.githubFlavored,
                inlineSyntaxes: new List <InlineSyntax> {
                new TaskListSyntax()
            },
                encodeHtml: false
                );
            var builder = new MarkdownBuilder(
                dele: this,
                selectable: this.widget.selectable,
                styleSheet: styleSheet, // todo merge fallback style sheet
                imageDirectory: this.widget.imageDirectory,
                imageBuilder: this.widget.imageBuilder,
                checkboxBuilder: this.widget.checkboxBuilder,
                fitContent: this.widget.fitContent
                );

            this._children = builder.build(document.parseLines(lines.ToList()));
        }
Example #3
0
 /// Creates a scrolling widget that parses and displays Markdown.
 public Markdown(Key key     = null,
                 String data = null,
                 MarkdownStyleSheet styleSheet       = null,
                 SyntaxHighlighter syntaxHighlighter = null,
                 MarkdownTapLinkCallback onTapLink   = null,
                 string imageDirectory = null) : base(key, data, styleSheet, syntaxHighlighter, onTapLink, imageDirectory)
 {
     this.padding = EdgeInsets.all(16);
 }
Example #4
0
 public TextSpan formatText(MarkdownStyleSheet styleSheet, string code)
 {
     //TODO: format code!
     if (widget.syntaxHighlighter != null)
     {
         return(widget.syntaxHighlighter.format(code));
     }
     return(new TextSpan(code, styleSheet.code));
 }
Example #5
0
 /// Creates a widget that parses and displays Markdown.
 ///
 /// The [data] argument must not be null.
 protected MarkdownWidget(Key key, string data, MarkdownStyleSheet markdownStyleSheet,
                          SyntaxHighlighter syntaxHighlighter1, MarkdownTapLinkCallback onTapLink, string imageDirectory) : base(key)
 {
     Debug.Assert(data != null, "data != null");
     this.data              = data;
     this.styleSheet        = markdownStyleSheet;
     this.syntaxHighlighter = syntaxHighlighter1;
     this.onTapLink         = onTapLink;
     this.imageDirectory    = imageDirectory;
 }
Example #6
0
 public MarkdownBuilder(
     IMarkdownBuilderDelegate dele,
     bool selectable,
     MarkdownStyleSheet styleSheet,
     string imageDirectory,
     MarkdownImageBuilder imageBuilder,
     MarkdownCheckboxBuilder checkboxBuilder,
     bool fitContent = false
     )
 {
     this.builderDelegate = dele;
     this.selectable      = selectable;
     this.styleSheet      = styleSheet;
     this.imageDirectory  = imageDirectory;
     this.imageBuilder    = imageBuilder;
     this.checkboxBuilder = checkboxBuilder;
     this.fitContent      = fitContent;
 }
 public CustomMarkdown(
     Key key         = null,
     string data     = null,
     bool selectable = false,
     MarkdownStyleSheet markdownStyleSheet = null,
     SyntaxHighlighter syntaxHighlighter   = null,
     MarkdownTapLinkCallback onTapLink     = null,
     string imageDirectory                   = null,
     ExtensionSet extensionSet               = null,
     MarkdownImageBuilder imageBuilder       = null,
     MarkdownCheckboxBuilder checkboxBuilder = null,
     ScrollPhysics physics                   = null,
     bool shrinkWrap                     = false,
     Widget contentHead                  = null,
     Widget relatedArticles              = null,
     List <Widget> commentList           = null,
     RefreshController refreshController = null,
     bool enablePullDown                 = false,
     bool enablePullUp                   = false,
     OnRefresh onRefresh                 = null,
     NotificationListenerCallback <ScrollNotification> onNotification = null,
     float initialOffset = 0f,
     bool needRebuildWithCachedCommentPosition = false,
     bool isArticleJumpToCommentStateActive    = false
     ) : base(key, data, markdownStyleSheet, syntaxHighlighter,
              onTapLink, imageDirectory, extensionSet, imageBuilder, checkboxBuilder, selectable)
 {
     this.padding           = EdgeInsets.all(16);
     this.physics           = physics;
     this.shrinkWrap        = shrinkWrap;
     this.contentHead       = contentHead;
     this.relatedArticles   = relatedArticles;
     this.commentList       = commentList;
     this.refreshController = refreshController;
     this.enablePullDown    = enablePullDown;
     this.enablePullUp      = enablePullUp;
     this.onRefresh         = onRefresh;
     this.onNotification    = onNotification;
     this.initialOffset     = initialOffset;
     this.needRebuildWithCachedCommentPosition = needRebuildWithCachedCommentPosition;
     this.isArticleJumpToCommentStateActive    = isArticleJumpToCommentStateActive;
 }
Example #8
0
 public Markdown(
     Key key         = null,
     string data     = null,
     bool selectable = false,
     MarkdownStyleSheet markdownStyleSheet = null,
     SyntaxHighlighter syntaxHighlighter   = null,
     MarkdownTapLinkCallback onTapLink     = null,
     string imageDirectory                   = null,
     ExtensionSet extensionSet               = null,
     MarkdownImageBuilder imageBuilder       = null,
     MarkdownCheckboxBuilder checkboxBuilder = null,
     ScrollPhysics physics                   = null,
     bool shrinkWrap = false
     ) : base(key, data, markdownStyleSheet, syntaxHighlighter,
              onTapLink, imageDirectory, extensionSet, imageBuilder, checkboxBuilder, selectable)
 {
     this.padding    = EdgeInsets.all(16);
     this.physics    = physics;
     this.shrinkWrap = shrinkWrap;
 }
Example #9
0
        void _parseMarkdown()
        {
            updateState(new List <Widget>());
            MarkdownStyleSheet styleSheet = widget.styleSheet ?? MarkdownStyleSheet.fromTheme(new ThemeData(brightness: Brightness.light, fontFamily: "Avenir"));

            _disposeRecongnizer();

            // TODO: This can be optimized by doing the split and removing \r at the same time
            string[]                lines    = widget.data.Replace("\r\n", "\n").Split('\n');
            markdown.Document       document = new Document();
            builder.MarkdownBuilder builder  = new builder.MarkdownBuilder(this, styleSheet, widget.imageDirectory);

            List <Node> nodes = null;

//            if (widget.getCachedParsed != null)
//            {
//                nodes = widget.getCachedParsed(widget.id);
//            }


//            _children = builder.build(document.parseLines(lines.ToList().remove(string.IsNullOrEmpty)));

            if (buildThread != null && buildThread.ThreadState == ThreadState.Running)
            {
                buildThread.Abort();
            }

            buildThread = new Thread(() =>
            {
                try
                {
                    Stopwatch sw = Stopwatch.StartNew();
                    if (nodes == null)
                    {
                        nodes = document.parseLines(lines.ToList());
                    }


                    if (widget.onParsed != null)
                    {
                        widget.onParsed(widget.id, nodes);
                    }


                    var elements = builder.build(nodes);

                    Dispatcher.Invoke(() =>
                    {
                        updateState(elements);
                    });


                    sw.Stop();
                    Debug.Log(sw.ElapsedMilliseconds / 1000f);
                }
                catch (ThreadAbortException e)
                {
                    Debug.Log(e.Message);
                }
            });


            buildThread.Start();
        }