From: BP Jonsson <bpj-J3H7GcXPSITLoDKTGw+V6w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: YAML closing delimiter
Date: Mon, 19 Oct 2015 10:50:34 +0200 [thread overview]
Message-ID: <5624AEDA.9050903@gmail.com> (raw)
In-Reply-To: <20151019051220.GA15885-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
Den 2015-10-19 kl. 07:12, skrev John MacFarlane:
> +++ BPJ [Oct 18 15 10:58 ]:
>> Try
>>
>> pandoc -t markdown [1]in.md | perl -ple's/^\.\.\.$/---/' >out.md
>
> This will probably work well enough in most cases, but what
> if your document has a line with `...` that isn't a YAML
> header closer? (E.g. in a fenced code block?) It will get
> converted to `---` too, won't it?
>
I thought the same right after I hit send. There is a trick which
will replace only the first match in the file, which is usually
what you want in this case:
pandoc -t markdown in.md | perl -ple'$seen ||=
s/^\.\.\.$/---/' >out.md
Here `$seen`, which is a global variable, will be set to a true
value the first time the substitution matches because the
substitution operator returns the number of substitutions made on
the current line, which in this case will be either 0 (false) or 1
(true). On subsequent lines, when `$seen` already has a true value
the substitution won't even be tried. It's faster too as it
doesn't need to try the regular expression against every line in
the file. (It needs to *print* every line though, which it does.)
/bpj
P.S. I don't know where the `[1]` came from. Probably a pasting
error!
next prev parent reply other threads:[~2015-10-19 8:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-13 16:11 John Muccigrosso
[not found] ` <ebb2d862-397d-4e25-9e7e-fb54323a81c2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-10-13 18:09 ` John MACFARLANE
[not found] ` <20151013180944.GB6891-4kKid1p5UN4xFjuZnxJpBp3lxR28IOakuDuwTybUTCk@public.gmane.org>
2015-10-13 20:54 ` John Muccigrosso
[not found] ` <08e65baa-f8d6-4437-af61-d106b36d1382-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-10-18 8:58 ` BPJ
[not found] ` <CADAJKhCt9EqV_v3XTrXq=oPFiOHnEsk5xEtB8wYiMKb3V0xDTw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-10-19 5:12 ` John MacFarlane
[not found] ` <20151019051220.GA15885-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
2015-10-19 8:50 ` BP Jonsson [this message]
[not found] ` <5624AEDA.9050903-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-10-21 4:04 ` John MacFarlane
2015-10-18 18:39 ` John Muccigrosso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5624AEDA.9050903@gmail.com \
--to=bpj-j3h7gcxpsitlodktgw+v6w@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).