✪ 1 …
Numbered Code Block

Script key: Numbered Code Block

Posted by @ijunghaertchen

Install

Details

Label ✪ 1 …
Voice Over Numbered Code Block
Script
// Script keys run short Javascripts
// For documentation and examples, visit:
// http://help.agiletortoise.com

// Puts numbers in front of selected lines.
// When more than 10 lines are selected,
// only every fifth line gets a number.
// Also adds comment line on beginning and end
// plus four-space indentation for MarkDown code block

// version 1.0
// by Immo Junghärtchen - twitter: @ijunghaertchen




function enumerate(s){
var temp = new Array();
temp = s.split('\n');

var result = "    --- Example ---\n    \n";
var i;
var z;
if (temp.length<10){
  for(i=0; i<temp.length; i++){
    z=i+1;
    result += "    "+z+" "+temp[i]+"\n";
  }
}
else if(temp.length<100){
  for(i=0; i<temp.length; i++){
    z=i+1;
    if (z%5==0){
      if (z==5){
        result += "    "+z+"  "+temp[i]+"\n";
      }
      else{
        result += "    "+z+" "+temp[i]+"\n";
      }
    }
    else{
      result += "    .  "+temp[i]+"\n";
    }
  }
}
else{
  for(i=0; i<temp.length; i++){
    z=i+1;
    if (z%5==0){
      if (z==5){
        result += "    "+z+"   "+temp[i]+"\n";
      }
      else if(z<100){
        result += "    "+z+"  "+temp[i]+"\n";
      }
      else{
        result += "    "+z+" "+temp[i]+"\n";
      }
    }
    else{
      result += "    .   "+temp[i]+"\n";
    }
  }
}
result += "\n    --- Example End ---\n";
return result;
}
setSelectedText(enumerate(getSelectedText()))

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus