Current state is something like this (diff is attached). I currently haven`t regression test, tab completion etc., I will add this thing following structure of asciidoc commit.
Output is tested using retext, rst is OK, md have problem with cells with newline (i must find out, how it is possible create table with this in markdown). [jelen@laptak patch_postgre_rst]$ [jelen@laptak psql]$ ./psql psql (9.6.2, server 9.6.1) Type "help" for help. jelen=# \pset linestyle markdown Line style is markdown. jelen=# values(E'nasral Franta\nna trabanta','Žluťoučký kobyly'), ('''',E'a\tb') \g | xclip jelen=# values(E'nasral Franta\nna trabanta','Žluťoučký kobyly'), ('''',E'a\tb') \g | column1 | column2 | |---------------|------------------| | nasral Franta | Žluťoučký kobyly | | na trabanta | | | ' | a b | (2 rows) jelen=# \pset linestyle rst Line style is rst. jelen=# values(E'nasral Franta\nna trabanta','Žluťoučký kobyly'), ('''',E'a\tb') \g +---------------+------------------+ | column1 | column2 | +===============+==================+ | nasral Franta+| Žluťoučký kobyly | | na trabanta | | +---------------+------------------+ | ' | a b | +---------------+------------------+ (2 rows) jelen=# 2017-02-24 0:46 GMT+01:00 Michael Paquier <michael.paqu...@gmail.com>: > On Fri, Feb 24, 2017 at 3:09 AM, Jan Michálek <godzilalal...@gmail.com> > wrote: > > I can try it, doesn`t look dificult, but I`m worry, that I`m not able to > > write clean, pretty code. > > If you want to have something available in Postgres 10, you had better > be quick. The last commit fest of the development cycle of Postgres 10 > begins on the 1st of March, you need to to register your patch here: > https://commitfest.postgresql.org/13/ > Here are also some rough guidelines about submitting a patch: > https://wiki.postgresql.org/wiki/Submitting_a_Patch > -- > Michael > -- Jelen Starší čeledín datovýho chlíva
diff -ru a/src/bin/psql/command.c b/src/bin/psql/command.c --- a/src/bin/psql/command.c 2017-02-06 22:45:25.000000000 +0100 +++ b/src/bin/psql/command.c 2017-02-28 01:07:26.000000000 +0100 @@ -2584,9 +2584,17 @@ popt->topt.line_style = &pg_asciiformat_old; else if (pg_strncasecmp("unicode", value, vallen) == 0) popt->topt.line_style = &pg_utf8format; + /* format markdown + */ + else if (pg_strncasecmp("markdown", value, vallen) == 0) + popt->topt.line_style = &pg_markdown; + /* format rst + */ + else if (pg_strncasecmp("rst", value, vallen) == 0) + popt->topt.line_style = &pg_rst; else { - psql_error("\\pset: allowed line styles are ascii, old-ascii, unicode\n"); + psql_error("\\pset: allowed line styles are ascii, old-ascii, unicode, markdown\n"); return false; } diff -ru a/src/fe_utils/print.c b/src/fe_utils/print.c --- a/src/fe_utils/print.c 2017-02-06 22:45:25.000000000 +0100 +++ b/src/fe_utils/print.c 2017-02-28 13:34:11.000000000 +0100 @@ -57,6 +57,48 @@ static printTableFooter default_footer_cell = {default_footer, NULL}; /* Line style control structures */ +const printTextFormat pg_markdown = +{ + "markdown", + { + {"", "", "", ""}, + {"-", "|", "|", "|"}, + {"", "", "", ""}, + {"", "|", "|", "|"} + }, + "|", + "|", + "|", + " ", + "+", + " ", + " ", + ".", + ".", + true +}; + +const printTextFormat pg_rst = +{ + "rst", + { + {"-", "+", "+", "+"}, + {"=", "+", "+", "+"}, + {"-", "+", "+", "+"}, + {"", "|", "|", "|"} + }, + "|", + "|", + "|", + " ", + "+", + " ", + "+", + ".", + ".", + true +}; + const printTextFormat pg_asciiformat = { "ascii", @@ -623,6 +665,12 @@ if (opt_border > 2) opt_border = 2; + if (format == &pg_markdown) + opt_border = 2; + + if (format == &pg_rst) + opt_border = 2; + if (cont->ncolumns > 0) { col_count = cont->ncolumns; @@ -1124,13 +1172,20 @@ fputc('\n', fout); } while (more_lines); + + /* add line after every record */ + if (opt_border == 2 && format == &pg_rst) + _print_horizontal_line(col_count, width_wrap, opt_border, + PRINT_RULE_BOTTOM, format, fout); } if (cont->opt->stop_table) { printTableFooter *footers = footers_with_default(cont); - if (opt_border == 2 && !cancel_pressed) + /* dont add line after last row, because line is added after every row + **/ + if ((opt_border == 2 && format != &pg_rst) && !cancel_pressed) _print_horizontal_line(col_count, width_wrap, opt_border, PRINT_RULE_BOTTOM, format, fout); @@ -1138,6 +1193,9 @@ if (footers && !opt_tuples_only && !cancel_pressed) { printTableFooter *f; + /*add newline after table because rst needs empty line after table + */ + fprintf(fout, "\n"); for (f = footers; f; f = f->next) fprintf(fout, "%s\n", f->data); diff -ru a/src/include/fe_utils/print.h b/src/include/fe_utils/print.h --- a/src/include/fe_utils/print.h 2017-02-06 22:45:25.000000000 +0100 +++ b/src/include/fe_utils/print.h 2017-02-28 01:04:05.000000000 +0100 @@ -176,6 +176,8 @@ extern volatile bool cancel_pressed; extern const printTextFormat pg_asciiformat; +extern const printTextFormat pg_markdown; /*format pro markdown*/ +extern const printTextFormat pg_rst; /*format pro rst*/ extern const printTextFormat pg_asciiformat_old; extern printTextFormat pg_utf8format; /* ideally would be const, but... */
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers