Consider the following commands, and their results :

$ echo "<br/> <br/>a<br/>b<br/>c<br/><br/> <br/>"|lynx -dump -stdin

$ echo "<br/> <br/>a<br/>b<br/>c<br/><br/> <br/>"|elinks -dump

Neither prints the correct number of lines : elinks skips the first white space, and both skip blank lines and trailing lines with white space only.

Is there a way to force lynx or elinks to interpret all spaces and line breaks ? I didn't see anything obvious in their manpage.

(I mean, beside using a temporary character to be suppressed by sed or tr or whatever after the display.)

  • Neither of these work for me either. What are you ultimately trying to accomplish with these? Just curious, since they all seem to do it, and I could find no direct reason as to why they work like this. But rather than fight uphill against these tools, perhaps there is some more deeper reason/problem that you're trying to solve that could be solved in a different way. – slm Nov 30 '14 at 14:22
  • Well I solved my problem using the workaround mentioned in parenthesis at the end of the question (I choose a character which I was confident was not in my data, in my case ~). – Skippy le Grand Gourou Nov 30 '14 at 14:26
  • Yeah I read that, but was curious if there was some down stream use you needed to have the new lines in, or were you just looking for a way to convert html to a text output, or something else entirely. – slm Nov 30 '14 at 14:28
  • As for what I'm ultimately trying to accomplish, I'm filling a DB with data from HTML tables. The easiest and most robust way I found is to dump each column into a separate file, then I merge files using paste, and finally I use psql \copy to fill the DB. Usually I use hxselect "td:nth-child()" to get columns, but for one particular column it gives me HTML code which needs to be interpreted, which is why I use lynx — then the issue arises when rows are empty. – Skippy le Grand Gourou Nov 30 '14 at 14:32
  • 1
    Nokogiri in Ruby is one such method: ruby.bastardsbook.com/chapters/html-parsing. Another example: stackoverflow.com/questions/8749101/… – slm Nov 30 '14 at 15:22

Lynx can be configured to modify this behavior using COLLAPSE_BR_TAGS in the configuration file, e.g., lynx.cfg:

If COLLAPSE_BR_TAGS is set FALSE, Lynx will not collapse serial BR tags. If set TRUE, two or more concurrent BRs will be collapsed into a single line break. Note that the valid way to insert extra blank lines in HTML is via a PRE block with only newlines in the block.

Default value for COLLAPSE_BR_TAGS is TRUE

  • Great suggestion. Unfortunately this parameter doesn't seem to have the expected effect, if any. – Skippy le Grand Gourou Oct 14 '15 at 13:35
  • @SkippyleGrandGourou, AFAICT, lynx -cfg <(echo COLLAPSE_BR_TAGS:FALSE) -dump -stdin has some effect, but still seems to do some br collapsing (seems to introduce only one blank line) – Stéphane Chazelas Oct 18 '15 at 21:23
  • This solution works perfectly for using lynx to view html in mutt. – Jonas Dahlbæk Sep 18 '17 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.