Skip to content

Instantly share code, notes, and snippets.

@harryfk
Last active August 29, 2015 14:17
Show Gist options
  • Save harryfk/a0e9c669d0d80a63daf8 to your computer and use it in GitHub Desktop.
Save harryfk/a0e9c669d0d80a63daf8 to your computer and use it in GitHub Desktop.
showdown interview extension
(function () {
var interview = function () {
return [
{ type: 'output', filter: function(source){
var questionRegex = /(<p>)(<strong>)?(Q|speaker): /gi;
return source.replace(questionRegex, function(match, p, s, i) {
var cssClass;
if (i.toLowerCase() == 'q') { cssClass= 'text-question'; }
if (i.toLowerCase() == 'speaker') { cssClass = 'text-speaker'; }
if (s) {
return '<p class="'+cssClass+'">'+s;
}
return '<p class="'+cssClass+'">';
});
}}
];
};
// Client-side export
if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) {
window.Showdown.extensions.interview = interview;
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment