How do I programatically fetch the live plaintext contents of an etherpad?
Asked Answered
H

5

5

This question came up on the etherpad-open-source-discuss mailing list and I thought it would be useful to have it here.

Hallerson answered 28/10, 2010 at 2:51 Comment(0)
H
3

Just construct a URL like so and fetch it:

http://dtherpad.com/ep/pad/export/foo/latest?format=txt

That will get the live, plaintext contents of http://dtherpad.com/foo

For example, in PHP you can grab it with

file_get_contents("http://dtherpad.com/ep/pad/export/foo/latest?format=txt")

Note that that's just the "export to plain text" link that's provided in the Import/Export menu of every pad.

Hallerson answered 28/10, 2010 at 2:55 Comment(1)
Argh, John McLear updated this for the latest version of Etherpad (thank you!) but someone else rejected it and now it's not letting me accept it.Hallerson
H
3

A few other possibilities:

  • From a browser, you can hit http://your-etherpad-server.com/ep/pad/view/padId/latest?pt=1
  • From within the code of the collaborative editor (ace2_inner.js), use rep.alltext
  • Within the Etherpad's javascript, use pad.text for the most recent version of pad.getRevisionText(rev.revNum) for a specified previous revision.
Halmahera answered 28/10, 2010 at 16:15 Comment(0)
R
2

It seems that the javascript functions mentioned by Ari in his response are no longer present in the current versions of Etherpad as implemented on sites like http://etherpad.mozilla.org

However you can now simply use the following javascript function, within eherpad's javascript to get the text of the latest revision

padeditor.ace.exportText()
Roop answered 28/6, 2012 at 22:22 Comment(0)
R
2

You can get the plaintext content of etherpad using jQuery as:

jQuery(document).ready(function(){
    jQuery('#export').click(function(){
        var padId = 'examplePadIntense';//Id of the div in which etherpad lite is integrated
        var epframeId = 'epframe'+ padId;
        var frameUrl = $('#'+ epframeId).attr('src').split('?')[0];
        var contentsUrl = frameUrl + "/export/txt";
        jQuery.get(contentsUrl, function(data) {
            var textContent = data;
        });
    });
});
Revetment answered 13/9, 2012 at 6:6 Comment(0)
Y
0

You can also use the getText HTTP api to retrieve the contents of a pad.

See my other answer for more details.

Yousuf answered 27/11, 2018 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.