From e693717f2aa2d65f8f0cf6412a01084280fc2c9a Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Sun, 28 Oct 2012 18:09:54 -0400
Subject: update syntax highlight after editing (#210), move markdown and
highlight scripts from lib to plugin
---
plugin/markdown/markdown.js | 32 +++++++++++++++++++++++
plugin/markdown/showdown.js | 62 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 94 insertions(+)
create mode 100644 plugin/markdown/markdown.js
create mode 100644 plugin/markdown/showdown.js
(limited to 'plugin/markdown')
diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js
new file mode 100644
index 0000000..07ffd80
--- /dev/null
+++ b/plugin/markdown/markdown.js
@@ -0,0 +1,32 @@
+// From https://gist.github.com/1343518
+// Modified by Hakim to handle Markdown indented with tabs
+(function(){
+
+ if( typeof Showdown === 'undefined' ) {
+ throw 'The reveal.js Markdown plugin requires Showdown to be loaded';
+ }
+
+ var sections = document.querySelectorAll( '[data-markdown]' );
+
+ for( var i = 0, len = sections.length; i < len; i++ ) {
+ var section = sections[i];
+
+ var template = section.querySelector( 'script' );
+
+ // strip leading whitespace so it isn't evaluated as code
+ var text = ( template || section ).innerHTML;
+
+ var leadingWs = text.match(/^\n?(\s*)/)[1].length,
+ leadingTabs = text.match(/^\n?(\t*)/)[1].length;
+
+ if( leadingTabs > 0 ) {
+ text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' );
+ }
+ else if( leadingWs > 1 ) {
+ text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' );
+ }
+
+ section.innerHTML = (new Showdown.converter()).makeHtml(text);
+ }
+
+})();
\ No newline at end of file
diff --git a/plugin/markdown/showdown.js b/plugin/markdown/showdown.js
new file mode 100644
index 0000000..3f280f4
--- /dev/null
+++ b/plugin/markdown/showdown.js
@@ -0,0 +1,62 @@
+//
+// showdown.js -- A javascript port of Markdown.
+//
+// Copyright (c) 2007 John Fraser.
+//
+// Original Markdown Copyright (c) 2004-2005 John Gruber
+//
"+d+"\n
",t(d)+e}),a=a.replace(/~0/,""),a},s=function(a){return a+="~0",a=a.replace(/\n```(.*)\n([^`]+)\n```/g,function(a,b,c){var d=b,e=c;return e=v(e),e=F(e),e=e.replace(/^\n+/g,""),e=e.replace(/\n+$/g,""),e=""+e+"\n
",t(e)}),a=a.replace(/~0/,""),a},t=function(a){return a=a.replace(/(^\n+|\n+$)/g,""),"\n\n~K"+(c.push(a)-1)+"K\n\n"},u=function(a){return a=a.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,function(a,b,c,d,e){var f=d;return f=f.replace(/^([ \t]*)/g,""),f=f.replace(/[ \t]*$/g,""),f=v(f),b+""+f+"
"}),a},v=function(a){return a=a.replace(/&/g,"&"),a=a.replace(//g,">"),a=G(a,"*_{}[]\\",!1),a},w=function(a){return a=a.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,"$2"),a=a.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,"$2"),a},x=function(a){return a=a.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,function(a,b){var c=b;return c=c.replace(/^[ \t]*>[ \t]?/gm,"~0"),c=c.replace(/~0/g,""),c=c.replace(/^[ \t]+$/gm,""),c=h(c),c=c.replace(/(^|\n)/g,"$1 "),c=c.replace(/(\s*[^\r]+?<\/pre>)/gm,function(a,b){var c=b;return c=c.replace(/^ /mg,"~0"),c=c.replace(/~0/g,""),c}),t("\n"+c+"\n")}),a},y=function(a){a=a.replace(/^\n+/g,""),a=a.replace(/\n+$/g,"");var b=a.split(/\n{2,}/g),d=new Array,e=b.length;for(var f=0;f=0?d.push(g):g.search(/\S/)>=0&&(g=i(g),g=g.replace(/^([ \t]*)/g," "),g+="
",d.push(g))}e=d.length;for(var f=0;f=0){var h=c[RegExp.$1];h=h.replace(/\$/g,"$$$$"),d[f]=d[f].replace(/~K\d+K/,h)}return d.join("\n\n")},z=function(a){return a=a.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&"),a=a.replace(/<(?![a-z\/?\$!])/gi,"<"),a},A=function(a){return a=a.replace(/\\(\\)/g,H),a=a.replace(/\\([`*_{}\[\]()>#+-.!])/g,H),a},B=function(a){return a=a.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,'$1'),a=a.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,function(a,b){return C(D(b))}),a},C=function(a){function b(a){var b="0123456789ABCDEF",c=a.charCodeAt(0);return b.charAt(c>>4)+b.charAt(c&15)}var c=[function(a){return""+a.charCodeAt(0)+";"},function(a){return""+b(a)+";"},function(a){return a}];return a="mailto:"+a,a=a.replace(/./g,function(a){if(a=="@")a=c[Math.floor(Math.random()*2)](a);else if(a!=":"){var b=Math.random();a=b>.9?c[2](a):b>.45?c[1](a):c[0](a)}return a}),a=''+a+"",a=a.replace(/">.+:/g,'">'),a},D=function(a){return a=a.replace(/~E(\d+)E/g,function(a,b){var c=parseInt(b);return String.fromCharCode(c)}),a},E=function(a){return a=a.replace(/^(\t|[ ]{1,4})/gm,"~0"),a=a.replace(/~0/g,""),a},F=function(a){return a=a.replace(/\t(?=\t)/g," "),a=a.replace(/\t/g,"~A~B"),a=a.replace(/~B(.+?)~A/g,function(a,b,c){var d=b,e=4-d.length%4;for(var f=0;f + + + + + + reveal.js - The HTML Presentation Framework + + + + + + + + + + + + + + + + + + + + + ++ + ++ + + + + + + + diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index b1660a1..8d40019 100644 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -6,11 +6,7 @@ throw 'The reveal.js Markdown plugin requires Showdown to be loaded'; } - var sections = document.querySelectorAll( '[data-markdown]' ); - - for( var i = 0, len = sections.length; i < len; i++ ) { - var section = sections[i]; - var notes = section.querySelector( 'aside.notes' ); + var stripLeadingWhitespace = function(section) { var template = section.querySelector( 'script' ); @@ -27,11 +23,125 @@ text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' ); } - section.innerHTML = (new Showdown.converter()).makeHtml(text); + return text; + + }; + + var slidifyMarkdown = function(markdown, separator, vertical) { + + separator = separator || '^\n---\n$'; + + var reSeparator = new RegExp(separator + (vertical ? '|' + vertical : ''), 'mg'), + reHorSeparator = new RegExp(separator), + matches, + lastIndex = 0, + isHorizontal, + wasHorizontal = true, + content, + sectionStack = [], + markdownSections = ''; + + // iterate until all blocks between separators are stacked up + while( matches = reSeparator.exec(markdown) ) { + + // determine direction (horizontal by default) + isHorizontal = reHorSeparator.test(matches[0]); + + if( !isHorizontal && wasHorizontal ) { + // create vertical stack + sectionStack.push([]); + } + + // pluck slide content from markdown input + content = markdown.substring(lastIndex, matches.index); + + if( isHorizontal && wasHorizontal ) { + // add to horizontal stack + sectionStack.push(content); + } else { + // add to vertical stack + sectionStack[sectionStack.length-1].push(content); + } + + lastIndex = reSeparator.lastIndex; + wasHorizontal = isHorizontal; + + } + + // add the remaining slide + (wasHorizontal ? sectionStack : sectionStack[sectionStack.length-1]).push(markdown.substring(lastIndex)); + + // flatten the hierarchical stack, and insert +tags + for( var k = 0, klen = sectionStack.length; k < klen; k++ ) { + markdownSections += typeof sectionStack[k] === 'string' + ? ' ' + sectionStack[k] + ' ' + : ''; + } + + return markdownSections; + }; + + var queryMarkdownSlides = function() { + + var sections = document.querySelectorAll( '[data-markdown]'), + section; + + for( var j = 0, jlen = sections.length; j < jlen; j++ ) { + + section = sections[j]; + + if( section.getAttribute('data-markdown').length ) { + + var xhr = new XMLHttpRequest(), + url = section.getAttribute('data-markdown'); + + xhr.onreadystatechange = function () { + if( xhr.readyState === 4 ) { + section.outerHTML = slidifyMarkdown( xhr.responseText, section.getAttribute('data-separator'), section.getAttribute('data-vertical') ); + } + }; + + xhr.open('GET', url, false); + xhr.send(); + + } else if( section.getAttribute('data-separator') ) { + + var markdown = stripLeadingWhitespace(section); + section.outerHTML = slidifyMarkdown( markdown, section.getAttribute('data-separator'), section.getAttribute('data-vertical') ); + + } + } + + querySlides(); + + }; + + var querySlides = function() { + + var sections = document.querySelectorAll( '[data-markdown]'); + + for( var j = 0, jlen = sections.length; j < jlen; j++ ) { + + makeHtml(sections[j]); + + } + + }; + + var makeHtml = function(section) { + + var notes = section.querySelector( 'aside.notes' ); + + var markdown = stripLeadingWhitespace(section); + + section.innerHTML = (new Showdown.converter()).makeHtml(markdown); if( notes ) { section.appendChild( notes ); } - } -})(); \ No newline at end of file + }; + + queryMarkdownSlides(); + +})(); -- cgit v1.2.3 From 7207122c75137c0d2c7dfd0e1d9a1a0e9bf0a88f Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Wed, 30 Jan 2013 00:09:02 +0100 Subject: Slightly refactored "slidify" flow --- plugin/markdown/markdown.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugin/markdown') diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index 8d40019..ae4d08b 100644 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -81,7 +81,7 @@ return markdownSections; }; - var queryMarkdownSlides = function() { + var querySlidingMarkdown = function() { var sections = document.querySelectorAll( '[data-markdown]'), section; @@ -112,11 +112,9 @@ } } - querySlides(); - }; - var querySlides = function() { + var queryMarkdownSlides = function() { var sections = document.querySelectorAll( '[data-markdown]'); @@ -142,6 +140,8 @@ }; + querySlidingMarkdown(); + queryMarkdownSlides(); })(); -- cgit v1.2.3 From f095af212ee2b6009412a89fe17ae46860efd8df Mon Sep 17 00:00:00 2001 From: asmod3us Date: Tue, 26 Feb 2013 16:06:18 +0100 Subject: Update plugin/markdown/markdown.js Use textContent instead of innerHTML to prevent encoding of certain characters in Markdown code blocks.--- plugin/markdown/markdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin/markdown') diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index ae4d08b..39e1168 100644 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -11,7 +11,7 @@ var template = section.querySelector( 'script' ); // strip leading whitespace so it isn't evaluated as code - var text = ( template || section ).innerHTML; + var text = ( template || section ).textContent; var leadingWs = text.match(/^\n?(\s*)/)[1].length, leadingTabs = text.match(/^\n?(\t*)/)[1].length; -- cgit v1.2.3 From f9f17be01473bd80e8f1b6431c6070c4005e1164 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Wed, 27 Feb 2013 15:01:30 -0500 Subject: merge external markdown support, move example to plugin (#329) --- demo.md | 29 ----------- index-markdown.html | 116 ------------------------------------------- plugin/markdown/example.html | 97 ++++++++++++++++++++++++++++++++++++ plugin/markdown/example.md | 29 +++++++++++ 4 files changed, 126 insertions(+), 145 deletions(-) delete mode 100644 demo.md delete mode 100644 index-markdown.html create mode 100644 plugin/markdown/example.html create mode 100644 plugin/markdown/example.md (limited to 'plugin/markdown') diff --git a/demo.md b/demo.md deleted file mode 100644 index 1efe5f9..0000000 --- a/demo.md +++ /dev/null @@ -1,29 +0,0 @@ -# External markdown - - - -## Slide 1.1 - -Content 1.1 - - -## Slide 1.2 - -Content 1.2 - - - -## Slide 2 - -Content 2.1 - - - -## Slide 3.1 - -Content 3.1 - - -## Slide 3.2 - -Content 3.2 diff --git a/index-markdown.html b/index-markdown.html deleted file mode 100644 index 367c879..0000000 --- a/index-markdown.html +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - - ' + sectionStack[k].join(' ') + ' reveal.js - The HTML Presentation Framework - - - - - - - - - - - - - - - - - - - - - -- - -- - - - - - - - diff --git a/plugin/markdown/example.html b/plugin/markdown/example.html new file mode 100644 index 0000000..b4e7f91 --- /dev/null +++ b/plugin/markdown/example.html @@ -0,0 +1,97 @@ + + + + + + + -reveal.js - Markdown Demo + + + + + + + ++ ++ + + + + + + + diff --git a/plugin/markdown/example.md b/plugin/markdown/example.md new file mode 100644 index 0000000..e988dd9 --- /dev/null +++ b/plugin/markdown/example.md @@ -0,0 +1,29 @@ +# Markdown Demo + + + +## External 1.1 + +Content 1.1 + + +## External 1.2 + +Content 1.2 + + + +## External 2 + +Content 2.1 + + + +## External 3.1 + +Content 3.1 + + +## External 3.2 + +Content 3.2 -- cgit v1.2.3 +