Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight Rd code blocks according to their language (new take) #1724

Merged
merged 28 commits into from
Oct 13, 2021
Merged

Conversation

maelle
Copy link
Collaborator

@maelle maelle commented Jun 18, 2021

Fix #1690
Fix #1692

TODOs

@maelle
Copy link
Collaborator Author

maelle commented Jun 18, 2021

This relies on div with classes introduced by r-lib/roxygen2#1229 -- is that a bad idea? Should the docs state that somehow?

NEWS.md Outdated Show resolved Hide resolved
@maelle maelle marked this pull request as ready for review June 18, 2021 12:10
@maelle maelle requested a review from hadley June 18, 2021 12:15
Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

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

Overall, this approach seems much better to me, thanks! Lots of smaller comments below 😄

NEWS.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
R/test.R Outdated Show resolved Hide resolved
R/html-tweak.R Outdated Show resolved Hide resolved
R/html-tweak.R Outdated Show resolved Hide resolved
R/html-tweak.R Outdated Show resolved Hide resolved
R/rd-html.R Outdated Show resolved Hide resolved
R/test.R Outdated Show resolved Hide resolved
R/html-tweak.R Outdated Show resolved Hide resolved
@maelle
Copy link
Collaborator Author

maelle commented Sep 1, 2021

Noting here that the snapshot depends on the Pandoc version 😩

Locally I have Pandoc 2.11.4 and got

 <body>
      <div class="ref-section">
      <div class="sourceCode yaml">
      <pre>
      <code><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a></span>
    <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="at">  </span><span class="fu">url</span><span class="kw">:</span><span class="at"> https://pkgdown.r-lib.org/</span></span>
    <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a></span>
    <span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="at">  </span></span></code>
      </pre>
      </div>
      </div>
      </body>

Conflicts:
	NEWS.md
	R/html-tweak.R
	tests/testthat/_snaps/html-tweak.md
	tests/testthat/test-html-tweak.R
	tests/testthat/test-template-content.R
@@ -0,0 +1,64 @@
# Syntax highlight for preformatted code blocks
tweak_reference_highlighting <- function(html) {
Copy link
Member

Choose a reason for hiding this comment

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

@maelle I ended up basically re-writing this, but it made me fully understand why it was so complicated 😄 It's a bit easier to test now because I've separated the "finding" from the "modifying" code, and tried to document what I learned in the comments.

@hadley hadley merged commit df47827 into master Oct 13, 2021
@hadley hadley deleted the yay-rd branch October 13, 2021 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants