@@ -22,7 +22,7 @@ var CodeMirror = (function() {
2222 '<div style="position: relative">' + // Set to the height of the text, causes scrolling
2323 '<pre style="position: absolute; visibility: hidden">' + // To measure line/char size
2424 '<span>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</span></pre>' +
25- '<div style="position: absolute ">' + // Moved around its parent to cover visible view
25+ '<div style="position: relative ">' + // Moved around its parent to cover visible view
2626 '<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' +
2727 '<div style="overflow: hidden; position: absolute; width: 0; left: 0">' + // Wraps and hides input textarea
2828 '<textarea style="height: 1px; position: absolute;" wrap="off"></textarea></div>' +
@@ -134,6 +134,7 @@ var CodeMirror = (function() {
134134 markText : operation ( function ( a , b , c ) { return operation ( markText ( a , b , c ) ) ; } ) ,
135135 setMarker : addGutterMarker ,
136136 clearMarker : removeGutterMarker ,
137+ setLineClass : operation ( setLineClass ) ,
137138 lineInfo : lineInfo ,
138139 addWidget : function ( pos , node , scroll ) {
139140 var pos = localCoords ( clipPos ( pos ) , true ) ;
@@ -728,6 +729,7 @@ var CodeMirror = (function() {
728729 }
729730 else {
730731 node . innerHTML = lines [ j ] . getHTML ( ch1 , ch2 , false ) ;
732+ node . className = lines [ j ] . className || "" ;
731733 node = node . nextSibling ;
732734 }
733735 }
@@ -957,6 +959,20 @@ var CodeMirror = (function() {
957959 line . gutterMarker = null ;
958960 updateGutter ( ) ;
959961 }
962+ function setLineClass ( line , className ) {
963+ if ( typeof line == "number" ) {
964+ var no = line ;
965+ line = lines [ clipLine ( line ) ] ;
966+ }
967+ else {
968+ var no = indexOf ( lines , line ) ;
969+ if ( no == - 1 ) return null ;
970+ }
971+ line . className = className ;
972+ changes . push ( { from : no , to : no + 1 } ) ;
973+ return line ;
974+ }
975+
960976 function lineInfo ( line ) {
961977 if ( typeof line == "number" ) {
962978 var n = line ;
@@ -1459,7 +1475,7 @@ var CodeMirror = (function() {
14591475 this . styles = styles || [ text , null ] ;
14601476 this . stateAfter = null ;
14611477 this . text = text ;
1462- this . marked = null ; this . gutterMarker = null ;
1478+ this . marked = this . gutterMarker = this . className = null ;
14631479 }
14641480 Line . prototype = {
14651481 // Replace a piece of a line, keeping the styles around it intact.
@@ -1543,7 +1559,9 @@ var CodeMirror = (function() {
15431559 // Produces an HTML fragment for the line, taking selection,
15441560 // marking, and highlighting into account.
15451561 getHTML : function ( sfrom , sto , includePre ) {
1546- var html = includePre ? [ "<pre>" ] : [ ] ;
1562+ var html = [ ] ;
1563+ if ( includePre )
1564+ html . push ( this . className ? '<pre class="' + this . className + '">' : "<pre>" ) ;
15471565 function span ( text , style ) {
15481566 if ( ! text ) return ;
15491567 if ( style ) html . push ( '<span class="' , style , '">' , htmlEscape ( text ) , "</span>" ) ;
0 commit comments