• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Browser deletes leading tab characters on each line when writing to child document

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Javascript to write data in the form of nested arrays to another text document or browser window.



I want the output to look something like this:

[   'Text level 1',
   [   'Text level 2',
       [   'Text level 3'
       ],
       [   'More text level 3',
       ]
   ]
]

What it appears as is this:

[   'Text level 1',
[   'Text level 2',
[   'Text level 3'
],
[   'More text level 3',
]
]
]
]

which is much less readable! All the leading tab characters are deleted, although tab characters that follow non-whitespace characters are not deleted. (I should mention, I output <pre> and </pre> at the beginning and the end of the child document.) I tried outputting the tab characters as \t and , but I did not see any difference. I'm using the latest version of Safari for Mac.

Any suggestions? Is the problem browser-specific? Is there a Javascript method that would tell the browser to output the leading tab characters?

 
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Grossman wrote:Is there a Javascript method that would tell the browser to output the leading tab characters?


That's not how HTML works. Whitespace between elements is collapsed, and tabs are not meaningful.

Either use space characters within <pre> if that's appropriate, or use CSS to add left margins as desired.
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind ... a bad for loop was preventing the tab characters from being written to the document. All is good now. Sorry to waste your time.
 
Just the other day, I was thinking ... about this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic