Developers

The editor on your site

The PeopleWritten editor can sit in your own page: a submissions form, a writing contest, a class assignment. People write in it as they would on PeopleWritten, it records how they write, and what they submit can be verified as their own work.

It works the way a payment form from a payment company does. The editor is served by PeopleWritten inside a frame on your page. Your page can read what’s written and submit it, but can’t type into it, and the record of how it was written goes straight from the frame to PeopleWritten. Pasting and dropping text in are turned off. See it on a demo page.

Quick start

Add an empty element where the editor should go, load the script, and mount the editor into the element.

HTML
<div id="writer"></div>

<script src="https://peoplewritten.com/embed/v1.js"></script>
<script>
  const editor = PeopleWritten().editor({
    placeholder: "Begin your essay…",
    draft: "spring-contest",
  });
  editor.on("change", ({ words }) => {
    document.querySelector("#count").textContent = words + " words";
  });
  editor.mount("#writer");
</script>

The editor fills the width of the element and, by default, grows with the writing. Its light theme is plain white and its dark theme near-black, so put it in a card or a bordered box if your form needs one.

Options

Pass options to editor(). Anything left out takes its default, and a value the editor can’t use falls back to the default too.

OptionDefaultWhat it does
titletrueStart with a title line. false for a body only.
placeholder“Start writing…”The body’s placeholder, up to 120 characters.
height"auto""auto" grows with the writing. A number of pixels, 600 or "600px" (200 to 4000), fixes the height, and the editor scrolls inside.
minHeight320The smallest writing area with "auto", in pixels (120 to 2000).
draftnoneA key for keeping an unfinished piece in the writer’s browser between visits. Letters, digits and _ : . - only, up to 64.
recordingtrueRecord how the piece is written. Without it there’s nothing to verify.
theme"light""light", "dark", or "auto" to follow the writer’s device.
accentPeopleWritten greenYour accent colour, as #rgb or #rrggbb.

Methods and events

  • mount(target): puts the editor in an element, or the first element matching a selector.
  • on(event, handler) and off(event, handler): listen for events. Both return the editor, so calls can be chained.
  • getContent(): resolves with what’s written so far, without ending the session.
  • submit(): ends the writing session and resolves with the piece and its receipt. Called again with nothing changed, it gives the same receipt. See below.
  • focus(): puts the cursor in the editor.
  • destroy(): removes the editor from the page.
EventDetailWhen
readynoneThe editor has loaded.
change{ title, words, characters, empty }After every edit. Use it for word counts and to enable your submit button.
pasteblockednoneThe writer tried to paste. Pasting is always off; the editor tells them why.
dropblockednoneThe writer tried to drop text in.
recording{ status }The recording’s state changed.
draft{ saved }Whether the draft is being kept in the writer’s browser. false when the browser refuses, as some do for frames from other sites: tell the writer to finish in one sitting.

Your page can create several editors, each mounted in its own element. To point the script at another PeopleWritten host, pass it: PeopleWritten({ origin: "https://…" }).

Submitting

When the writer is done, call submit() from your own submit button. It seals the record of the session and resolves with the piece:

JavaScript
form.addEventListener("submit", async (event) => {
  event.preventDefault();
  const { title, html, text, json, words, receipt } = await editor.submit();
  await fetch("/your/submissions", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ title, html, words, peoplewrittenSession: receipt?.sessionId }),
  });
});
  • title, html, text and json are the piece, as a title, HTML, plain text and the editor’s own document format. words is its length.
  • receipt describes the record. receipt.sessionId is what PeopleWritten verifies: keep it with the submission. When the record is sealed, the receipt also has sealed: true, when the session started and was sealed, how many events it holds, a hash of the content and consistent, whether the record ends with exactly the content submitted. If it couldn’t be sealed, it has sealed: false and a reason.
  • submit() waits up to 15 seconds for the record to reach PeopleWritten. On a slow connection it resolves with sealed: false and reason: "pending", and the editor keeps sending; call submit() again to wait for the same receipt. If PeopleWritten refuses the record, reason says why. It rejects only when the editor itself can’t answer, with an error you can show the writer. Troubleshooting

Treat what arrives at your server as you would any form submission. The receipt names the writing session behind the piece; it isn’t proof by itself, and there’s no public way yet to look a session up. The verdict on a piece comes from PeopleWritten, and a verified piece gets a certificate and a badge like any other. How verification works

On the page

Content-Security-Policy

If your site sends a Content-Security-Policy, allow PeopleWritten as a script and a frame:

script-src https://peoplewritten.com;
frame-src https://peoplewritten.com;

Drafts

With a draft key, an unfinished piece is kept in the writer’s own browser, and comes back when they return to your page. Nothing is kept on your server or ours until they submit. Use a different key for each form, so drafts for one contest don’t open in another.

Communities without a site

Discord servers, subreddits, Facebook groups and most forums can’t embed the editor, because they don’t let anyone add scripts or frames. Members can write on PeopleWritten itself, or in the PeopleWritten app, have the piece verified, and paste it in whole: it arrives ending with its verification line. How it works for communities