All Projects → PerfectExamples → Perfect-Markdown-Editor

PerfectExamples / Perfect-Markdown-Editor

Licence: Apache-2.0 license
This project demonstrates how to build an Online Markdown Editor based on Perfect HTTP Server, Perfect WebSocket and Perfect Markdown.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Perfect-Markdown-Editor

Perfect-URLRouting
Perfect Example Module: URL Routing
Stars: ✭ 20 (+25%)
Mutual labels:  perfect
Perfect-JSON-API
An Example JSON API for Perfect
Stars: ✭ 43 (+168.75%)
Mutual labels:  perfect
Swift-FS-China
Swift China Community
Stars: ✭ 44 (+175%)
Mutual labels:  perfect
SlackBot
A starter template project for Slack Bot Servers based on Perfect.
Stars: ✭ 16 (+0%)
Mutual labels:  perfect
Perfect-TensorFlow-Demo-Vision
Perfect TensorFlow Server Example of Computer Vision
Stars: ✭ 39 (+143.75%)
Mutual labels:  perfect
Perfect-URL-Shortener
An Example URL Shortener System for Perfect
Stars: ✭ 37 (+131.25%)
Mutual labels:  perfect
Perfect-SMTP
SMTP Client for Perfect.
Stars: ✭ 19 (+18.75%)
Mutual labels:  perfect
Perfect-HTTP
Base HTTP Support for Perfect.
Stars: ✭ 29 (+81.25%)
Mutual labels:  perfect
Perfect-Authentication
OAuth2 Implementations with Facebook, Google, LinkedIn, Slack, SalesForce and GitHub providers.
Stars: ✭ 14 (-12.5%)
Mutual labels:  perfect
live-share-editor
ソースコードをリアルタイムで共有できるオンラインエディタ
Stars: ✭ 15 (-6.25%)
Mutual labels:  online-editor
Perfect-HTTPServer
HTTP server for Perfect.
Stars: ✭ 104 (+550%)
Mutual labels:  perfect
SwiftString
A comprehensive, lightweight string extension for Swift 3.x & 4.0
Stars: ✭ 117 (+631.25%)
Mutual labels:  perfect
Perfect-WebSocketsServer
Perfect Example Module: WebSockets Server
Stars: ✭ 34 (+112.5%)
Mutual labels:  perfect
Perfect-Thread
Core threading library for Perfect Server Side Swift. Includes support for serial and concurrent thread queues, locks, read/write locks and events.
Stars: ✭ 17 (+6.25%)
Mutual labels:  perfect
Draft
▪️Online markdown editor
Stars: ✭ 29 (+81.25%)
Mutual labels:  online-editor
Perfect-XML
XML support for Perfect.
Stars: ✭ 16 (+0%)
Mutual labels:  perfect
Perfect
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)
Stars: ✭ 13,890 (+86712.5%)
Mutual labels:  perfect
Perfect-Weather
Demonstrate using URL Routes & variables, Fetching of remote data from API's as JSON, reading and transforming to data more appropriately consumable by an API client.
Stars: ✭ 32 (+100%)
Mutual labels:  perfect
PerfectLearnGuide
Are you eager to get programming with Swift and Perfect? This PerfectLearnGuide will help you.
Stars: ✭ 19 (+18.75%)
Mutual labels:  perfect
bside
Github Content Management System
Stars: ✭ 22 (+37.5%)
Mutual labels:  online-editor

Perfect Online Markdown Editor Demo 简体中文

Get Involved with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 3.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

This project demonstrates how to build an Online Markdown Editor based on Perfect HTTP Server, Perfect WebSocket and Perfect Markdown.

Ensure you have installed and activated the latest Swift 3.1 tool chain.

Quick Start

Follow the bash commands below to download, build and run this project:

$ git clone https://github.com/PerfectExamples/Perfect-Markdown-Editor.git
$ cd Perfect-Markdown-Editor
$ swift build
$ ./.build/debug/PerfectMarkdownEditor

If success, messages should pop out as below:

[INFO] Starting HTTP server localhost on 0.0.0.0:7777

This means you can use browser to check http://localhost:7777.

For the tutorial purposes, this project only provides plain HTML without any render style to minimize the code. However, you can add any CSS to make it prettier.

Project Walkthrough

The whole project is based on PerfectTemplate.

Package.swift

It is a common file required by Swift Package Manager, with key lines of components for the server:

	.Package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", majorVersion: 2),
	.Package(url: "https://github.com/PerfectlySoft/Perfect-WebSockets.git", majorVersion:2),
	.Package(url: "https://github.com/PerfectlySoft/Perfect-Markdown.git", majorVersion: 1)

Among these dependencies, Perfect-HTTPServer includes all essential functions of a Swift HTTP Server on both mac / linux; Perfect-Markdown is a library that enables the Swift convert Markdown string to HTML; Besides, Perfect-WebSockets provides WebSocket access to clients, which means that any input will get instant render feedback.

main.swift

main.swift is the main entry of the server, which is a typical PerfectTemplate application. The server will provide only two routes:

  • /editor - the WebSocket handler, i.e., incoming WebSocket requests will be processed as program below:
public class EditorHandler: WebSocketSessionHandler {

  public let socketProtocol : String? = "editor"

  // This function is called by the WebSocketHandler once the connection has been established.
  public func handleSession(request: HTTPRequest, socket: WebSocket) {

    socket.readStringMessage { input, _, _ in

      guard let input = input else {
        socket.close()
        return
      }//end guard

      // translate markdown to HTML, just one line code
      let output = input.markdownToHTML ?? ""

		// send the HTML back to socket
      socket.sendStringMessage(string: output, final: true) {
        self.handleSession(request: request, socket: socket)
      }//end send
    }//end readStringMessage
  }//end handleSession
}//end Handler
  • / - the root handler, i.e., a static HTML home page, but client user behaviour - type any markdown into the input box and immediately translate to HTML - is controlled by a small piece of WebSocket script embedded in the HTML:
var input, output;
function init(){
	input = document.getElementById('textInput');
	output = document.getElementById('results');
	// create a socket and point it to the current server with api "/editor" and protocol "editor" (can be different names)
	sock = new WebSocket('ws://' + window.location.host + '/editor', 'editor');
	sock.onmessage = function(evt) { output.innerText = evt.data; }
}//end init
function send() {
	sock.send(input.value);
}

Issues

We are transitioning to using JIRA for all bugs and support related issues, therefore the GitHub issues has been disabled.

If you find a mistake, bug, or any other helpful suggestion you'd like to make on the docs please head over to http://jira.perfect.org:8080/servicedesk/customer/portal/1 and raise it.

A comprehensive list of open issues can be found at http://jira.perfect.org:8080/projects/ISS/issues

Further Information

For more information on the Perfect project, please visit perfect.org.

Now WeChat Subscription is Available (Chinese)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].