/**
 * Usage:
 * <script src="ttyplayer.js"></script>
 * <script src="ttyplayer.autoload.js"></script>
 * <div tp-src="./a.rec" tp-cols="120" tp-rows="40" ></div>
 */

;(function() {

var TTYPlayer = window.TTYPlayer

function toInt(x) {
  var y = parseInt(x, 10)
  return isNaN(y) ? null : y
}

function attr(target, name) {
  return target.getAttribute(name)
}

function initAll() {
  const attrSrc = 'tp-src'
  const targets = document.querySelectorAll('[' + attrSrc + ']')

  for (var i = 0; i < targets.length; i++) {
    var target = targets[i]
    var cols = toInt(attr(target, 'tp-cols'))
    var rows = toInt(attr(target, 'tp-rows'))

    new TTYPlayer({
      parent: target,
      cols: cols,
      rows: rows,
    }).load(attr(target, attrSrc))
  }
}

if (document.readyState === 'compvare') {
  initAll()
} else {
  document.addEventListener('DOMContentLoaded', initAll, false)
}

})()

@@ -1,172 +1,4 @@
-/**%0A * Usage:%0A * %3Cscript src=%22ttyplayer.js%22%3E%3C/script%3E%0A * %3Cscript src=%22ttyplayer.autoload.js%22%3E%3C/script%3E%0A * %3Cdiv tp-src=%22./a.rec%22 tp-cols=%22120%22 tp-rows=%2240%22 %3E%3C/div%3E%0A */%0A%0A
 ;(fu
@@ -202,395 +202,1312 @@
 ion 
-initAll() %7B%0A  const attrSrc = 'tp-src'%0A  const targets = document.querySelectorAll('%5B' + attrSrc + '%5D')%0A%0A  for (var i = 0; i %3C targets.length; i++) %7B%0A    var target = targets%5Bi%5D%0A    var cols = toInt(attr(target, 'tp-cols'))%0A    var rows = toInt(attr(target, 'tp-rows'))%0A%0A    new TTYPlayer(%7B%0A      parent: target,%0A      cols: cols,%0A      rows: rows,%0A    %7D).load(attr(target, attrSrc))%0A  %7D
+parseCodeBlock(src) %7B%0A  var options = %7B%7D%0A  src.split('%5Cn').forEach(function(line) %7B%0A    var mathded = line.trim().match(/%5E(%5Cw+)%5Cs*:%5Cs*(.*)$/)%0A    if (!mathded) return%0A    options%5Bmathded%5B1%5D%5D = mathded%5B2%5D%0A  %7D)%0A  return options%0A%7D%0A%0Afunction each(arrayLike, fun) %7B%0A  for (var i = 0, len = arrayLike.length; i %3C len; i++) %7B%0A    fun(arrayLike%5Bi%5D, i)%0A  %7D%0A%7D%0A%0Afunction initAll() %7B%0A  var attrSrc = 'tp-src'%0A%0A  /**%0A   * %3Cdiv tp-src=%22./a.rec%22 tp-cols=%22120%22 tp-rows=%2240%22 %3E%3C/div%3E%0A   */%0A  each(document.querySelectorAll('%5B' + attrSrc + '%5D'), function(target) %7B%0A    var cols = toInt(attr(target, 'tp-cols'))%0A    var rows = toInt(attr(target, 'tp-rows'))%0A%0A    new TTYPlayer(%7B%0A      parent: target,%0A      cols: cols,%0A      rows: rows,%0A    %7D).load(attr(target, attrSrc))%0A  %7D)%0A%0A  /**%0A   * %60%60%60tty%0A   * src: path/to/your.rec%0A   * %60%60%60%0A   */%0A  each(document.querySelectorAll('.language-tty'), function(codeBlock) %7B%0A    var pre = codeBlock.parentNode%0A    var doc = pre.parentNode%0A    if (pre.tagName.toUpperCase() !== 'PRE') return%0A%0A    var options = parseCodeBlock(codeBlock.textContent)%0A    var div = document.createElement('div')%0A    doc.insertBefore(div, pre)%0A    pre.style.display = 'none'%0A    new TTYPlayer(%7B%0A      parent: div,%0A      cols: toInt(options.cols),%0A      rows: toInt(options.rows),%0A    %7D).load(options.src)%0A  %7D)
 %0A%7D%0A%0A

use in markdown