Re: Markdown format output for psql, design notes

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Daniel Verite <daniel(at)manitou-mail(dot)org>
Cc: Lætitia Avrot <laetitia(dot)avrot(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Markdown format output for psql, design notes
Date: 2018-12-02 04:10:54
Message-ID: CAFj8pRBtysSixj0r1L4KErPV8VufPu7VE1_+Cp+cMUg9ra6P-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

so 1. 12. 2018 v 22:11 odesílatel Daniel Verite <daniel(at)manitou-mail(dot)org>
napsal:

> Lætitia Avrot wrote:
>
> > But as Vik said earlier, maybe it's not worth it to provide a markdown
> > output as pandoc can generate the markdown from the HTML output.
> > And if you need the markdown output to generate HTML why don't you use
> the
> > HTML output ?
>
> The round-trip through pandoc does not do any miracle.
> The end result is readable to the human eye but structurally
> broken. If converted back to html, it's no longer a table.
>
> Anyway I tend to agree with Vik on this:
> "Markdown isn't standardized enough to support and please everyone."
>
> BTW github has independently started to support '|' in the cells
> by accepting the quoted version '\|' :
> https://help.github.com/articles/organizing-information-with-tables/
>
> Now that we have csv as an output format, we can suggest
> custom csv-to-markdown converters to produce markdown
> rather than implementing one particular flavor of markdown
> in psql, or several flavors through flags. The popular script
> languages have solid CSV parsers that make this relatively easy
> and safe.
>

I agree with you about importance of CSV. On second hand, I don't see a
reason why we should not to support some very popular markdown formats -
although there can be a discussion - which

maybe github and JIRA, CONFLUENCE

Regards

Pavel

> Personally I'd use Perl with something like below, which looks
> short/simple enough to be shared on wiki.postgresql.org,
> along with versions in other languages.
>
> #!/usr/bin/perl
>
> # Usage
> # inside psql:
> # \pset format csv
> # \o |csvtomarkdown >/tmp/output.md
> # SQL commands...
> # \o
>
> # or psql --csv -c "...query..." | csvtomarkdown
>
> use Text::CSV;
> use open qw( :std :encoding(UTF-8) );
>
> my $csv = Text::CSV->new({ binary => 1, eol => $/ });
>
> sub do_format {
> # customize to your needs
> s/&/&amp;/g;
> s/</&lt;/g;
> s/>/&gt;/g;
> s/\n/<br>/g;
> s/\|/&#x7C;/g;
> return $_;
> }
>
> my $header = $csv->getline(STDIN);
> for (@{$header}) {
> $_ = do_format($_);
> }
> print join ('|', @{$header}), "\n";
> print join ('|', map { "---" } @{$header}), "\n";
>
> while (my $row = $csv->getline(STDIN)) {
> my @contents = map { do_format($_) } @{$row};
> print join('|', @contents), "\n";
> }
>
>
> Best regards,
> --
> Daniel Vérité
> PostgreSQL-powered mailer: http://www.manitou-mail.org
> Twitter: @DanielVerite
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Gierth 2018-12-02 06:08:22 Re: AllocSetContextCreate changes breake extensions
Previous Message Pavel Stehule 2018-12-02 03:59:05 Re: proposal: less strict input of regprocedure type