Ejemplo n.º 1
0
        public void FormatHtmlTableTest()
        {
            string md = @"
        <table>
        <tbody>
        <tr>    <td>Column1</td>     <td style='text-align: right'>Column2</td>     <td>Column3</td> </tr>
        <tr>
            <td>Column1 Row 1</td><td>Column2 Row 1</td><td>Column3 Row 1</td>
        </tr>
        <tr>    <td>Column1 Row 2</td>
            <td>Column2 Row 2</td><td>Column3 Row 2</td>
        </tr>
        <tr>
            <td>Column1 Row 3</td>
            <td>Column2 Row 3</td>
            <td>Column3 Row 3</td>
        </tr></tbody></table></html>
        ";

            var parser = new TableParserHtml();
            var niceMd = parser.FormatMarkdownTable(md);

            Console.WriteLine(niceMd);
            Assert.IsTrue(niceMd.Contains("	<td>Column3 Row 3</td>"), "Pipe is not formatted as expected");
        }
Ejemplo n.º 2
0
        public void FormatPipeTableTest()
        {
            string md = @"
        | Header1 | Header 2   | Header 3    |
        |--------------------------------------------|
        | column 1 | Column 2 | Column 3 |
        | Custom Table Content | Column 5 | Column 6 |
        | Column 7  | Column 8 | Column 9 |
        ";

            var parser = new TableParserHtml();
            var niceMd = parser.FormatMarkdownTable(md);

            Console.WriteLine(niceMd);
            Assert.IsTrue(niceMd.Contains("| Column 7             |"), "Pipe is not formatted as expected");
        }
Ejemplo n.º 3
0
        public void FormatGridTableTest()
        {
            string md     = @"
        +------------------------+----------------+------------+
        | Header 1 | Header 2       | Header 3   |
        +==========================================+================+============+
        | Column 1  | Column 2 Text  | Column 3   |
        +------------------------------------------+----------------+------------+
        | Column 4                     | Column 5 Text  | Column 5.5 |
        | and a bottle of Russian rum              |                |            |
        | with broken glass   |                |            |
        +------------------------------------------+----------------+------------+
        | Column 6                      | Column 7 Text  | Column 8   |
        +------------------------------------------+----------------+------------+
        | Column 9      | Column 10 Text | Column 11  |
        | ho ho and a bottle of rum                |                |            |
        +------------------------------------------+----------------+------------+
        ";
            var    parser = new TableParserHtml();
            var    niceMd = parser.FormatMarkdownTable(md);

            Console.WriteLine(niceMd);
            Assert.IsTrue(niceMd.Contains("| Column 1                    |"), "Grid is not formatted as expected");
        }
        private bool CheckForTable(string line, AcePosition pos)
        {
            if (string.IsNullOrEmpty(line))
            {
                return(false);
            }

            line = line.Trim();

            if (line.Contains("|") ||
                line.StartsWith("+-") ||
                line.StartsWith("+="))
            {
                var mi = new MenuItem
                {
                    Header = "Edit Table"
                };
                mi.Click += (o, args) =>
                {
                    var tableMarkdown = SelectPipeAndGridTableMarkdown();
                    Model.ActiveEditor.EditorSelectionOperation("table", tableMarkdown);
                };
                ContextMenu.Items.Add(mi);

                mi = new MenuItem
                {
                    Header = "Format Table"
                };
                mi.Click += (o, args) =>
                {
                    string mdTableHtml = SelectPipeAndGridTableMarkdown();
                    if (string.IsNullOrEmpty(mdTableHtml))
                    {
                        return;
                    }

                    var parser    = new TableParserHtml();
                    var formatted = parser.FormatMarkdownTable(mdTableHtml);
                    if (formatted == null)
                    {
                        return;
                    }

                    Model.ActiveEditor.SetSelectionAndFocus(formatted);
                    Model.ActiveEditor.PreviewMarkdownCallback();
                };
                ContextMenu.Items.Add(mi);

                return(true);
            }
            else if (line.StartsWith("<td", StringComparison.InvariantCultureIgnoreCase) ||
                     line.StartsWith("<tr", StringComparison.InvariantCultureIgnoreCase) ||
                     line.StartsWith("<th", StringComparison.InvariantCultureIgnoreCase) ||
                     line.StartsWith("<table>", StringComparison.InvariantCultureIgnoreCase) ||
                     line.StartsWith("<table ", StringComparison.InvariantCultureIgnoreCase) ||
                     line.Equals("<thead>", StringComparison.InvariantCultureIgnoreCase) ||
                     line.Equals("<tbody>", StringComparison.InvariantCultureIgnoreCase))
            {
                StringBuilder sbTableMarkdown = new StringBuilder();

                var mi = new MenuItem
                {
                    Header = "Edit Table"
                };
                mi.Click += (o, args) =>
                {
                    string mdTableHtml = SelectHtmlTableMarkdown();
                    if (string.IsNullOrEmpty(mdTableHtml))
                    {
                        return;
                    }

                    Model.ActiveEditor.EditorSelectionOperation("table", mdTableHtml);
                };
                ContextMenu.Items.Add(mi);
                mi = new MenuItem
                {
                    Header = "Format Table"
                };
                mi.Click += (o, args) =>
                {
                    string mdTableHtml = SelectHtmlTableMarkdown();
                    if (string.IsNullOrEmpty(mdTableHtml))
                    {
                        return;
                    }

                    var parser    = new TableParserHtml();
                    var formatted = parser.FormatMarkdownTable(mdTableHtml);
                    if (formatted == null)
                    {
                        return;
                    }

                    Model.ActiveEditor.SetSelectionAndFocus(formatted);
                    Model.ActiveEditor.PreviewMarkdownCallback();
                };

                ContextMenu.Items.Add(mi);
                return(true);
            }

            return(false);
        }