Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 155 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I am wondering if there's a way to get the last post's revision source without these steps. Is there a more direct way?

  • I need to ask the Stack Exchange API to give me the API site parameter
  • I need to get revisions of current posts via the API
  • I need to get that revision from http://"+document.domain+"/revisions/"+revision_guid+"/view-source, and parse the response (jQuery $(response).filter("pre");)

The body field from /revisions/ (in the second step) just gives HTML response, which is not what I'm looking for.

For those wanting to know WHY do I want to do this, it's because I want to show post source under the current post.

share|improve this question
Shouldn't this type of question be asked on ? (I'm not sure) – Mat Apr 22 '12 at 11:22
@Mat I wasn't actually sure, too – Martin. Apr 22 '12 at 11:23
If its not already there I can userscript it :) – Manishearth Apr 22 '12 at 12:25
@Martin: I know, it was a bad meme joke :/ – Manishearth Apr 22 '12 at 14:45
@Martin: Being a programmer site, wouldn't you expect to point to That would be a great way to implement this--negative-relative revision numbering. :) – Manishearth Apr 22 '12 at 14:47
For my script I found it simplest to copy the source out of the /edit/ page, but that's not so great if you need to handle locked/uneditable posts. – Jeremy Banks Apr 22 '12 at 16:17
@Twilight actually, no. What a great idea! Just a simple OT question: why does $(response).filter("pre") work in my code to find the raw source but $("pre", response) nor $(response).find("pre") doesn't? (gives me an empty array) – Martin. Apr 23 '12 at 4:22

@Twilight gave me an amazing idea of using edit page for this simple purpose.

This gets a source of question and answers:

$(".question, .answer").each(function() {
    var id = $(this).attr("data-questionid");
    if (!id) {
        id = $(this).attr("data-answerid");
    $.get("http://"+document.domain+"/posts/"+id+"/edit-inline", function(t) {  
        // $(t).find("textarea").val() is the source
share|improve this answer
Just for future readers, one drawback that Twilight noted: "not so great if you need to handle locked/uneditable posts". I myself wonder if this would somehow increase some counters on the servers, like indicators that someone started editing. But I guess such counters would actually be based on true editing the text (like when a draft is saved). And I don't know of any current functionality that would use such counters to start with. – Arjan Apr 28 '12 at 10:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .