lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Lynx-dev] copy out of lynx, replace and paste


From: Tim Chase
Subject: Re: [Lynx-dev] copy out of lynx, replace and paste
Date: Tue, 22 Mar 2022 12:52:16 -0500

On 2022-03-20 02:08, s18@stof999.ch wrote:
> what is best (easiest) solution for copy text out of lynx AND

Depends on the particulars of what you want.

a) If you want a subset of what's displayed on the screen, I'd reach
for tmux which allows you to copy sections of the display to a
clipboard and then pipe that content out elsewhere to a process that
makes the transformations you want:

  $ tmux
  (tmux)$ lynx example.com
  «control+B»[    # to start scrollback copy mode

with the content in the buffer, you can output it to a transformation
command like

  (tmux)$ tmux showb | sed '…'

b) If you want the entire rendered document you can save it locally
(usually bound to "p"rint by default which lets you save it to a
file, mail it to yourself, or a few other options).  Alternatively,
if your version of lynx was built with USE_EXTERNALS which you can
check by launching lynx with

  $ lynx LYNXCOMPILEOPTS:

and searching for "USE_EXTERNALS", you might be able to tweak your
EXTERN_PAGE settings to fire off a script on the current page.

> replace (in clipboard ?) all NL/CR followed by 3 spaces with 1
> space, bevor pasting it somewhere?

Once you have the rendered content that you want, either as a file or
as stdin, you can use any number of tools to transform it.  Here's an
awk one-liner that looks for all newlines followed by 3 spaces

 awk 'function p(){for (i=0;i<length(a);i++)printf("%s%s",i?"
 ":"",a[i]);print ""; delete a; a[0]=$0} {if (/   /)
 a[length(a)]=substr($0, 4); else p()}END{p()}'

which formats more neatly as the following script:

  #!/usr/bin/awk -f
   function p(){
    for (i=0; i<length(a); i++) {
      # join them together with a single space
      printf("%s%s", i?" ":"", a[i])
    }
    # emit a newline
    print ""
    delete a
    a[0] = $0
  }
  {
    # accrue subsequent lines that begin with 3 spaces
    if (/   /) a[length(a)]=substr($0, 4)
    else p()
  }
  END{
    p()
  }

You didn't mention what you want to happen if a line starts with
*more* than three spaces, so the implementation above strips the 3
spaces and leaves any additional leading-spaces.

You can then pipe the printed file or the `tmux showb` output to this
script to reformat it as you describe.

-tim









reply via email to

[Prev in Thread] Current Thread [Next in Thread]