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

Add question type checked by JavaScript functions #49

Merged
merged 2 commits into from
Apr 21, 2024

Conversation

seragunn
Copy link
Contributor

Sample usage

<script src="/js/permutations.js"></script>
<script>
    function checkCycles(ans) {
        return (input) => {
            const ans_perm = new Permutation(ans);
            const in_perm = new Permutation().parseCycles(input);
            return in_perm.equals(ans_perm);
        }
    } 
    function checkShuffle(ans) {
        return (input) => {
            const ans_perm = new Permutation(ans);
            const in_perm = new Permutation().parseList(input);
            return in_perm.equals(ans_perm);
        }
    } 
</script>
using QuizQuestions

scriptq("checkCycles([2, 12, 3, 5, 4, 9, 8, 7, 6, 10, 1, 11])")

scriptq("checkShuffle([[1,8,12],[2,3,6,7,9],[4,10,11]])")

@jverzani
Copy link
Owner

I was wondering how one injects a javascript snippet into the resulting HTML. You have this in your example:

"""

// in JavaScript
function threshold(t) {
    return (input) => {
        return input >= threshold;
    }
}

"""

Would there be an easy quarto equivalent?

If not, would some "question" form be useful with a show method that writes out the javascript code for mime-type text/html be useful?

I'm thinking something like:

struct Script{T} <: ???
txt::T
end

script(txt) = Script(txt)
function Base.show(io::IO, ::MIME"text/html", s::Script) 
println(io, "<script>")
println(io, s.txt) # ? escaped?
println(io, "</script>")
end

Maybe this isn't needed, but it might be helpful?

@seragunn
Copy link
Contributor Author

In Quarto you can put the script tags right into the file. I wouldn't try to have Julia try to programmatically output JavaScript that seems messy. The goal here is we have some external JavaScript code (for my current project, that's JavaScript code to represent permutations as cycles, lists, do multiplication, etc.). Plus that way you get syntax highlighting and debugging.

@seragunn

This comment was marked as resolved.

@seragunn
Copy link
Contributor Author

Yes, so other than Quarto which lets you write <script> tags right into the markdown, you might need some kind of show method to output those tags.

However, I don't know who would be planning on using that. I'm only planning on using this for Quarto and I'm not sure how many other people use this package (or if they're using it outside of Quarto).

@jverzani
Copy link
Owner

This looks great. I'll merge tomorrow and tag a new version unless you say hold off a bit. Thanks!

@jverzani jverzani merged commit 3a206a7 into jverzani:main Apr 21, 2024
5 checks passed
@seragunn seragunn deleted the scriptq-function branch April 21, 2024 19:05
@seragunn seragunn restored the scriptq-function branch April 21, 2024 19:05
@seragunn seragunn deleted the scriptq-function branch April 21, 2024 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants