Last active
November 24, 2016 22:03
-
-
Save struberg/7a1cef8c2e8f4d8453086bc7882f0164 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following small changes allows to use < and > in asciidoctor code parts in reveal.js | |
------- | |
(function () { | |
var optionKeys = ['attributes']; | |
var defaultOptions = ['showtitle']; | |
var sections = document.querySelectorAll('[data-asciidoctor]'); | |
var attributes, options; | |
for (var i = 0, len = sections.length; i < len; i++) { | |
var currentAttr = sections[i].getAttribute('data-attributes'); | |
var currentOptions; | |
if (!currentAttr) { | |
if (!attributes) { | |
attributes = sections[i].parentNode.getAttribute('data-attributes'); | |
options = attributes ? Opal.hash2(optionKeys, {attributes: attributes ? attributes.split(",") : defaultOptions}) : attributes; | |
} | |
currentAttr = attributes; | |
currentOptions = options; | |
} else { | |
currentOptions = Opal.hash2(optionKeys, {attributes: currentAttr ? currentAttr.split(",") : defaultOptions}); | |
} | |
var notes = sections[i].querySelector('aside.notes'); | |
/* original: var content = sections[i].innerHTML */ | |
var content = sections[i].innerHTML.replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&'); /*MSX*/ | |
var whiteSpaces = 0; | |
for (var skip = 0; skip < content.length; skip++) { | |
var c = content.charAt(skip); | |
if (c == '\n') { | |
whiteSpaces = 0; | |
} else if (c != ' ' && c != '\t') { | |
break; | |
} else { | |
whiteSpaces++; | |
} | |
} | |
sections[i].innerHTML = Opal.Asciidoctor.$convert(content.trim().replace(new RegExp('\r?\n {' + whiteSpaces + '}', 'g'), '\n'), currentOptions); | |
if (notes) { | |
sections[i].appendChild(notes); | |
} | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment