Skip to content

Commit 53f65da

Browse files
committed
test for slides using codefocus fix for slides not
1 parent 2f10d56 commit 53f65da

File tree

4 files changed

+77
-17
lines changed

4 files changed

+77
-17
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ In addition, `.current-only` will make the fragment disappear when you move into
4747
Here is the source code for a minimal example: [example.qmd](example.qmd) and the [Revealjs presentation](https://reuning.github.io/codefocus/example.html)
4848

4949
Thanks also to [shafayetShafee](https://github.com/shafayetShafee/codefocus).
50-

_extensions/codefocus/codefocus.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,23 @@ window.RevealCodeFocus = function() {
5353

5454
if(currentFragmentsList.length ){
5555

56-
var preElems = currentSlide.querySelectorAll('pre code');
57-
forEach(preElems, function(pre){
58-
/* Added in from highlight-lines.js */
59-
pre.parentNode.classList.add("code-wrapper")
60-
pre.classList.add("has-line-highlights");
56+
/* Check if using codefocus */
57+
var codeFocusSlide = 0;
58+
forEach(currentFragmentsList, function(fragment){
59+
if(fragment.hasAttribute('data-code-focus')){
60+
codeFocusSlide = 1;
61+
}
6162
});
63+
64+
if(codeFocusSlide){
65+
var preElems = currentSlide.querySelectorAll('pre code');
66+
forEach(preElems, function(pre){
67+
/* Added in from highlight-lines.js */
68+
pre.parentNode.classList.add("code-wrapper");
69+
pre.classList.add("has-line-highlights");
70+
});
71+
};
72+
6273
}
6374
clearPreviousFocus();
6475

example.html

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,8 @@ <h1 class="title">Codefocus Example</h1>
12191219
</div>
12201220

12211221
</section>
1222-
<section>
1223-
<section id="slide-one" class="title-slide slide level1 center">
1224-
<h1>Slide One</h1>
1222+
<section id="slide-one" class="slide level2">
1223+
<h2>Slide One</h2>
12251224
<div class="cell">
12261225
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1"></a>vector <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>)</span>
12271226
<span id="cb1-2"><a href="#cb1-2"></a>vector <span class="ot">&lt;-</span> <span class="fu">sample</span>(vector)</span>
@@ -1270,10 +1269,30 @@ <h2>Using normal highlights</h2>
12701269
<div class="sourceCode" id="cb6" data-code-line-numbers="1,3|2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1"></a>a <span class="ot">&lt;-</span> <span class="dv">1</span></span>
12711270
<span id="cb6-2"><a href="#cb6-2"></a>b <span class="ot">&lt;-</span> <span class="dv">2</span></span>
12721271
<span id="cb6-3"><a href="#cb6-3"></a>c <span class="ot">&lt;-</span> <span class="dv">1</span> <span class="sc">+</span> <span class="dv">2</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
1272+
</section>
1273+
<section id="test-1" class="slide level2">
1274+
<h2>Test 1</h2>
1275+
<p>Should be normal</p>
1276+
<div class="cell">
1277+
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1"></a>df <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">x=</span><span class="dv">1</span>)</span>
1278+
<span id="cb7-2"><a href="#cb7-2"></a>df</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
1279+
<div class="cell-output cell-output-stdout">
1280+
<pre><code> x
1281+
1 1</code></pre>
1282+
</div>
1283+
</div>
1284+
<div class="fragment">
1285+
<p>Should be normal</p>
1286+
<div class="sourceCode" id="cb9"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1"></a>df <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">x=</span><span class="dv">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
1287+
</div>
1288+
</section>
1289+
<section id="test-2" class="slide level2">
1290+
<h2>Test 2</h2>
1291+
<p>Another slide</p>
12731292
<div class="footer footer-default">
12741293

12751294
</div>
1276-
</section></section>
1295+
</section>
12771296
</div>
12781297
</div>
12791298

@@ -1848,12 +1867,23 @@ <h2>Using normal highlights</h2>
18481867

18491868
if(currentFragmentsList.length ){
18501869

1851-
var preElems = currentSlide.querySelectorAll('pre code');
1852-
forEach(preElems, function(pre){
1853-
/* Added in from highlight-lines.js */
1854-
pre.parentNode.classList.add("code-wrapper")
1855-
pre.classList.add("has-line-highlights");
1870+
/* Check if using codefocus */
1871+
var codeFocusSlide = 0;
1872+
forEach(currentFragmentsList, function(fragment){
1873+
if(fragment.hasAttribute('data-code-focus')){
1874+
codeFocusSlide = 1;
1875+
}
18561876
});
1877+
1878+
if(codeFocusSlide){
1879+
var preElems = currentSlide.querySelectorAll('pre code');
1880+
forEach(preElems, function(pre){
1881+
/* Added in from highlight-lines.js */
1882+
pre.parentNode.classList.add("code-wrapper");
1883+
pre.classList.add("has-line-highlights");
1884+
});
1885+
};
1886+
18571887
}
18581888
clearPreviousFocus();
18591889

example.qmd

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ execute:
99
embed-resources: true
1010
---
1111

12-
# Slide One
12+
## Slide One
1313

1414
```{r}
1515
vector <- c(1,2,3)
@@ -59,4 +59,24 @@ You can still use normal higlights as well.
5959
a <- 1
6060
b <- 2
6161
c <- 1 + 2
62-
```
62+
```
63+
64+
65+
## Test 1
66+
67+
Should be normal
68+
```{r}
69+
df <- data.frame(x=1)
70+
df
71+
```
72+
. . .
73+
74+
Should be normal
75+
76+
```{.r}
77+
df <- data.frame(x=1)
78+
```
79+
80+
## Test 2
81+
82+
Another slide

0 commit comments

Comments
 (0)