Exemplo n.º 1
0
 /// Creates an object that builds a [Widget] tree from parsed Markdown.
 public Builder(IMarkdownBuilderDelegate myDelegate, MarkdownStyleSheet styleSheet,
                string imgDir)
 {
     this.myDelegate     = myDelegate;
     this.styleSheet     = styleSheet;
     this.imageDirectory = imgDir;
 }
Exemplo n.º 2
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));
 }
Exemplo n.º 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);
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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');
            Document document = new Document();

            MarkdownBuilder.Builder builder = new MarkdownBuilder.Builder(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();
        }