public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* markdown to markdown, stripping Yaml comments and keeping 3-backticks code blocks intact
@ 2023-08-26 19:57 bapt a
       [not found] ` <9abf1645-7bd2-427c-846e-1b2e7a438760n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: bapt a @ 2023-08-26 19:57 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2160 bytes --]

Hi,

I'm playing with an idea for quarto, where one could comment out portions 
of the input document including text and code chunks. This workaround would 
make use of the trick that 1) Yaml blocks can appear anywhere in a pandoc 
document, and 2) commented out (#) lines in Yaml are stripped by pandoc (?).

I'd like to run a pre-processing step* on the input document to return 
essentially the same input, but getting rid off those commented out Yaml 
lines.

Consider the following input file,

``````
---
title: Comment
---

## Section

This is a simple placeholder for the manuscript's main document [@knuth84].


```{r}
x <- 1 + 1
x
```

Note pi is `r pi`.

---
#  You can embed code like this:
# 
# ```{r}
# 1 + 1
# ```
# but beware, is `r .NotYetImplemented()` still executed?
---

More text.

``````
The commented out portion should be removed before quarto calls the 
computational engine, otherwise the code still gets executed.

I've tried various flavours of markdown, such as

> quarto pandoc -t noop.lua  -f markdown  index.qmd

where noop.lua is a dummy Writer doing nothing,

```
function Writer (doc, opts)
  local filter = {  }
  return pandoc.write(doc:walk(filter), 'markdown', opts)
end
````

but I'm not finding the right combination of options, if there is one. Some 
markdown flavours seem to keep the Yaml comments (not sure why), others 
reformat the 3-backticks code block. Is this "identity" Writer going to be 
difficult to achieve?

Many thanks,

baptiste

* Note that code is currently detected via regex in quarto, so it gets 
executed even inside comments (hence the need of a pre-processor to strip 
it entirely from the document).
See https://github.com/quarto-dev/quarto-cli/discussions/3330 for more 
context

-- 
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 pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/9abf1645-7bd2-427c-846e-1b2e7a438760n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 3006 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: markdown to markdown, stripping Yaml comments and keeping 3-backticks code blocks intact
       [not found] ` <9abf1645-7bd2-427c-846e-1b2e7a438760n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-08-29 13:40   ` Jonathan Whiteley
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Whiteley @ 2023-08-29 13:40 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3088 bytes --]

I would love a way to "comment out" blocks of Markdown.  The only way I've 
been able to do it in R Markdown is to wrap the contents in a R code chunk 
with `eval=FALSE, include=FALSE`, to stop knit() from evaluating it, and 
removing it from the intermediate md output.  Of course, such a block can 
not contain other nested R-code chunks, unless they are commented-out.

``````
---
title: Comment
---

## Section

This is a simple placeholder for the manuscript's main document [@knuth84].


```{r}
x <- 1 + 1
x
```

Note pi is `r pi`.

```{r comments, eval=FALSE, include=FALSE}
You can embed code like this:

# ```{r}
# 1 + 1
# ```
but beware, is `r .NotYetImplemented()` still executed?
```

More text.

``````

Best of luck,

Jonathan
On Saturday, 26 August 2023 at 15:57:10 UTC-4 bapt a wrote:

> Hi,
>
> I'm playing with an idea for quarto, where one could comment out portions 
> of the input document including text and code chunks. This workaround would 
> make use of the trick that 1) Yaml blocks can appear anywhere in a pandoc 
> document, and 2) commented out (#) lines in Yaml are stripped by pandoc (?).
>
> I'd like to run a pre-processing step* on the input document to return 
> essentially the same input, but getting rid off those commented out Yaml 
> lines.
>
> Consider the following input file,
>
> ``````
> ---
> title: Comment
> ---
>
> ## Section
>
> This is a simple placeholder for the manuscript's main document [@knuth84].
>
>
> ```{r}
> x <- 1 + 1
> x
> ```
>
> Note pi is `r pi`.
>
> ---
> #  You can embed code like this:
> # 
> # ```{r}
> # 1 + 1
> # ```
> # but beware, is `r .NotYetImplemented()` still executed?
> ---
>
> More text.
>
> ``````
> The commented out portion should be removed before quarto calls the 
> computational engine, otherwise the code still gets executed.
>
> I've tried various flavours of markdown, such as
>
> > quarto pandoc -t noop.lua  -f markdown  index.qmd
>
> where noop.lua is a dummy Writer doing nothing,
>
> ```
> function Writer (doc, opts)
>   local filter = {  }
>   return pandoc.write(doc:walk(filter), 'markdown', opts)
> end
> ````
>
> but I'm not finding the right combination of options, if there is one. 
> Some markdown flavours seem to keep the Yaml comments (not sure why), 
> others reformat the 3-backticks code block. Is this "identity" Writer going 
> to be difficult to achieve?
>
> Many thanks,
>
> baptiste
>
> * Note that code is currently detected via regex in quarto, so it gets 
> executed even inside comments (hence the need of a pre-processor to strip 
> it entirely from the document).
> See https://github.com/quarto-dev/quarto-cli/discussions/3330 for more 
> context
>

-- 
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 pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/6e4c86d9-f030-4dcd-bf04-b9ff68b8981fn%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 4544 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-29 13:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-26 19:57 markdown to markdown, stripping Yaml comments and keeping 3-backticks code blocks intact bapt a
     [not found] ` <9abf1645-7bd2-427c-846e-1b2e7a438760n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-08-29 13:40   ` Jonathan Whiteley

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).