From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/13757 Path: news.gmane.org!not-for-mail From: BP Jonsson Newsgroups: gmane.text.pandoc Subject: Re: YAML closing delimiter Date: Mon, 19 Oct 2015 10:50:34 +0200 Message-ID: <5624AEDA.9050903@gmail.com> References: <20151013180944.GB6891@D25Q40BGFY13.Berkeley.EDU> <08e65baa-f8d6-4437-af61-d106b36d1382@googlegroups.com> <20151019051220.GA15885@protagoras.berkeley.edu> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed X-Trace: ger.gmane.org 1445244652 30143 80.91.229.3 (19 Oct 2015 08:50:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 19 Oct 2015 08:50:52 +0000 (UTC) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBXG5SKYQKGQE2CMN7OQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mon Oct 19 10:50:38 2015 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-lf0-f62.google.com ([209.85.215.62]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zo69N-00023A-Hn for gtp-pandoc-discuss@m.gmane.org; Mon, 19 Oct 2015 10:50:37 +0200 Original-Received: by lfaz124 with SMTP id z124sf26219256lfa.0 for ; Mon, 19 Oct 2015 01:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=sender:from:subject:to:references:message-id:date:user-agent :mime-version:in-reply-to:content-type:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=xJs249PvTgh+Sy/uCcDxFXSmsueB0sct7ItQMhMtD9Q=; b=nX2yrdYUcfeeeu7zzBWIt/lBPbNsi8PerXzAb7XB5TSitIxzRJpaed9eDvEnABGyuB cKH9KTcl14z5578jqDikWwqtBpwDlRRfRVUBDUOFpDMwIHYC03tqf9bUqUcqNdPfoXqi A8iFHreHYGuXdpcbdvEIxO2VP37DPQZKZdnvjaDOsASz+JQ8p9BAgwGIj1JoGhknS0KR flH+NxQfQ4CRUIilb7kdjDTFHwvUrwCC6BD7hTHmuiGpj4/q30xjMx4FKPp2Es/M0gWS to7FlvXwzhrVbvK34Mz4KxCX1wBsuJ7QpR9YfmhNWpDEw0ZYvWvz8cYJhEKswRJ9ZfyW 17fg== X-Received: by 10.180.211.35 with SMTP id mz3mr73911wic.6.1445244637186; Mon, 19 Oct 2015 01:50:37 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.180.89.102 with SMTP id bn6ls561401wib.43.canary; Mon, 19 Oct 2015 01:50:36 -0700 (PDT) X-Received: by 10.180.79.68 with SMTP id h4mr451159wix.6.1445244636412; Mon, 19 Oct 2015 01:50:36 -0700 (PDT) Original-Received: from mail-lb0-x229.google.com (mail-lb0-x229.google.com. [2a00:1450:4010:c04::229]) by gmr-mx.google.com with ESMTPS id os10si935780lbb.3.2015.10.19.01.50.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2015 01:50:36 -0700 (PDT) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4010:c04::229 as permitted sender) client-ip=2a00:1450:4010:c04::229; Original-Received: by mail-lb0-x229.google.com with SMTP id wb3so74482563lbb.1 for ; Mon, 19 Oct 2015 01:50:36 -0700 (PDT) X-Received: by 10.112.125.231 with SMTP id mt7mr13609885lbb.87.1445244636245; Mon, 19 Oct 2015 01:50:36 -0700 (PDT) Original-Received: from [192.168.1.253] ([178.249.150.249]) by smtp.gmail.com with ESMTPSA id gg8sm1008558lbc.17.2015.10.19.01.50.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2015 01:50:34 -0700 (PDT) Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: <20151019051220.GA15885-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org> X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4010:c04::229 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Spam-Checked-In-Group: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:13757 Archived-At: 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!