From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/18003 Path: news.gmane.org!.POSTED!not-for-mail From: John MacFarlane Newsgroups: gmane.text.pandoc Subject: Re: Pandoc support for implicit fenced code blocks in source files Date: Fri, 4 Aug 2017 08:03:52 -0700 Message-ID: <20170804150352.GC74082@Johns-MacBook-Pro.local> References: <36c4d1d4-2d9d-4919-97ab-0eaf588b22a3@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8"; format=flowed X-Trace: blaine.gmane.org 1501859046 13677 195.159.176.226 (4 Aug 2017 15:04:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 4 Aug 2017 15:04:06 +0000 (UTC) User-Agent: Mutt/1.6.2 (2016-07-01) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCJZJHG45QDBBZMZSLGAKGQENX5ZRPY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Aug 04 17:04:00 2017 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-vk0-f59.google.com ([209.85.213.59]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dde8t-0003Bc-SL for gtp-pandoc-discuss@m.gmane.org; Fri, 04 Aug 2017 17:04:00 +0200 Original-Received: by mail-vk0-f59.google.com with SMTP id g189sf1052318vke.2 for ; Fri, 04 Aug 2017 08:04:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1501859046; cv=pass; d=google.com; s=arc-20160816; b=j9ORiGh0duIxG0Sp492qu3r7KJDEMggfwpz0lvkal1APTDlgWIHtmHBqa4YTJ1gIsT K9uwKl4AIwdy54ehAexXj9EBBypzzc03WGZ75bZvb7nfdUL+G3FfeqVn/aH6HWBL0F/s EPZzEsz1gqr+3ZGYynXItWX4ez3gApEzUqeqoQrT11k5SGKnZQ3Z/hEzDna/VWHSpJsz +lpgvWKP4XZSdHiG+mI6ntab9NcM4TdGCb+Zs1FgRK/uAnCueUv8GD3dj+fv8zovbwoM xIi/p1BE7apHsQD0v3qgP+leHkjqMCGucDIxYSa5oMdSPCh2BZUUYk9pAC8fpkw+HiMF TiKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :date:from:arc-authentication-results:arc-message-signature:sender :dkim-signature:arc-authentication-results; bh=eNizuIDigVOzxMyknAza+ZJFf7ITfs/vEMtje6gWwac=; b=pDIM2cvu4lFk9nksBYMUh3/CWiQKR1nF+eRabXKy+ijO56l3yE5rd8NA0NaW8jkvvF BHKoYsYACzneZj5ICZAMFQVO2uRtn9ffuhA0bBvJJw0fyOU8VAkaMCYkspaOWDcBNh0N 3kxz7ogtMAgZUDxmgU5SKILGwpjZ9NiHxMs9Dv3IqTYp/mn9C3juRsfeaMQFMNET6byh Z/mTEjFUgEYFVmPe7jkRTqqUUcYytYSA0zTJZXzucsH5sem5liSvajugSluiikVi0dxf 9aY9zNY3ashTfRrbws8RJjXIJuPvgRC5qPlT9G4OYApb1D35hK9M7nVqssuqcB1CP6LQ ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@berkeley-edu.20150623.gappssmtp.com header.b=XibEE3zw; spf=pass (google.com: domain of jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org designates 2607:f8b0:400e:c05::241 as permitted sender) smtp.mailfrom=jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:date:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=eNizuIDigVOzxMyknAza+ZJFf7ITfs/vEMtje6gWwac=; b=eKMwMd1ea7iJ3SAT4f9BhI1e6S0n9jmLYxh1ProXNThzH6liDTOOcXl8rfpt7iEmwX I6xrGdLbudqTlNtRVTWWNPPJk0//th7QBfciKydeKQGgBaf/jouhnEKccw/gEvqpguh3 83OC8Clzbz0cuhEV02cXQ3d5VD1KLNW10ugg8SNwN+NBQmhjoWtB4aooc9jJ2VrHy8sq fhouSNIzdf8IUBYBaFHo6fJkHPz99duzVSEuBrQLqDCFcWGKCVmUtLQBfaqhk43N8H8V BwyCk+4k2g+EhN183ToVrNZln1PFSAAEc7O0ilwa+Adn6iKmdGfhm2uL8paXsLywR7LB OkLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:date:to:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent :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=eNizuIDigVOzxMyknAza+ZJFf7ITfs/vEMtje6gWwac=; b=RFTkVjJIxObVRhQwh3xaZHgPTNSALl/6odKB0mvTPyjt//cb2/ehytMyaX7r8iLZOI YvVM9sSqQwQmDqh2Le9quqP6r51AyVjf3C4MSNTQrALSLGr5Wm2zJ+yhJwX5HrgtPszG lXDCsmsIrR8iTI17SDjRQiQgxVFfCidrAsc908x08T+8WDrJutnZf0pFoFxo8kpSknBK soK53/xrQzrftRo3h79+9bnGkpNlDXge5VPHUL1J0pzWKk6cUjeoKSmYbvXopO1eeIBN dY9Vo+UCjPYPdQZtWsu146XkEHNJqltZCasXcslwMSk8yqaF0DK2cdWfcSVa6VzeVEpa Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AHYfb5jvbGs4AkSVDVwj/98B+ZNQ4iLb6FQKEZBHK9lfwgKv6VIE6oNr cfk9fueqE6CjhQ== X-Received: by 10.36.93.142 with SMTP id w136mr81861ita.10.1501859045990; Fri, 04 Aug 2017 08:04:05 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.107.58.197 with SMTP id h188ls3465627ioa.44.gmail; Fri, 04 Aug 2017 08:04:05 -0700 (PDT) X-Received: by 10.129.232.8 with SMTP id a8mr1522398ywm.97.1501859045124; Fri, 04 Aug 2017 08:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501859045; cv=none; d=google.com; s=arc-20160816; b=f1F4IIGxQzSJLor3U2hw3+aiUSupEkg+zBgC8Y7Z5J4hBuigyEDUghej6r0ysqLSgm sIQOZOSSpenG8lOgtf1lxpqKWYhVl/nd7YuQvivvPKT7CwXTHVMu2yHLrw6qZrIPuuBu 6nQVrzIjgCQC7h61CH5vier8lKXJ931ULVpEdExgzUX/wkj8TMZWCDHMU860p/2ylNXX zyikSUuJKMf67J78PuZU3LyZFH3JalM+rmEgBZBiA7Dy4gp686PZMmckkfWXDQMNEo6s W0KyJSR40aUcm+keS7nKbcBj+8QJUtwNGDB2SlAOnUroWWNF7IkIanmeNkCPBF3z76cF Ef3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:to:date:from:dkim-signature :arc-authentication-results; bh=63elUnwS51Eir90O6LZ1ksctJ1+Vb/AJ+3+mX39DcNA=; b=MNyttFF54dorVnoBBTiYASJfajqIMp2DtZuweqmVBr/wqC1J39tL07o18f4KUhj2II 463TGtFOC/stpSb/KZvXqiNkzBMLt2CadQvaEt5juIo8rD0pqW4PuTNxdrt5N0Xloepq RBsi+BjZ3S6kfloQbswip+wjIQJkSJ5MMSJliokXfuxpngnmJZ3XqlgKTJLdyHCnG3Nk t7cR0cMn/dCJsjC2JyhRskd3aFUHmJ+mT1YUgbwyI2xUpN/GRLRKma7Bq9gi2fj4eemr 1TKxQ+/HDiU/U1Vd2TkkfPZ7IyYD5tsQnwAJH29hdtxEu5DODuBQNIOM7Pq9VCAVfsJ6 RKvg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@berkeley-edu.20150623.gappssmtp.com header.b=XibEE3zw; spf=pass (google.com: domain of jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org designates 2607:f8b0:400e:c05::241 as permitted sender) smtp.mailfrom=jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org Original-Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com. [2607:f8b0:400e:c05::241]) by gmr-mx.google.com with ESMTPS id c4si367232pfe.15.2017.08.04.08.04.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Aug 2017 08:04:05 -0700 (PDT) Received-SPF: pass (google.com: domain of jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org designates 2607:f8b0:400e:c05::241 as permitted sender) client-ip=2607:f8b0:400e:c05::241; Original-Received: by mail-pg0-x241.google.com with SMTP id y192so2057429pgd.1 for ; Fri, 04 Aug 2017 08:04:05 -0700 (PDT) X-Received: by 10.84.217.216 with SMTP id d24mr3235155plj.144.1501859044540; Fri, 04 Aug 2017 08:04:04 -0700 (PDT) Original-Received: from johnmacfarlane.net (li55-134.members.linode.com. [74.82.3.134]) by smtp.gmail.com with ESMTPSA id c25sm5150150pfj.85.2017.08.04.08.04.03 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2017 08:04:03 -0700 (PDT) Original-Received: by johnmacfarlane.net (Postfix, from userid 1000) id 05EEDA1C5; Fri, 4 Aug 2017 11:03:53 -0400 (EDT) Content-Disposition: inline In-Reply-To: <36c4d1d4-2d9d-4919-97ab-0eaf588b22a3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-PGP-Key: http://johnmacfarlane.net/jgm.asc X-Original-Sender: jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@berkeley-edu.20150623.gappssmtp.com header.b=XibEE3zw; spf=pass (google.com: domain of jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org designates 2607:f8b0:400e:c05::241 as permitted sender) smtp.mailfrom=jgm-TVLZxgkOlNX2fBVCVOL8/A@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-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:18003 Archived-At: I'd say the obvious thing to do is to create a program preprocesses the C source file, converting it into a Markdown document that you can pipe through pandoc. Or write a standalone tool in Haskell, using pandoc as a library. (And language-c to parse the source code.) +++ Sam Liddicott [Aug 04 17 07:43 ]: > I use pandoc in my C source files. > C comments contain pandoc markup, or perhaps special C comments like > this /*:pandoc > and the pandoc ends when the C comment ends. > Combined with goat (to convert ascii diagrams to SVG) this is a great > way to document code. > The difficulty in doing this now is convincing pandoc that code outside > of comments is a fenced code block, and that the start end end comment > markers shouldn't be rendered. > For instance: > ---8<------8<------8<------8<------8<------8<------8<--- > /** > It's a shame that pandoc renders the leading /* > and now here is some code but it the comment markers sadly render: > ~~~C > */ > int x() { > blag(); > }; /* > ~~~ > etc. > */ > ---8<------8<------8<------8<------8<------8<------8<--- > This feature can't be implemented using the filters, because if pandoc > treats the C source as pandoc markup, the start-comment might be > halfway through an AST node that never should be there. > I think that it needs parser support; but it isn't a new input format > either, as other variants of markdown might be used internally. > Ideally, this requires a new parsing mode to assume a fenced-code-block > interspersed with other pandoc markup. > i think the method is: > based on the file extension or a runtime argument, set the default > fenced code block type, and the comment start and end sequences. > 1. If, (after skipping initial white space), the first text is not a > comment-start-sequence, then the fence-code block is assumed before the > white space, and all the input is inserted into that fenced code block > in the AST until end-of-file or a comment-start-sequence. > 2. At a comment-start-sequence, the sequence is thrown away and the > parse acts as if a fenced-code-block-end was read. > 3. Parsing continues as normal until a comment-end-sequence is read. > This sequence is thrown away and the parser repeats from 1. > Now maybe the start-comment-sequence is always followed by a magic > header like :pandoc and maybe by further attributes which ought to be > applies to the previous fenced code block, and maybe the > end-comment-sequence could have attributes to apply to the upcoming > fenced-code-block. Maybe as a way to say: skip this code block until > you next see a pandoc comment, don't even bother to emit it. Not all > code wants to be part of the documentation, after all. > Maybe this would be better suited to an awk script to run manually and > not be part of pandoc at all. I'm using this sed, which does the job > somewhat. > sed -e '1!s/^\/\* */~~~\n\n/;/\/\*/!s/\*\/$/\n\n~~~C/' | pandoc --toc > -s -S -o doc.html > What are others thoughts on this? > Sam > > -- > You received this message because you are subscribed to the Google > Groups "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to > [2]pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > [3]https://groups.google.com/d/msgid/pandoc-discuss/36c4d1d4-2d9d-4919- > 97ab-0eaf588b22a3%40googlegroups.com. > For more options, visit [4]https://groups.google.com/d/optout. > >References > > 1. mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > 2. mailto:pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > 3. https://groups.google.com/d/msgid/pandoc-discuss/36c4d1d4-2d9d-4919-97ab-0eaf588b22a3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org?utm_medium=email&utm_source=footer > 4. https://groups.google.com/d/optout