Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing syntax highlighting in static mode and PDF output

  • Loading branch information...
commit 00f52a9c4a09a6e3073b18e6c5fb5501d1641fde 1 parent ea6046a
Martin Grund grundprinzip authored
9 lib/showoff.rb
View
@@ -394,6 +394,11 @@ def index(static=false)
if static
@title = ShowOffUtils.showoff_title
@slides = get_slides_html(static)
+
+ # Identify which languages to bundle for highlighting
+ @languages = []
+ @languages += @slides.scan(/<pre class="(sh_.*?\w)"/).uniq.map{ |w| "sh_lang/#{w[0]}.min.js"}
+
@asset_path = "./"
end
erb :index
@@ -453,6 +458,10 @@ def pdf(static=true)
@slides = get_slides_html(static, true)
@no_js = false
+ # Identify which languages to bundle for highlighting
+ @languages = []
+ @languages += @slides.scan(/<pre class="(sh_.*?\w)"/).uniq.map{ |w| "/sh_lang/#{w[0]}.min.js"}
+
html = erb :onepage
# TODO make a random filename
2  public/js/onepage.js
View
@@ -1,4 +1,4 @@
function setupOnePage() {
- sh_highlightDocument('/js/sh_lang/', '.min.js')
+ sh_highlightDocument();
centerSlides($("#slides > .slide"))
}
21 public/js/showoff.js
View
@@ -28,6 +28,8 @@ function setupPreso(load_slides, prefix) {
}
preso_started = true
+
+ // Load slides fetches images
loadSlidesBool = load_slides
loadSlidesPrefix = prefix
loadSlides(loadSlidesBool, loadSlidesPrefix)
@@ -64,7 +66,7 @@ function loadSlides(load_slides, prefix) {
function initializePresentation(prefix) {
// unhide for height to work in static mode
- $("#slides").show();
+ $("#slides").show();
//center slides offscreen
centerSlides($('#slides > .slide'))
@@ -90,8 +92,19 @@ function initializePresentation(prefix) {
slidesLoaded = true
}
setupSlideParamsCheck();
- sh_highlightDocument(prefix+'/js/sh_lang/', '.min.js')
+ try {
+ sh_highlightDocument(prefix+'/js/sh_lang/', '.min.js')
+ } catch(e) {
+ sh_highlightDocument();
+ }
$("#preso").trigger("showoff:loaded");
+
+ // Add any initialization hook there is provided
+ $.each(ShowOff.initCallbacks, function(idx, cb){
+ if (typeof(cb) == "function")
+ cb();
+ });
+
}
function centerSlides(slides) {
@@ -101,7 +114,7 @@ function centerSlides(slides) {
}
function centerSlide(slide) {
- var slide_content = $(slide).children(".content").first()
+ var slide_content = $(slide).find(".content").first()
var height = slide_content.height()
var mar_top = (0.5 * parseFloat($(slide).height())) - (0.5 * parseFloat(height))
if (mar_top < 0) {
@@ -117,7 +130,7 @@ function setupMenu() {
var menu = new ListMenu()
slides.each(function(s, elem) {
- content = $(elem).children(".content")
+ content = $(elem).find(".content")
shortTxt = $(content).text().substr(0, 20)
path = $(content).attr('ref').split('/')
currSlide += 1
4 views/header.erb
View
@@ -25,6 +25,10 @@
<link type="text/css" href="<%= @asset_path %>css/theme/ui.all.css" media="screen" rel="stylesheet" />
<link type="text/css" href="<%= @asset_path %>css/sh_style.css" rel="stylesheet" >
+<% @languages.each do |l| %>
+ <script type="text/javascript" src="<%= @asset_path %>js/<%= l %>"></script>
+<% end %>
+
<% css_files.each do |css_file| %>
<link rel="stylesheet" href="file/<%= css_file %>" type="text/css"/>
<% end %>
2  views/onepage.erb
View
@@ -15,7 +15,7 @@
<%= inline_css(css_files) %>
<% if !@no_js %>
- <%= inline_js(['jquery-1.4.2.min.js', 'jquery-print.js', 'showoff.js', 'onepage.js', 'sh_main.min.js', 'core.js', 'showoffcore.js'], 'public/js') %>
+ <%= inline_js(['jquery-1.4.2.min.js', 'jquery-print.js', 'showoff.js', 'onepage.js', 'sh_main.min.js', 'core.js', 'showoffcore.js'] + @languages, 'public/js') %>
<script type="text/javascript">
$(document).ready(function() {
setupOnePage()
Please sign in to comment.
Something went wrong with that request. Please try again.