getting HTML source or rich text from the X clipboard

1

2

How can rich text or HTML source code be obtained from the X clipboard? For example, if you copy some text from a web browser and paste it into kompozer, it pastes as HTML, with links etc. preserved. However, xclip -o for the same selection just outputs plain text. I'd like to pull the HTML out and into a text editor.

intuited

Posted 2010-05-22T21:35:43.067

Reputation: 2 861

It does appear to obtain the HTML source itself: things like the class properties of <div> elements are preserved. – intuited – 2010-05-23T03:08:10.243

improve the title of your question to match what you really want: the source code of the website / rich text... – akira – 2010-07-06T10:42:07.143

@akira: Thanks for your suggestion. It would have been more polite to phrase it as such. – intuited – 2010-07-06T15:12:52.333

not polite, just more to the point :) – akira – 2010-07-06T18:39:32.670

Answers

1

With some help from the answer to the stackoverflow.com fork of this question, I built a ghetto command-line client to pull this info.

Usage

clipcli [-h] [-f FILE] [-d] [-l] [TARGET]

positional arguments:
  TARGET                display the contents of this target

optional arguments:
  -h, --help            show this help message and exit
  -d, --debug           enable debug tracing
  -f FILE, --file FILE  the file to which output will be directed
  -l, --list            list available targets

Example:

$ clipcli text/html
some text with <em>emphasis</em>

The way this works, even the availability of different targets, seems to depend a lot on the application which is providing the clipboard data. There's a bit more info at the stackoverflow question.

intuited

Posted 2010-05-22T21:35:43.067

Reputation: 2 861

0

Does xclip -o -selection secondary or xclip -o -selection clipboard work for you?

These could be abbreviated to

xclip -o -se s 

and

xclip -o -se c

Paused until further notice.

Posted 2010-05-22T21:35:43.067

Reputation: 86 075

No, that still gives a textual rendering of the page rather than the HTML source. – intuited – 2010-05-23T02:27:57.203