code-line-numbers
Advanced tools
Comparing version 0.0.2 to 0.0.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class CodeLineNumbers { | ||
static addCodeLineNumbers(selector = CodeLineNumbers.DEFAULT_SELECTOR) { | ||
let els = document.querySelectorAll(selector); | ||
els.forEach(el => { | ||
CodeLineNumbers.addLineNumbersTo(el); | ||
}); | ||
var CodeLineNumbers = /** @class */ (function () { | ||
function CodeLineNumbers() { | ||
} | ||
static addCodeLineNumbersOnLoad(selector = CodeLineNumbers.DEFAULT_SELECTOR) { | ||
document.addEventListener("DOMContentLoaded", () => { | ||
CodeLineNumbers.addCodeLineNumbers = function (selector) { | ||
if (selector === void 0) { selector = CodeLineNumbers.DEFAULT_SELECTOR; } | ||
var els = document.querySelectorAll(selector); | ||
for (var i = 0; i < els.length; i++) | ||
CodeLineNumbers.addLineNumbersTo(els[i]); | ||
}; | ||
CodeLineNumbers.addCodeLineNumbersOnLoad = function (selector) { | ||
if (selector === void 0) { selector = CodeLineNumbers.DEFAULT_SELECTOR; } | ||
document.addEventListener("DOMContentLoaded", function () { | ||
CodeLineNumbers.addCodeLineNumbers(selector); | ||
}); | ||
} | ||
static addLineNumbersTo(elCode) { | ||
let lines = elCode.innerHTML.split("\n"); | ||
}; | ||
CodeLineNumbers.addLineNumbersTo = function (elCode) { | ||
var lines = elCode.innerHTML.split("\n"); | ||
if (lines.length === 0 || (lines.length === 1 && lines[0].length === 0)) | ||
return; | ||
let digitsCount = ("" + lines.length).length; | ||
for (let n = 0; n < lines.length; n++) { | ||
let numberWithZeros = "" + n; | ||
var digitsCount = ("" + lines.length).length; | ||
for (var n = 0; n < lines.length; n++) { | ||
var numberWithZeros = "" + n; | ||
if (numberWithZeros.length < digitsCount) { | ||
let zeros = ""; | ||
for (let i = 0; i < digitsCount - numberWithZeros.length; i++) | ||
var zeros = ""; | ||
for (var i = 0; i < digitsCount - numberWithZeros.length; i++) | ||
zeros += "0"; | ||
numberWithZeros = `<span class="hljs-line-numbers__number__zeros">${zeros}</span>${n}`; | ||
numberWithZeros = "<span class=\"hljs-line-numbers__number__zeros\">" + zeros + "</span>" + n; | ||
} | ||
lines[n] = `<span class="hljs-line-numbers__number">${numberWithZeros}</span>` + lines[n]; | ||
lines[n] = "<span class=\"hljs-line-numbers__number\">" + numberWithZeros + "</span>" + lines[n]; | ||
} | ||
elCode.innerHTML = lines.join("\n"); | ||
} | ||
} | ||
CodeLineNumbers.DEFAULT_SELECTOR = "pre > code"; | ||
}; | ||
CodeLineNumbers.DEFAULT_SELECTOR = "pre > code"; | ||
return CodeLineNumbers; | ||
}()); | ||
exports.CodeLineNumbers = CodeLineNumbers; |
{ | ||
"name": "code-line-numbers", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Adding line numbers for code, HighLight.js is supported too", | ||
@@ -5,0 +5,0 @@ "main": "./dist/code-line-numbers.js", |
{ | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"target": "es5", | ||
"module": "commonjs", | ||
@@ -5,0 +5,0 @@ "declaration": true, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6581
81