.
, ace.js.
, , , .
, , :
var line = 1;
code = code.replace(/^/gm, function() {
return '<span class="line-number-position">​<span class="line-number">' + line++ + '</span></span>';
});
/^/gm "" span-in-span.
​ - , , , Firefox , .
line-number-positionand line-numberare CSS classes such as:
.line-number-position {
position: relative;
top: 0;
}
.line-number {
position: absolute;
text-align: right;
right: 17px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
font-size: 12px;
}
Yes, there are some magic numbers to match ace formatting, but the point is to put a relative positional zero size at the beginning of each line and use it as a control point to add an absolute position in the left margin.
Works with current browsers Chrome, Safari, Firefox and Opera.
source
share