Skip to content

Commit 7c3c005

Browse files
committed
Add syntax highlighting support
1 parent 72d96c7 commit 7c3c005

File tree

4 files changed

+58
-29
lines changed

4 files changed

+58
-29
lines changed

README.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Quizgen: Html Quiz Generator
22

3-
Description: Dead simple way to create HTML quizzes with LaTeX support. Can be used to generate quizzes like: http://stanford.edu/~kvmohan/quizgen/sample.html. Problems with multiple correct answers are supported and images can also be embedded. Tested with Python 2.6/2.7. Shoot me an email at kvmohan [at] stanford [dot] edu if it doesn't work for newer versions.
3+
Description: Dead simple way to create HTML quizzes with LaTeX support and code highlighting. Can be used to generate quizzes like: http://stanford.edu/~kvmohan/quizgen/sample.html. Problems with multiple correct answers are supported and images can also be embedded. Tested with Python 2.6/2.7. Shoot me an email at karanveer.1992 [at] gmail [dot] com if it doesn't work for newer versions.
44

55
## Table of Contents
6-
[Setup](#setup)
7-
[Quiz Structure](#structure)
8-
[Creating Quizzes](#create)
9-
[Samples](#samples)
10-
[Getting Started](#start)
11-
[Feature Requests / Contributing changes / Issues](#issues)
12-
[FAQ](#faq)
13-
[Credits](#credits)
14-
[MIT License](#license)
6+
[Setup](#setup)
7+
[Quiz Structure](#structure)
8+
[Creating Quizzes](#create)
9+
[Samples](#samples)
10+
[Getting Started](#start)
11+
[Feature Requests / Contributing changes / Issues](#issues)
12+
[FAQ](#faq)
13+
[Credits](#credits)
14+
[MIT License](#license)
1515

1616
<a name="setup"/>
1717
## Project Setup
@@ -20,8 +20,8 @@ How do I start using Quizgen?
2020

2121
1. Copy over the file [quizgen.py](https://raw.githubusercontent.com/karanveerm/quizgen/master/quizgen.py).
2222
2. Everything you need is in the file!
23-
3. Run `python quizgen.py` to get help on usage.
24-
4. You might want to alias it or `sudo cp quizgen.py /usr/bin/quizgen` so you can simply type in quizgen.
23+
3. Run `python quizgen.py` to get help on usage.
24+
4. You might want to alias it or `sudo cp quizgen.py /usr/bin/quizgen` so you can simply type in quizgen.
2525
5. Remember to `sudo chmod +x /usr/bin/quizgen` to make the file executable.
2626

2727
<a name="structure"/>
@@ -46,8 +46,14 @@ This is the statement for problem group one.
4646
You can add a link to websites like this: ||LINK: http://www.google.com||.
4747
You can add images like this:
4848
||IMG:http://upload.wikimedia.org/wikipedia/commons/9/9b/Carl_Friedrich_Gauss.jpg||
49-
The image source can either be a local path, or some URL. Images can be embedded
49+
The image source can either be a local path, or some web URL. Images can be embedded
5050
anywhere: within problem groups, problems or options.
51+
It also supports syntax highlighting like this:
52+
||CODE:java:
53+
int a = 2;
54+
int b = 3;
55+
System.out.println(a + b);
56+
||
5157
Quizgen supports LaTeX:
5258
\[
5359
a = \begin{pmatrix} 1 \\ 3 \\ 2 \end{pmatrix} , \quad
@@ -58,8 +64,8 @@ A blank line marks the end of this problem group introduction text and the
5864
beginning of the first problem.
5965
6066
This is the first problem in the problem group with some LaTeX: $a_3$.
61-
* This is an option. :: You can add an explanation for an option after the double
62-
colon to explain why it is correct/incorrect.
67+
* This is an option. :: You can add an explanation for an option after the double colon to explain
68+
why it is correct/incorrect.
6369
* This is another option. Observe that explanations are optional.
6470
*= This option is the correct option since it is marked with an equal to sign.
6571
@@ -75,10 +81,10 @@ x=Zy + a - c.
7581
You can also have problems with multiple correct responses.
7682
Students will be asked to select all that apply, and then submit their
7783
responses.
78-
*= Option 1.
84+
*= Option 1. :: This is an explanation.
7985
* Option 2.
8086
* Option 3.
81-
*= Option 4. :: This is another correct option.
87+
*= Option 4.
8288
8389
[]
8490
This problem group has no title and has no introduction.
@@ -111,19 +117,19 @@ sample.quiz is a great place to get started. A list of samples can also be found
111117

112118
- Feel free to make a pull request; I'll review the code and merge.
113119
- Or just file an issue.
114-
- Alternatively, email kvmohan [at] stanford [dot] edu and I'll try to help you ASAP!
120+
- Alternatively, email karanveer.1992 [at] gmail [dot] com and I'll try to help you ASAP!
115121

116122
<a name="faq"/>
117123
## FAQ
118124

119125
1. Can we keep track of how students perform on the quizzes?
120126

121127
No. Quizgen generates quizzes that are only for self-assessment; it does not support logging of responses.
122-
128+
123129
2. Why did you work on this?
124130

125131
I was hoping to create simple, lightweight method for instructors to generate quizzes that can be easily incorporated into a course website, allowing students to quickly get some feedback on how well they understand the basic material in a class.
126-
132+
127133
<a name="credits"/>
128134
## Credits
129135
Designed and implemented by Karanveer Mohan, with design input from [Stephen Boyd](http://www.stanford.edu/~boyd/) and [Karthik Viswanathan](http://www.karthikv.net/). Partly based on a simple quiz generator developed by Eric Chu, that was used in Stanford’s EE263 and EE364a classes since 2012, but was never made public.

quizgen.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ def add_dom_to_template(dom, html_file_name, quiz):
417417
# For the links
418418
content = re.sub('\|\|LINK:\s?(\S+)\|\|', r'<a href="\1">\1</a>', content)
419419

420+
# For code blocks
421+
content = re.sub('\|\|CODE:(\S+):\s?(.*?)\|\|', r'<pre><code class="\1">\2</pre></code>', content,
422+
flags=re.DOTALL)
423+
424+
420425
generated_file.write(content)
421426
generated_file.close()
422427

@@ -553,6 +558,9 @@ def main():
553558
});
554559
</script>
555560
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML.js"></script>
561+
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/styles/default.min.css">
562+
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/highlight.min.js"></script>
563+
<script>hljs.initHighlightingOnLoad();</script>
556564
557565
<script type="text/javascript">
558566
$(document).ready(function(){

sample.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html>
44
<head>
55
<meta charset="UTF-8" />
6-
<title>Sample Quiz Title</title>
6+
<title>Quiz</title>
77
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans|Alike' rel='stylesheet' type='text/css'>
88
<link rel="stylesheet" href="quiz.css" type="text/css" />
99
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
@@ -16,6 +16,9 @@
1616
});
1717
</script>
1818
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML.js"></script>
19+
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/styles/default.min.css">
20+
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/highlight.min.js"></script>
21+
<script>hljs.initHighlightingOnLoad();</script>
1922

2023
<script type="text/javascript">
2124
$(document).ready(function(){
@@ -71,6 +74,11 @@ <h1>Sample Quiz Title</h1>
7174
<div><img src="http://upload.wikimedia.org/wikipedia/commons/9/9b/Carl_Friedrich_Gauss.jpg"></div>
7275
The image source can either be a local path, or some web URL. Images can be embedded
7376
anywhere: within problem groups, problems or options.
77+
It also supports syntax highlighting like this:
78+
<pre><code class="java">int a = 2;
79+
int b = 3;
80+
System.out.println(a + b);
81+
</pre></code>
7482
Quizgen supports LaTeX:
7583
\[
7684
a = \begin{pmatrix} 1 \\ 3 \\ 2 \end{pmatrix} , \quad
@@ -79,6 +87,7 @@ <h1>Sample Quiz Title</h1>
7987
\]
8088
A blank line marks the end of this problem group introduction text and the
8189
beginning of the first problem.</div>
90+
<hr/>
8291
<div>
8392
<div class="description">
8493
This is the first problem in the problem group with some LaTeX: $a_3$.</div>
@@ -144,14 +153,14 @@ <h1>Sample Quiz Title</h1>
144153
<span class="multiple-selection">Option 1. </span>
145154
<span class="correct-checkbox"></span>
146155
<span class="incorrect-checkbox"></span>
147-
<div class="response right">This option is correct. This option is correct.</div>
156+
<div class="response right">This option is correct. This is an explanation.</div>
148157
</label>
149158
<label>
150159
<input type="checkbox"/>
151-
<span class="multiple-selection">Option 2. </span>
160+
<span class="multiple-selection">Option 2.</span>
152161
<span class="correct-checkbox"></span>
153162
<span class="incorrect-checkbox"></span>
154-
<div class="response wrong">This option is incorrect. This option is not correct.</div>
163+
<div class="response wrong">This option is incorrect. </div>
155164
</label>
156165
<label>
157166
<input type="checkbox"/>
@@ -162,10 +171,10 @@ <h1>Sample Quiz Title</h1>
162171
</label>
163172
<label>
164173
<input type="checkbox"/>
165-
<span class="multiple-selection">Option 4. </span>
174+
<span class="multiple-selection">Option 4.</span>
166175
<span class="correct-checkbox"></span>
167176
<span class="incorrect-checkbox"></span>
168-
<div class="response right">This option is correct. This is another correct option.</div>
177+
<div class="response right">This option is correct. </div>
169178
</label>
170179
<button>Submit</button>
171180
</div>

sample.quiz

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ You can add images like this:
66
||IMG:http://upload.wikimedia.org/wikipedia/commons/9/9b/Carl_Friedrich_Gauss.jpg||
77
The image source can either be a local path, or some web URL. Images can be embedded
88
anywhere: within problem groups, problems or options.
9+
It also supports syntax highlighting like this:
10+
||CODE:java:
11+
int a = 2;
12+
int b = 3;
13+
System.out.println(a + b);
14+
||
915
Quizgen supports LaTeX:
1016
\[
1117
a = \begin{pmatrix} 1 \\ 3 \\ 2 \end{pmatrix} , \quad
@@ -32,10 +38,10 @@ x=Zy + a - c.
3238
You can also have problems with multiple correct responses.
3339
Students will be asked to select all that apply, and then submit their
3440
responses.
35-
*= Option 1. :: This option is correct.
36-
* Option 2. :: This option is not correct.
41+
*= Option 1. :: This is an explanation.
42+
* Option 2.
3743
* Option 3.
38-
*= Option 4. :: This is another correct option.
44+
*= Option 4.
3945

4046
[]
4147
This problem group has no title and has no introduction. When the text following the start of a new problem group is immediately followed by the options, it is inferred to be a problem.

0 commit comments

Comments
 (0)