Skip to content

Commit

Permalink
Support for ol, ul simple writing in multislide
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele Beltrame committed Nov 6, 2011
1 parent 58d4fa1 commit 6e6e0f7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README
@@ -1,6 +1,6 @@
Presentazion
HTML/JS software to present slides in DWIM way
Version 0.50 - November 2nd, 2011
Version 0.50 - November 6th, 2011
First released on November 1st, 2011
Author: Michele Beltrame
License: Artistic (Perl5) or GPL3, at user choice
Expand Down
59 changes: 50 additions & 9 deletions presentazion.js
@@ -1,6 +1,6 @@
/* Presentazion
HTML/JS software to present slides in DWIM way
Version 0.50 - November 2nd, 2011
Version 0.50 - November 6th, 2011
First released on November 1st, 2011
Author: Michele Beltrame
License: Artistic (Perl5) or GPL3, at user choice
Expand Down Expand Up @@ -108,6 +108,9 @@ Presentazion = {
$(".slide ol").wrap('<div class="olwrapper">');
},

// Convert less-verbose multislides into slides
// This code should be BURNED and rewritten, but I'd like
// to get things to work before
preprocess_multislides : function() {
$(".multislide").each(function(i, el) {
// Split multislide on separators
Expand All @@ -121,15 +124,12 @@ Presentazion = {

// Process lines
var lines = shtml.split("\n");
//var nlastline = lines.length - 1;
//var j = 0;
var in_code = 0;
//while ( j <= nlastline ) {
var in_code = 0; var in_ul = 0; var in_ol = 0;
$.each(lines, function(j, line) {
// If a line begins with at least a \s, then it's code
// and it's subsequents are as well, if they still begin with \s
if ( lines[j].match(/^(?:\s{4}|\t)/) ) {
lines[j] = lines[j].replace(/^(?:\s{4}|\t)/, "");
if ( line.match(/^(?:\s{4}|\t)/) ) {
lines[j] = line.replace(/^(?:\s{4}|\t)/, "");
if ( !in_code ) {
lines[j] = '<div class="codewrapper"><pre>' + "\n" + lines[j];
in_code = 1;
Expand All @@ -146,16 +146,57 @@ Presentazion = {
}
}

// ULs
if ( line.match(/^\*\s/) ) {
lines[j] = line.replace(/^\*\s/, "");
lines[j] = "<li>" + lines[j] + "</li>";
if ( !in_ul ) {
lines[j] = '<ul>' + "\n" + lines[j];
in_ul = 1;
}
return true;
} else {
if ( in_ul ) {
lines[j] += "\n" + '</ul>';
in_ul = 0;
return true;
}
}


// OLs
if ( line.match(/^\#\s/) ) {
lines[j] = line.replace(/^\#\s/, "");
lines[j] = "<li>" + lines[j] + "</li>";
if ( !in_ol ) {
lines[j] = '<ol>' + "\n" + lines[j];
in_ol = 1;
}
return true;
} else {
if ( in_ol ) {
lines[j] += "\n" + '</ol>';
in_ol = 0;
return true;
}
}

// Wrap lonesome lines in <p>
// a lonesome lines does not begin with (<) (TODO: improve this)
if ( !lines[j].match("^<") ) {
lines[j] = "<p>" + lines[j] + "</p>";
if ( !line.match("^<") ) {
lines[j] = "<p>" + line + "</p>";
}
});
// If we closed with code, then add closing tags
if ( in_code ) {
lines[lines.length-1] += "\n</pre></div>";
}
if ( in_ul ) {
lines[lines.length-1] += "\n</ul>";
}
if ( in_ol ) {
lines[lines.length-1] += "\n</ol>";
}

// Add to the dOM
$(".multislide").before('<div class="slide">' + lines.join("\n") + '</div>');
Expand Down

0 comments on commit 6e6e0f7

Please sign in to comment.