Skip to content

Commit

Permalink
Current version of Markdown handout and exercise scripts
Browse files Browse the repository at this point in the history
Includes rendering and running, delivery, and an example handout.
  • Loading branch information
maxg committed Jan 23, 2016
1 parent 0efc6e3 commit 2e46bc9
Show file tree
Hide file tree
Showing 15 changed files with 4,197 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
76 changes: 76 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,79 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

============
= PageDown =
============

A javascript port of Markdown, as used on Stack Overflow
and the rest of Stack Exchange network.

Largely based on showdown.js by John Fraser (Attacklab).

Original Markdown Copyright (c) 2004-2005 John Gruber
<http://daringfireball.net/projects/markdown/>

Original Showdown code copyright (c) 2007 John Fraser

Modifications and bugfixes (c) 2009 Dana Robinson
Modifications and bugfixes (c) 2009-2014 Stack Exchange Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

=======================================
= Markdown Extra Plugins for PageDown =
=======================================

Javascript Markdown Extra Extensions for Pagedown
Copyright © 2012-2013 Justin McManus
All rights reserved.

PHP Markdown & Extra
Copyright © 2004-2013 Michel Fortin
All rights reserved.

Original Markdown
Copyright © 2004-2006 John Gruber
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

Neither the name “PHP Markdown” nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.

This software is provided by the copyright holders and contributors “as is” and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are
disclaimed. In no event shall the copyright owner or contributors be liable for
any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused and on
any theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.
120 changes: 120 additions & 0 deletions example/handout/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!DOCTYPE html>
<html>
<head>

<title>Example Handout</title>

<link href="../../web/handout/handout-style.css" rel="stylesheet"></link>
</head>
<body>
<header>6.HANDX &mdash; Handouts + Exercises</header>
<!-- optional: nav.table-of-contents becomes a table of contents -->
<nav class="table-of-contents"></nav>
<main>

<div class="markdown">

The page title is automatically added as a page heading.

## Section

Use `##` for sections.

### Subsection

Use `###` for subsections.
Use `####` if necessary.

**Bold**, *italic*, and `code` inline styles.

+ Bulleted lists
+ with `+`
+ or `-`
+ or `*`

```java
public static void main(String[] args) {
System.out.println("Syntax-highlighted code");
}
```

You must escape `&lt;` characters.
Sorry.

<pre>
Fixed-width block with **inline** *styles*.
</pre>

<div class="exercises">

# Exercise 1

Exercises are in a `&lt;div class="exercises">`.

Use `#` for exercise titles.

Highlight questions using `##`:

## What is the airspeed velocity of an unladen swallow?

[x] Checkboxes
[x] *with* **styles**
[ ] `and code`

( ) Radio buttons
(x) *with* **styles**
( ) `and code`

Use Markdown blockquote (`>`) for explanations.

> The answer is: 42.

---

# Exercise 2

Separate multiple exercises with a Markdown horizontal rule (`---`).

[x] OK

Dropdowns and text fields have normal and `code` versions:

[[ Drop, (down) ]]

[[` code, (correct()), incorrect), (incorrect, incorrect() `]]

= text field

= `code text field`

> Explanation with `inline_code` and a code block:
>
> ```java
> public void blockOfCode() { }
> ```

---

# Exercise 3

Text fields can also be checked against a regular expression:

= /regular expression|regexp?/ regex

= `/a +b +c/ a b c`

</div>

## Another section

And so on, and so on.

</div>

</main>
<!-- optional: footer containing &copy; becomes a copyright message -->
<footer>&copy;</footer>
<footer>MIT EECS</footer>
<script src="../../web/handout/handout-render.js"></script>
</body>
</html>
82 changes: 82 additions & 0 deletions scripts/deliver-handouts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

#
# Handout Delivery
#

webmaster= # TODO [email protected]
phantomjs="${PHANTOMJS:-/default/path/to/phantomjs-2.0}" # TODO
deliver=web/handout/deliver/deliver.phantom.js
home=home # special home page handout

set -e
set -u

path="${1:?Must specify path}"
src="${2:?Must specify source location}"
www="${3:?Must specify www location}"
handx="${4:?Must specify handx location}"

abssrc="$(cd "$src" && pwd)"

from="$src/$path/handout"
deploy="$www/$path"
if [ "$path" == "$home" ]; then
# deploy home page to root
deploy="$www"
fi

if [ ! -d "$from" ]; then
echo -e "[no handouts] $path in $src"
exit
fi

if [ ! -d "$deploy" ]; then
echo -e "\033[1;31m[deploy skipped]\033[0m $path directory does not exist in $www"
exit
fi

echo "[deploy] $path"

[ -n "$webmaster" ] && sendmail "$webmaster" <<EOM
Subject: [handx] updating $path
$path updated by $USER
$from -> $deploy
EOM

(cd "$from" && find . -mindepth 1 -type d) | # find directories
sed 's/^.\///' | # relative dir names
(cd "$deploy" && xargs -I DIR mkdir -p DIR) # create in www

(cd "$from" && find . -type f) | # find files
sed 's/^.\///' | # relative file names
while read -r file; do # for each file...
# handouts are HTML files that reference the handout script
if [[ "$file" == *.html ]] && fgrep -q handout-render.js "$from/$file"; then
# pre-render the handout
echo " render $file"
IFS=/ read -r kind handout part <<< "$path/${file%.html}"
part="${part%index}"; part="${part%/}"
[ -f "$deploy/$file" ] && rm "$deploy/$file"
"$phantomjs" "$src/$deliver" "$from/$file" "$deploy/$file" "$handx" "$kind" "$handout" "$part"
else
# just copy the file
echo " copy $file"
cp "$from/$file" "$deploy/$file"
fi
case "$file" in
*.html|*.svg)
# fix paths to site CSS & JavaScript
# ="../../../web/handout/handout-file" -> ="../../web/handout-file"
perl -pi -e 's#(="[^"]*)/\.\./([^"]*)/handout/([^"]*")#\1/\2/\3#g' "$deploy/$file"
if [ "$path" == "$home" ]; then
# fix relative paths from home page
# ="../web/something" -> ="web/something"
perl -pi -e 's#(=")\.\./([^"]*")#\1\2#g' "$deploy/$file"
fi
;;
esac
done

echo -e "\033[1;32m[deployed]\033[0m $path"
40 changes: 40 additions & 0 deletions scripts/deliver-handouts-athena
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

#
# Athena Handout Delivery Wrapper
#

# TODO www=/mit/6.HANDX/www
# TODO handx=/mit/6.HANDX/web_scripts/handx

set -e
set -u

path="${1:?Must specify path}"

scripts="$(dirname "$0")" # scripts directory
scripts="$(cd "$scripts" && pwd)" # full path

src="$(dirname "$scripts")" # semester directory

semester="${src##*/}" # long semester name
shortsem="${semester/#fall/fa}" # short semester name
shortsem="${shortsem/#spring/sp}"

from="$src/$path/handout"
deploy="$www/$shortsem/$path"

if [ ! -d "$from" ]; then
echo -e "[no handouts] $path"
exit
fi

if [ ! -d "$deploy" ]; then
echo -e "\033[1;31m[deploy skipped]\033[0m $path directory does not exist in www. Create it:"
echo "$ mkdir $deploy"
echo 'Then push again or:'
echo "$ $scripts/${0##*/} $path"
exit
fi

"$scripts/deliver-handouts" "$path" "$src" "$www/$shortsem" "$handx/$shortsem/data"
45 changes: 45 additions & 0 deletions scripts/repo-post-receive-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

#
# Repository Post-Receive Hook
#

# TODO snapshotdir=/mit/6.HANDX/path/to/repo-snapshot

set -e
set -u

# meta-hook supplies original script name
self="$1"

semester="${self%/scripts/repo-post-receive-hook}"

# be helpful to someone debugging this script
if [ -z "$GIT_DIR" -o -z "$self" ]; then
echo "Usage: echo <oldrev> <newrev> <branch> | GIT_DIR=<dir> $0 <path/to/self>"
exit 1
fi

master="refs/heads/master"

while read -r oldrev newrev branch; do
if [ "$branch" == "$master" ]; then
break
fi
done

if [ "$branch" != "$master" -o -z "$newrev" ]; then
exit 0
fi

# update our snapshot of master
echo Updating snapshot in $snapshotdir
GIT_WORK_TREE="$snapshotdir" git checkout -f

# deploy handouts to the web
git diff --name-only "$oldrev" "$newrev" |
perl -lne "/$semester"'\/(.*)\/handout\// && print $1' |
sort | uniq |
while read -r dir; do
"$snapshotdir/$semester/scripts/deliver-handouts-athena" "$dir"
done
11 changes: 11 additions & 0 deletions web/handout/course-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Course Handout Configuration
*
* Customize me!
*/

HANDOUT_SEMESTER = 'IAP 2000';
HANDOUT_AUTHORS = 'Copyright Alice and Bob, all imaginary rights reserved.';
HANDOUT_HOME = 'http://example.com/6.HANDX/www/ia00/';
// optional: handx server for server-checked exercises
// HANDOUT_EXERCISES = 'https://example.com/handx/ia00/';
Loading

0 comments on commit 2e46bc9

Please sign in to comment.