Skip to content

Document - The ability to run DocumentController server side #246

Description

@adrian-moisa

Edit Delta Docs In Dart Server

You can edit delta docs on the server side using DocumentController. This can come in handy for a couple of scenarios:

  • SEO - You can get retrieve the plain text of a delta doc and then render it as a plain old html document using whatever server side technology you desire.
  • Elastic Search - If you need to write a search feature for a large number of documents, once again, you will need the plain text server side. Again running the visual editor on the server side is super handy.
  • Coop Editing - In case you want to implement a master server to compare the edits of multiple users, again you can run doc edits on the dart server itself.

Importing Visual Editor Server
By importing the server side library we ensure that no dart:ui dependencies are imported. Note that both the frontend and server versions of the library use the same code. They are just different export files.

import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:visual_editor/visual-editor-server.dart';

//...
// Convert delta text to plain text
final document = DeltaDocM.fromJson(jsonDecode(deltaText));
final plainText = DocumentController(document, null, null).toPlainText();

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions