@@ -132,24 +132,29 @@ const processPackages = function(code) {
132132 return code . replace ( / ( < c o d e c l a s s = " p (?: e r ) ? l k e y w o r d " > ( u s e | p a c k a g e | r e q u i r e ) < \/ c o d e > < c o d e c l a s s = " p (?: e r ) ? l p l a i n " > ) ( [ A - Z _ a - z ] [ 0 - 9 A - Z _ a - z ] * (?: : : [ 0 - 9 A - Z _ a - z ] + ) * ) ( .* ?< \/ c o d e > ) / g, replace_pattern ) ;
133133} ;
134134
135- const getCodeLinesHtml = Renderer . prototype . getCodeLinesHtml ;
136- Renderer . prototype . getCodeLinesHtml = function ( ) {
137- // the syntax highlighter has a bug that strips spaces from the first line.
138- // replace any leading whitespace with an entity, preventing that.
139- // html = html.replace(/^ /, " ");
140- // html = html.replace(/^\t/, "	");
141- let html = getCodeLinesHtml . apply ( this , arguments ) ;
142- return processPackages . call ( this , html ) ;
135+ const processUrls = Renderer . prototype . processUrls ;
136+ Renderer . prototype . processUrls = function ( html , ...args ) {
137+ html = processPackages . apply ( this , [ html ] ) ;
138+ html = processUrls . apply ( this , [ html , ...args ] ) ;
139+ return html ;
143140} ;
144141
145142const getHtml = Renderer . prototype . getHtml ;
146- Renderer . prototype . getHtml = function ( ) {
147- let html = getHtml . call ( this ) ;
143+ Renderer . prototype . getHtml = function ( ... args ) {
144+ let html = getHtml . call ( this , ... args ) ;
148145 html = html . replace ( / \s + ( < ( t b o d y | t a b l e | d i v ) \b ) / g, '$1' ) ;
149146 html = html . replace ( / ( < \/ ( t b o d y | t a b l e | d i v ) > ) \s + / g, '$1' ) ;
150147 return html ;
151148} ;
152149
150+ const wrapLine = Renderer . prototype . wrapLine ;
151+ Renderer . prototype . wrapLine = function ( lineIndex , lineNumber , lineHtml ) {
152+ if ( lineHtml == ' ' ) {
153+ lineHtml = '' ;
154+ }
155+ return wrapLine . call ( this , lineIndex , lineNumber , lineHtml ) ;
156+ } ;
157+
153158// on pod pages, set the language to perl if no other language is set
154159CODE: for ( const code of document . querySelectorAll ( ".pod pre > code" ) ) {
155160 for ( const className of code . classList ) {
@@ -231,14 +236,44 @@ for (const code of document.querySelectorAll(".content pre > code")) {
231236
232237 config . package_target_type = source ? 'source' : 'pod' ;
233238
234- // highlighter strips leading blank lines, throwing off line numbers.
235- // add a blank line for the highlighter to strip
236- // const html = code.innerHTML;
237- // if (html.match(/^ *\n/)) {
238- // code.innerHTML = "\n " + html;
239- // }
239+ let highlightObject = code ;
240+
241+ const html = code . innerHTML ;
242+ if ( html . match ( / ^ * \n + / ) ) {
243+ // highlighter strips leading blank lines, throwing off line numbers.
244+ // use this awful hack to bypass it. depends on specific details inside
245+ // the syntaxhighlighter module
246+
247+ const fakeCode = {
248+ className : code . className ,
249+ id : code . id ,
250+ title : code . title ,
251+ innerHTML : {
252+ toString : function ( ) {
253+ return html
254+ } ,
255+ replace : function ( search , replace ) {
256+ if ( search . toString ( ) == / ^ [ ] * [ \n ] + | [ \n ] * [ ] * $ / g. toString ( ) ) {
257+ return html . replace ( / \n $ / g, '' ) ;
258+ }
259+ return html . replace ( search , replace ) ;
260+ } ,
261+ } ,
262+ } ;
263+ const parentNode = code . parentNode ;
264+ fakeCode . parentNode = {
265+ replaceChild : function ( newEl , oldEl ) {
266+ if ( oldEl === fakeCode ) {
267+ oldEl = code
268+ }
269+ parentNode . replaceChild ( newEl , oldEl ) ;
270+ } ,
271+ } ;
272+
273+ highlightObject = fakeCode ;
274+ }
240275
241- SyntaxHighlighter . highlight ( config , code ) ;
276+ SyntaxHighlighter . highlight ( config , highlightObject ) ;
242277
243278 const pod_lines = pre . dataset . podLines ;
244279 if ( pod_lines ) {
0 commit comments