Skip to content

Add lua-based codefolding feature and apply it to html_vignette - #2340

Merged
cderv merged 19 commits into
rstudio:mainfrom
atusy:code-folding
Apr 11, 2022
Merged

cderv merged 19 commits into
rstudio:mainfrom
atusy:code-folding

Conversation

@atusy

@atusy atusy commented Mar 31, 2022 •

Copy link
Copy Markdown
Collaborator

This is a step to solve rstudio/bookdown#764

For the toggle switch, I applied minimal styling.
Let me know if we should mimic html_document.

Also, current implementation does not include show/hide all button.
It can be a future work.

image

@atusy

atusy commented Mar 31, 2022

Copy link
Copy Markdown
Collaborator Author

The error from the latest GHA comes from Pandoc devel, which is not related to this PR.

Last 13 lines of output:
  + "    -   <a href=\"#11-b\" id=\"toc-11-b\">1.1 B</a>"
  - "-   [2 C](#2-c)"
  + "-   <a href=\"#2-c\" id=\"toc-2-c\">2 C</a>"
  - "    -   [2.1 D](#21-d)"
  + "    -   <a href=\"#21-d\" id=\"toc-21-d\">2.1 D</a>"
    ""
    "# 1 A"
    ""

@yihui yihui left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me overall. I'll let @cderv review it in detail. Thanks!

@atusy

atusy commented Apr 1, 2022

Copy link
Copy Markdown
Collaborator Author

I tweaked lua and css so that code folding may work without css.
Previous implementation required css for the summary text.

I also realized that we need to check fold-show and fold-hide classes in class.source so that we can control initial state of the code folding.
I will do that later (maybe tonight)

@atusy

atusy commented Apr 1, 2022

Copy link
Copy Markdown
Collaborator Author

ok, implemented fold-show, fold-hide, and fold-none.

@yihui
yihui requested a review from cderv April 1, 2022 14:01

@cderv cderv left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this. This was again something that needed to be done to have a Lua filter for this feature.

This is a first implementation that stick to the current JS one but it gets me new ideas (like customization of the the <summary> text instead of default, adding the language of code source in the summary text too, ...

Anyway, let's keep it simple. You'll find some comments for discussion below, some are suggested changes, other are ideas I want to run by you.

Also, best would be to have some tests for this, but I can do it later. Do you already have a Rmd that you are using for testing ?
If so that, can you share it ? Otherwise, I'll do one myself.

Again thanks a lot for all your help on this. This is truly very appreciated !

The error from the latest GHA comes from Pandoc devel, which is not related to this PR.

yes it is known (#2306) , but I am waiting for next Pandoc release.

Comment thread R/html_vignette.R Resolved
Comment thread R/html_vignette.R Resolved
Comment thread NEWS.md Resolved
Comment thread R/html_vignette.R Resolved
Comment thread R/html_vignette.R Resolved
Comment thread R/html_vignette.R Resolved
Comment thread inst/rmarkdown/lua/codefolding.lua Resolved
Comment thread inst/rmarkdown/lua/codefolding.lua Resolved
Comment thread R/html_dependencies.R Resolved
@atusy

atusy commented Apr 4, 2022

Copy link
Copy Markdown
Collaborator Author

@cderv Thank you for your neat review! I just responsed to the two important comments because their conclusions may affect action to other comments.

@cderv

cderv commented Apr 4, 2022

Copy link
Copy Markdown
Collaborator

Thanks @atusy I answered them.

@cderv cderv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking into account the feedback.

I'll merge this now.

@cderv
cderv merged commit 1ca8a87 into rstudio:main Apr 11, 2022
@cderv

cderv commented Apr 11, 2022

Copy link
Copy Markdown
Collaborator

Thanks @atusy ! I reverted one of your change as it was not correct afterall (#2340 (comment))

@atusy

atusy commented Apr 11, 2022

Copy link
Copy Markdown
Collaborator Author

Thanks a lot for the neat review and final checks!!

j-magnolia pushed a commit to j-magnolia/rmarkdown that referenced this pull request May 5, 2022
* jg-devel:
  use tufte::tufte_handout in test, and remove tufte_handout in doc
  mark tufte_handout() as defunct
  CRAN release v2.14
  typo in NEWS
  Update arrow.theme regarding accessibility
  Adapt test snapshots to last pandoc devel 2.18+ (rstudio#2349)
  Revert "remove from NEWS as pandoc devel reverted the change"
  remove from NEWS as pandoc devel reverted the change
  Support for `fold-none` class in `html_document()` (rstudio#2348)
  Support new scheme for Pandoc nightly build
  Add lua-based codefolding feature and apply it to html_vignette (rstudio#2340)
  `site_generator()` stops search at RStudio project root (rstudio#2345)
  Update CONTRIBUTING.md
  Update tests following Pandoc change in 2.18 (rstudio#2334)
  dirname('.') returns '.', which will cause infinite recursion, so normalize the relative path to absolute before the next recursion (fix rstudio#2339)
  Fix parsing by pandoc of last paragraph in shinyrmd doc (rstudio#2337)
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants