Skip to content

Commit bc4c013

Browse files
committed
Improve tests
1 parent 3f15ad5 commit bc4c013

File tree

4 files changed

+96
-3
lines changed

4 files changed

+96
-3
lines changed

src/format/html/format-html-bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function bootstrapHtmlPostprocessor(
327327

328328
// Look for included / embedded notebooks and include those
329329
if (format.render[kNotebookLinks] !== false) {
330-
await processNotebookEmbeds(doc, format, resources);
330+
await processNotebookEmbeds(input, doc, format, resources);
331331
}
332332

333333
// default treatment for computational tables

src/format/html/format-html-notebook.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export function notebookViewPostProcessor() {
8383

8484
// Processes embeds within an HTML page and emits notebook previews as apprpriate
8585
export async function processNotebookEmbeds(
86+
input: string,
8687
doc: Document,
8788
format: Format,
8889
resources: string[],
@@ -116,8 +117,9 @@ export async function processNotebookEmbeds(
116117
// Read options for this notebook
117118
const nbPreviewOptions = nbViewConfig.options(notebookPath);
118119

120+
const nbAbsPath = join(dirname(input), notebookPath);
119121
const htmlPreview = await renderHtmlView(
120-
notebookPath,
122+
nbAbsPath,
121123
nbPreviewOptions,
122124
format,
123125
services,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Note Preview
3+
subtitle: This demonstrates some cool stuff with notebooks
4+
author:
5+
- name: Charles Teague
6+
affiliation: Posit, PBC
7+
- name: Norah Jones
8+
affiliation: Blue Note Records
9+
date: last-modified
10+
format:
11+
html:
12+
title-block-banner: "#370D32"
13+
title-block-banner-color: white
14+
ipynb: default
15+
code-line-numbers: true
16+
code-annotations: select
17+
grid:
18+
sidebar-width: 300px
19+
body-width: 1000px
20+
margin-width: 300px
21+
gutter-width: 1.5rem
22+
theme: spacelab
23+
notebook-view:
24+
- notebook: plots.ipynb
25+
url: https://www.kaggle.com/code/kanncaa1/data-sciencetutorial-for-beginners
26+
title: TEST NB
27+
notebook-links: "inline"
28+
_quarto:
29+
tests:
30+
html:
31+
ensureHtmlElements:
32+
- ['a.quarto-notebook-link']
33+
- ['div.quarto-alternate-notebooks a']
34+
ensureFileRegexMatches:
35+
- ['Source: TEST NB']
36+
---
37+
38+
## Sample Code. Cool!
39+
40+
```{r}
41+
num = 47
42+
factorial = 1
43+
if(num < 0) { # <2>
44+
print("Sorry, factorial does not exist for negative numbers")
45+
} else if(num == 0) {
46+
print("The factorial of 0 is 1")
47+
} else {
48+
for(i in 1:num) { # <3>
49+
factorial = factorial * i # <3>
50+
} # <3>
51+
print(paste("The factorial of", num ,"is",format(factorial)))
52+
}
53+
```
54+
55+
2. Check is the number is negative, positive or zero
56+
3. Actually compute the factorial
57+
58+
## A Figure
59+
60+
Also, see the figure below, which shows something cool.
61+
62+
{{< embed plots.ipynb#plot-dot >}}
63+
64+
2. fo
65+
3. foo
66+
67+
```{r}
68+
num = 47
69+
factorial = 1
70+
if(num < 0) { # <2>
71+
print("Sorry, factorial does not exist for negative numbers")
72+
} else if(num == 0) {
73+
print("The factorial of 0 is 1")
74+
} else {
75+
for(i in 1:num) { # <3>
76+
factorial = factorial * i # <3>
77+
} # <3>
78+
print(paste("The factorial of", num ,"is",format(factorial)))
79+
}
80+
```
81+
82+
2. Check is the number is negative, positive or zero
83+
3. Actually compute the factorial

tests/docs/smoke-all/2023/01/05/notebook-preview.qmd renamed to tests/docs/smoke-all/2023/01/05/notebook-preview-simple.qmd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ grid:
2020
margin-width: 300px
2121
gutter-width: 1.5rem
2222
theme: spacelab
23-
2423
notebook-view: true
2524
notebook-links: true
25+
_quarto:
26+
tests:
27+
html:
28+
ensureHtmlElements:
29+
- [
30+
'div.quarto-alternate-notebooks a',
31+
'a.quarto-notebook-link'
32+
]
33+
- []
2634
---
2735

2836
## Sample Code. Cool!

0 commit comments

Comments
 (0)