reveal.jsquarto

how to add comments that are hidden in the rendered quarto revealjs presentation


Is there a way to add comments to quarto Revealjs presentation that are hidden from the presentation? Typically in R we use # to comment code so that we can keep track of what we are doing. However if I use # in quarto revealjs document that adds a slider. I am trying to add something that is visible in the code block (to me) but is invisible and doesn't show up in presentation. This is specifically for the "presentation" part of revealjs rather than the code block chuck part.


Solution

  • You can add comments (only visible in the code editor and invisible in the presentation) in the quarto documents and not in the code block (i.e. code-chunk) by using the html syntax <!-- some comment --> for commenting out.

    And to add comment hidden in the rendered document, you can use the Quarto extension code-visibility, where you can add #| hide_line after each comment to hide that comment in rendered document.

    But appending #| hide_line after each line seems more typing to me, so I have used the following lua filter hide-comment.lua modifying the source code of code-visibility veeryy litte and to use it, simply start the comment you want to hide from code chunk with #>.

    ---
    title: "RevealJS"
    format: revealjs
    filters:
      - hide-comment.lua
    execute: 
      echo: true
    ---
    
    ## Quarto
    
    <!-- This is some hidden comment -->
    
    
    ```{r}
    #| message: false
    #> This is some hidden comment which is visible in code editor
    #> but not in rendered documents
    library(dplyr)
    
    #> more hidden comment
    mtcars %>% 
      select(mpg, am ,vs) %>% 
      group_by(vs) %>% 
      summarise(mean(mpg))
    ```
    

    hide-comment.lua

    local function filter_lines(text, filter)
      local lines = pandoc.List()
      local code = text .. "\n"
      for line in code:gmatch("([^\r\n]*)[\r\n]") do
        if filter(line) then
          lines:insert(line)
        end
      end
      return table.concat(lines, "\n")
    end
    
    function CodeBlock(el)
      if el.classes:includes('cell-code') then
        el.text = filter_lines(el.text, function(line)
          return not line:match("#>")
        end)
        return el
      end
    end
    
    

    Update: I have written a Quarto Extension filter hide-comment which can be used to add comments in code chunk that will be hidden in the rendered version of the document.


    hide comment in quarto