Skip to content
Permalink
Browse files

Initial version.

  • Loading branch information
lapets committed Sep 1, 2014
1 parent 482a52e commit 2b1c4b1ca7380cb4d7cebf6a87beb52eba9c9b25
Showing with 1,448 additions and 1 deletion.
  1. +22 −0 LICENSE.TXT
  2. +8 −1 README.md
  3. +97 −0 hooks/Haskell.php
  4. +117 −0 hooks/JavaScript.php
  5. +110 −0 hooks/Python.php
  6. +92 −0 hooks/SQL.php
  7. +204 −0 hooks/math.php
  8. +69 −0 package.xml
  9. +5 −0 release.sh
  10. +150 −0 sheaf.css
  11. +21 −0 sheaf.js
  12. +553 −0 sheaf.php
@@ -0,0 +1,22 @@
Copyright 2014 various contributors

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.
@@ -1,4 +1,11 @@
sheaf
=====

Representation format and web application for storing and rendering lecture notes in mathematics and computer science.
Representation format and web application for storing and rendering lecture notes in mathematics and computer science.

A library that supports the representation and automated
rendering of lecture notes for mathematics and computer
science courses.

Web: sheaf.io
Version: 0.0.1.0
@@ -0,0 +1,97 @@
<?php /**************************************************************
**
** sheaf/hooks/Haskell.php
**
** Hook for rendering simple markdown notation for Haskell code
** snippets.
**
*/

/********************************************************************
*/

function sheaf_hook_Haskell ($s) {
$s = sheaf::r($s, "\r", "");

$inp = $s;
$s = "";
$flag = array('line' => 0, 'delimited' => 0, 'literal' => 'none', 'escaped' => 0);
$lineComment = 'false';
for ($i = 0; $i < strlen($inp); $i++) {
$c = $inp[$i];

// Handle single-line newline-terminated comments.
if (($c === '#' || ($c === "-" && $i < strlen($inp)-1 && $inp[$i+1] == "-")) && $flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="comment">';
$s .= $c;
$flag['line'] = 1;
} else if ($c == "\n" && $flag['line'] == 1) {
$s .= '</span>';
$s .= $c;
$flag['line'] = 0;
}

// Handle string literals.
else if ($c == '"') {
if ($flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="literal">';
$s .= $c;
$flag['literal'] = '"';
} else if ($flag['literal'] == '"') {
$s .= $c;
$s .= '</span>';
$flag['literal'] = 'none';
} else {
$s .= $c;
}
}
else if ($c == "'" && strlen($inp) > $i+2 && $inp[$i+2] == "'") {
if ($flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="literal">'.$inp[$i+1].'</span>';
$i += 2;
}
}

// Defaults.
else if ($c === " ") {
$s .= "&nbsp;";
} else if ($c === "@") {

// Handle built in commands.
$handled = false;
$commands = array(
'module','where', 'import',
'data','deriving','type','class','instance',
'if','then','else','let','in'
);
$builtins = array(
);
foreach ($builtins as $prefix) {
if (sheaf::startsWith(substr($inp, $i), '@'.$prefix)) {
$s .= '<span class="builtin">' . $prefix . '</span>';
$i += strlen('@'.$prefix)-1;
$handled = true;
break;
}
}
foreach ($commands as $prefix) {
if (sheaf::startsWith(substr($inp, $i), '@'.$prefix)) {
$s .= '<span class="keyword">' . $prefix . '</span>';
$i += strlen('@'.$prefix)-1;
$handled = true;
break;
}
}
if (!$handled)
$s .= $c;
} else {
$s .= $c;
}
}

$s = sheaf::r($s, "*>", '<span style="color:#ABABAB;">*&gt;</span>');
$s = sheaf::r($s, "\n", "<br/>");
return $s;
}

/*eof*/ ?>
@@ -0,0 +1,117 @@
<?php /**************************************************************
**
** sheaf/hooks/JavaScript.php
**
** Hook for rendering simple markdown notation for JavaScript code
** snippets.
**
*/

/********************************************************************
*/

function sheaf_hook_JavaScript ($s) {
$s = sheaf::r($s, "\r", "");

$inp = $s;
$s = "";
$flag = array('line' => 0, 'delimited' => 0, 'literal' => 'none', 'escaped' => 0);
$lineComment = 'false';
for ($i = 0; $i < strlen($inp); $i++) {
$c = $inp[$i];

// Handle single-line newline-terminated comments.
if ($c === '#' && $flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="comment">';
$s .= $c;
$flag['line'] = 1;
} else if ($c == "\n" && $flag['line'] == 1) {
$s .= '</span>';
$s .= $c;
$flag['line'] = 0;
}

// Handle string literals.
else if ($c == '"') {
if ($flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="literal">';
$s .= $c;
$flag['literal'] = '"';
} else if ($flag['literal'] == '"') {
$s .= $c;
$s .= '</span>';
$flag['literal'] = 'none';
}
}
else if ($c == "'") {
if ($flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="literal">';
$s .= $c;
$flag['literal'] = "'";
} else if ($flag['literal'] == "'") {
$s .= $c;
$s .= '</span>';
$flag['literal'] = 'none';
}
}

// Defaults.
else if ($c === " ") {
$s .= "&nbsp;";
} else if ($c === "@") {

// Handle built in commands.
$handled = false;
$commands = array(
'function', 'return',
'for', 'while', 'break', 'continue',
'if', 'else'
);
$builtins = array(
'exit',
'print',
'len',
'range',
'max',
'min',
'pow',
'sum',
'int',
'type',
'str',
'dict',
'list',
'tuple',
'None',
'True',
'False'
);
foreach ($builtins as $prefix) {
if (sheaf::startsWith(substr($inp, $i), '@'.$prefix)) {
$s .= '<span class="builtin">' . $prefix . '</span>';
$i += strlen('@'.$prefix)-1;
$handled = true;
break;
}
}
foreach ($commands as $prefix) {
if (sheaf::startsWith(substr($inp, $i), '@'.$prefix)) {
$s .= '<span class="keyword">' . $prefix . '</span>';
$i += strlen('@'.$prefix)-1;
$handled = true;
break;
}
}
if (!$handled)
$s .= $c;
} else {
$s .= $c;
}
}

$s = sheaf::r($s, ">>>", '<span style="color:#ABABAB;">&gt;&gt;&gt;</span>');
$s = sheaf::r($s, "\n", "<br/>");
return $s;
}

/*eof*/ ?>
@@ -0,0 +1,110 @@
<?php /**************************************************************
**
** sheaf/hooks/Python.php
**
** Hook for rendering simple markdown notation for Python code
** snippets.
**
*/

/********************************************************************
*/

function sheaf_hook_Python ($s) {
$s = sheaf::r($s, "\r", "");

$inp = $s;
$s = "";
$flag = array('line' => 0, 'delimited' => 0, 'literal' => 'none', 'escaped' => 0);
$lineComment = 'false';
for ($i = 0; $i < strlen($inp); $i++) {
$c = $inp[$i];

// Handle single-line newline-terminated comments.
if ($c === '#' && $flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="comment">';
$s .= $c;
$flag['line'] = 1;
} else if ($c == "\n" && $flag['line'] == 1) {
$s .= '</span>';
$s .= $c;
$flag['line'] = 0;
}

// Handle string literals.
else if ($c == '"') {
if ($flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="literal">';
$s .= $c;
$flag['literal'] = '"';
} else if ($flag['literal'] == '"') {
$s .= $c;
$s .= '</span>';
$flag['literal'] = 'none';
}
}
else if ($c == "'") {
if ($flag['line'] == 0 && $flag['delimited'] == 0 && $flag['literal'] == 'none') {
$s .= '<span class="literal">';
$s .= $c;
$flag['literal'] = "'";
} else if ($flag['literal'] == "'") {
$s .= $c;
$s .= '</span>';
$flag['literal'] = 'none';
}
}

// Defaults.
else if ($c === " ") {
$s .= "&nbsp;";
} else if ($c === "@") {

// Handle built in commands.
$handled = false;
$commands = array(
'import', 'from', 'pass',
'class', 'def', 'return', 'lambda',
'for', 'while', 'break', 'continue',
'if', 'elif', 'else',
'or', 'and', 'not',
'is', 'in'
);
$builtins = array(
'exit',
'print', 'exec', 'open',
'len', 'range',
'max', 'min', 'sum', 'pow',
'map', 'filter',
'int', 'float', 'type', 'str', 'list', 'set', 'frozenset', 'dict', 'tuple',
'None', 'True', 'False'
);
foreach ($builtins as $prefix) {
if (sheaf::startsWith(substr($inp, $i), '@'.$prefix)) {
$s .= '<span class="builtin">' . $prefix . '</span>';
$i += strlen('@'.$prefix)-1;
$handled = true;
break;
}
}
foreach ($commands as $prefix) {
if (sheaf::startsWith(substr($inp, $i), '@'.$prefix)) {
$s .= '<span class="keyword">' . $prefix . '</span>';
$i += strlen('@'.$prefix)-1;
$handled = true;
break;
}
}
if (!$handled)
$s .= $c;
} else {
$s .= $c;
}
}

$s = sheaf::r($s, ">>>", '<span style="color:#ABABAB;">&gt;&gt;&gt;</span>');
$s = sheaf::r($s, "\n", "<br/>");
return $s;
}

/*eof*/ ?>

0 comments on commit 2b1c4b1

Please sign in to comment.
You can’t perform that action at this time.