(function (sunlight, document, undefined){ if (sunlight === undefined) { throw "Include sunlight.js before including plugin files" } function getLineCount(node){ var lastTextNode = function getLastNode(node){ if (!node.lastChild) { return null ; } if (node.lastChild.nodeType === 3) { return node.lastChild; } return getLastNode(node.lastChild); } (node) || { lastChild: ""} ; return _AN_Read_length("length", _AN_Call_replace("replace", node.innerHTML, /[^\n]/g, "")) - /\n$/.test(_AN_Read_nodevalue("nodeValue", lastTextNode)); } sunlight.bind("afterHighlightNode", function (context){ var lineContainer, lineCount, lineHighlightOverlay, currentLineOverlay, lineHighlightingEnabled, i, eol, link, name; if (!this.options.lineNumbers) { return ; } if (this.options.lineNumbers === "automatic" && sunlight.util.getComputedStyle(context.node, "display") !== "block") { return ; } lineContainer = _AN_Call_createelement("createElement", document, "pre"); lineCount = getLineCount(context.node); lineHighlightingEnabled = _AN_Read_length("length", this.options.lineHighlight) > 0; if (lineHighlightingEnabled) { lineHighlightOverlay = _AN_Call_createelement("createElement", document, "div"); lineHighlightOverlay.className = this.options.classPrefix + "line-highlight-overlay"; } lineContainer.className = this.options.classPrefix + "line-number-margin"; eol = document.createTextNode(sunlight.util.eol); for (i = this.options.lineNumberStart; i <= this.options.lineNumberStart + lineCount; i++ ){ link = _AN_Call_createelement("createElement", document, "a"); name = (context.node.id? context.node.id: this.options.classPrefix + context.count) + "-line-" + i; _AN_Call_setattribute("setAttribute", link, "name", name); _AN_Call_setattribute("setAttribute", link, "href", "#" + name); _AN_Call_appendchild("appendChild", link, document.createTextNode(i)); _AN_Call_appendchild("appendChild", lineContainer, link); _AN_Call_appendchild("appendChild", lineContainer, eol.cloneNode(false )); if (lineHighlightingEnabled) { currentLineOverlay = _AN_Call_createelement("createElement", document, "div"); if (sunlight.util.contains(this.options.lineHighlight, i)) { currentLineOverlay.className = this.options.classPrefix + "line-highlight-active"; } _AN_Call_appendchild("appendChild", lineHighlightOverlay, currentLineOverlay); } } context.codeContainer.insertBefore(lineContainer, context.codeContainer.firstChild); if (lineHighlightingEnabled) { _AN_Call_appendchild("appendChild", context.codeContainer, lineHighlightOverlay); } context.codeContainer.style.borderWidth = "1px"; context.codeContainer.style.borderStyle = "solid"; } ); sunlight.globalOptions.lineNumbers = "automatic"; sunlight.globalOptions.lineNumberStart = 1; sunlight.globalOptions.lineHighlight = [] ; } (this.Sunlight, document));