Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Instead of just removing an empty node, convert it to an '&nbsp' for …#428

Open
wheelerlaw wants to merge 1 commit intogooglearchive:masterfrom
wheelerlaw:convert-newline-to-nbsp
Open

Instead of just removing an empty node, convert it to an '&nbsp' for …#428
wheelerlaw wants to merge 1 commit intogooglearchive:masterfrom
wheelerlaw:convert-newline-to-nbsp

Conversation

@wheelerlaw
Copy link
Copy Markdown

…when dynamically prettifying code.

When prettifying code that has been dynamically inserted into the <pre> block when line numbering is enabled, blank lines (only consisting of a newline and/or carriage return) are erroneously removed from the DOM, when they should actually be preserved and converted into &nbsp elements to prevent browsers from not displaying them, which causes inconsistencies with the line numbering. Here is an example:

Original python script:

# Script Name   : test.py
# Author        : Wheeler Law
# Created       : 2 March 2016
# Last Modified : 
# Version       : 1.0

# Modifications : 

# Description   : Sample python script to test the script uploader/syntax highlighter. 

import sys      # Import the Modules
import os       # Import the Modules

# Readfile Functions which open the file that is passed to the script

def readfile(filename):
    line = open(filename, 'r').read()
    print line

def main():
  if len(sys.argv) == 2:        # Check the arguments passed to the script
    filename = sys.argv[1]      # The filename is the first argument
    if not os.path.isfile(filename):    # Check the File exists
      print '[-] ' + filename + ' does not exist.'
      exit(0)
    if not os.access(filename, os.R_OK):    # Check you can read the file
      print '[-] ' + filename + ' access denied'
      exit(0)
  else:
    print '[-] Usage: ' + str(sys.argv[0]) + ' <filename>' # Print usage if not all parameters passed/Checked
    exit(0)
  print '[+] Reading from : ' + filename    # Display Message and read the file contents
  readfile(filename)

if __name__ == '__main__':
  main()

This is the output:

image

You'll notice that the lines in the script that do not have any content in them are removed from the DOM, which causes inconsistencies with the line numbering.

@amroamroamro
Copy link
Copy Markdown
Contributor

I can't reproduce the problem described. Here are two examples that highlight code dynamically inserted:

Both working fine with correct line numbers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants