Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 930631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:22:09+00:00 2026-05-15T20:22:09+00:00

How can rich text or HTML source code be obtained from the X clipboard?

  • 0

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, reformatted in a way similar to that of elinks -dump. I’d like to pull the HTML out and into a text editor (specifically vim).

I asked the same question on superuser.com, because I was hoping there was a utility to do this, but I didn’t get any informative responses. The X clipboard API is to me yet a mysterious beast; any tips on hacking something up to pull this information are most welcome. My language of choice these days is Python, but pretty much anything is okay.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:22:10+00:00Added an answer on May 15, 2026 at 8:22 pm

    In X11 you have to communicate with the selection owner, ask about supported formats, and then request data in the specific format. I think the easiest way to do this is using existing windowing toolkits. E,g. with Python and GTK:

    #!/usr/bin/python
    
    import glib, gtk
    
    def test_clipboard():
        clipboard = gtk.Clipboard()
        targets = clipboard.wait_for_targets()
        print "Targets available:", ", ".join(map(str, targets))
        for target in targets:
            print "Trying '%s'..." % str(target)
            contents = clipboard.wait_for_contents(target)
            if contents:
                print contents.data
    
    def main():
        mainloop = glib.MainLoop()
        def cb():
            test_clipboard()
            mainloop.quit()
        glib.idle_add(cb)
        mainloop.run()
    
    if __name__ == "__main__":
        main()
    

    Output will look like this:

    $ ./clipboard.py 
    Targets available: TIMESTAMP, TARGETS, MULTIPLE, text/html, text/_moz_htmlcontext, text/_moz_htmlinfo, UTF8_STRING, COMPOUND_TEXT, TEXT, STRING, text/x-moz-url-priv
    ...
    Trying 'text/html'...
    I asked <a href="http://superuser.com/questions/144185/getting-html-source-or-rich-text-from-the-x-clipboard">the same question on superuser.com</a>, because I was hoping there was a utility to do this, but I didn't get any informative responses.
    Trying 'text/_moz_htmlcontext'...
    <html><body class="question-page"><div class="container"><div id="content"><div id="mainbar"><div id="question"><table><tbody><tr><td class="postcell"><div><div class="post-text"><p></p></div></div></td></tr></tbody></table></div></div></div></div></body></html>
    ...
    Trying 'STRING'...
    I asked the same question on superuser.com, because I was hoping there was a utility to do this, but I didn't get any informative responses.
    Trying 'text/x-moz-url-priv'...
    http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service which takes the user supplied rich text (can have HTML
I am using php to output some rich text. How can I strip out
I'm using HTML entities on a string of rich html text, but some characters
The project I am working on has a rich text box that can have
Can I bind my h:dataTable/rich:dataTable with some Map? I found that h:dataTable can work
i use jquery.ajax to save a rich text area . corr=some.innerHTML(); /* corr='&lt; some
If csv file has rich text in it. Using csv.reader() can the same format
How can I make certain parts of my html not selectable? I have some
I fetch html data and wish to show it in a rich text editor
My problem I want to clean HTML pasted in a rich text editor (FCK

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.