Ejemplo n.º 1
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()));
        }
Ejemplo n.º 2
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();
        }