Skip to content

Commit 6e92822

Browse files
committed
correct check_hints() function; close #5
1 parent fd995e2 commit 6e92822

File tree

6 files changed

+90
-79
lines changed

6 files changed

+90
-79
lines changed

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ Type: Package
33
Title: Check-Fields and Check-Boxes for 'rmarkdown'
44
Version: 0.0.6
55
Depends: R (>= 3.5.0)
6-
Author: George Moroz
7-
Maintainer: George Moroz <agricolamz@gmail.com>
6+
Authors@R: c(person("George", "Moroz",
7+
role = c("aut", "cre"),
8+
email = "agricolamz@gmail.com",
9+
comment = c(ORCID="0000-0003-1990-6083")))
810
Description: Creates auto checking check-fields and check-boxes for 'rmarkdown' html. It could be used in class, when teacher share materials and tasks, so student can solve some problems and check themselves. In contrast with the 'learnr' package the 'checkdown' package works without 'shiny'.
911
Imports: knitr, markdown
1012
URL: https://agricolamz.github.io/checkdown/
1113
BugReports: https://github.com/agricolamz/checkdown/issues
1214
Suggests: rmarkdown
1315
License: GPL (>= 2)
1416
Encoding: UTF-8
15-
RoxygenNote: 7.1.0
17+
RoxygenNote: 7.1.1
1618
VignetteBuilder: knitr

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
checkdown 0.0.6 (16.10.2020)
2+
- correct the "check_hints" problem.
3+
14
checkdown 0.0.5 (14.05.2020)
25
- if argument "answer" in the "check_question()" function is NULL thene remove check button. Thnaks to @ManuelSpinola for the idea.
36
- correct the "insert_images()" function

R/check_hint.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
check_hint <- function(hint_text,
2323
hint_title = "Click here to see/close the hint",
24-
hint_id = sample(1:1e5, 1)){
24+
hint_id = sample(1e5:1, 1)){
2525
if(knitr::is_html_output()){
26+
if(grepl("\\.", hint_id)){
27+
hint_id <- gsub("\\.", "_", hint_id)
28+
}
2629
hint_text <- (markdown::markdownToHTML(text = hint_text,
2730
output = NULL,
2831
fragment.only = TRUE))
@@ -33,6 +36,7 @@ check_hint <- function(hint_text,
3336
fragment.only = TRUE))
3437
hint_title <- gsub("(<.?p>)|(\n)|(\\#)", "", hint_title)
3538

39+
print(hint_id)
3640
cat(paste0(c('<p id="hint_',
3741
hint_id,
3842
'", onclick="return show_hint_',

R/check_hints.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ check_hints <- function(hint_text,
3131
if(knitr::is_html_output()){
3232
hint_title <- paste0(hint_title_prefix, hint_title, hint_title_suffix)
3333
df <- data.frame(hint_text, hint_title, stringsAsFactors = FALSE)
34-
df$hint_id <- sample(2:1e5, nrow(df))
34+
df$hint_id <- sample(1:1e5, nrow(df))
3535

3636
df$hint_text <- unlist(lapply(seq_along(df$hint_text), function(i){
3737
x <- as.character(df$hint_text[i])
@@ -67,28 +67,30 @@ check_hints <- function(hint_text,
6767
'"></p>',
6868
collapse = "")
6969

70+
id <- sample(2e+05:1e5, 1)
71+
7072
cat(paste0(c('<p id="hint_',
71-
1,
73+
id,
7274
'", onclick="return show_hint_',
73-
1,
75+
id,
7476
'()">',
7577
list_title,
7678
'</p><p id="result_',
77-
1,
79+
id,
7880
'"></p>',
7981
'<script> function show_hint_',
80-
1,
82+
id,
8183
'() {',
8284
'var x = document.getElementById("result_',
83-
1,
85+
id,
8486
'").innerHTML;',
8587
"if(!x){document.getElementById('result_",
86-
1,
88+
id,
8789
"').innerHTML = '",
8890
hints,
8991
"';}",
9092
'else {document.getElementById("result_',
91-
1,
93+
id,
9294
'").innerHTML = "";}}',
9395
paste0(
9496
'function show_hint_',

docs/index.html

Lines changed: 66 additions & 66 deletions
Large diffs are not rendered by default.

man/check_hint.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)