has the class
// feature-math
$( function() {
if ( $( "body.feature-math:not(.feature-nomath)" ).length ) {
renderMathInElement(document.body);
}
});
// Render abcjs sheet music, but only if the has the class
// feature-music. Do this by removing the
// and replacing it with a
which will be used to hold the
// generated sheet music. Remark's code syntax highlighting transforms the
// block into a bunch of
//
K: Emin
// one per line, so we have to reassemble those to get back linebreaks.
$( function() {
if ( $( "body.feature-music:not(.feature-nomusic)" ).length ) {
$( "code.language-abc, code.abc" ).each(function(i, e){
var $this = $(this);
var abc = $this.text();
if ( $this.hasClass("remark-code") ) {
abc = "";
$this.children().each(function(i, e) {
abc += "\n" + $(this).text();
});
abc = abc.trim();
}
var p = $this.parent().before('
has the class feature-tweetquote and the blockquote ends
// with a twitter permalink URL.
$( function() {
if ( $( "body.feature-tweetquote:not(.feature-notweetquote)" ).length ) {
$("blockquote p:first-child a[href*='twitter.com']").each(function(i, e){
$(this.parentElement.parentElement).addClass("tweet sans-serif mw6");
$(this).addClass("no-underline b");
$(this).prepend('');
var m = $(this).attr('href').match(/twitter.com\/([^\/]*)\//);
if (m.length > 1) {
$(this).append(' @' + m[1] + '');
}
});
}
});
// Render perspective book images, if has the class
// feature-3dbook-covers
$( function() {
$( "body.feature-3dbook-covers article a" ).has( "img[src~='3dbook']" ).each(function(i, e) {
$( this ).addClass("book");
$( this ).parent().addClass("books");
});
});
// Highlight code listings, if has the class
// feature-highlight
$( function() {
if ( $( "body.feature-highlight:not(.feature-nohighlight)" ).length ) {
hljs.initHighlightingOnLoad();
}
});
/* Turn images into figures with captions. Several scenarios are handled, in
* order:
* If the img is followed by an , then transform the into a caption.
* If the img has a title, use that as the caption.
* If the img has an alt, use that.
* The following features have to be enabled:
* - feature-figcaption has to be enabled or the whole thing is disabled
* - feature-figcaption-hidden makes the captions invisible till you hover
* - feature-fignum adds figure numbering
* - feature-figlink adds automatic links of text like "Figure 4"
*/
$( function() {
$("body.feature-figcaption:not(.feature-nofigcaption) article img").each(function(i, e) {
var $this = $(this);
// Don't put captions on images that have URL fragment pseudo-classes.
if ( $this.attr('src').match(/#/) ) return;
var $txt = false;
if ( $this.next().is("em") ) {
$txt = $this.next().html();
$this.next().remove();
} else {
$txt = $this.attr('title') ? $this.attr('title')
: $this.attr('alt') ? $this.attr('alt')
: false;
}
if ( $txt ) {
var $fig = $this.wrap('')
.after('' + $txt + '')
.parent();
}
});
if ( $("body.feature-figlink").length ) {
$("article p, article li").each(function(i, e) {
var $old = $(this).html();
var $new = $old.replace(/Figure\s+(\d+)/g, 'Figure $1');
if ( $old !== $new ) {
$(this).html($new);
}
});
}
});
/* Add captions to tables.
* If the table is followed by a
, then transform the into a caption.
* The following features have to be enabled:
* - feature-tablecaption has to be enabled or the whole thing is disabled
* - feature-fignum adds table numbering
* - feature-figlink adds automatic links of text like "Table 4"
*/
$( function() {
$("body.feature-tablecaption article table").each(function(i, e) {
var $this = $(this);
var $txt = false;
if ( $this.next().is("p") ) {
if ( $this.next().children().first().is("em:only-child") ) {
$txt = $this.next().children().first().html();
$this.next().remove();
}
}
if ( $txt ) {
$this.prepend('
' + $txt + '
');
}
});
if ( $("body.feature-figlink").length ) {
$("article p, article li").each(function(i, e) {
var $old = $(this).html();
var $new = $old.replace(/Table\s+(\d+)/g, 'Table $1');
if ( $old !== $new ) {
$(this).html($new);
}
});
}
});