enjoy live editing (+markdown)

Overview

Pen Editor


pen editor - screenshot


0. source code

You can clone the source code from github, or using bower.

bower install pen

1. installation

1.1 init with id attribute

var editor = new Pen('#editor');

1.2 init with an element

var editor = new Pen(document.getElementById('editor'));

1.3 init with options

var options = {
  editor: document.body, // {DOM Element} [required]
  class: 'pen', // {String} class of the editor,
  debug: false, // {Boolean} false by default
  textarea: '<textarea name="content"></textarea>', // fallback for old browsers
  list: ['bold', 'italic', 'underline'], // editor menu list
  linksInNewWindow: true // open hyperlinks in a new windows/tab
}

var editor = new Pen(options);

2. configure

The following object sets up the default settings of Pen:

defaults = {
  class: 'pen',
  debug: false,
  textarea: '<textarea name="content"></textarea>',
  list: [
    'blockquote', 'h2', 'h3', 'p', 'insertorderedlist', 'insertunorderedlist',
    'indent', 'outdent', 'bold', 'italic', 'underline', 'createlink'
  ],
  stay: true,
  linksInNewWindow: false
}

If you want to customize the toolbar to fit your own project, you can instanciate Pen constructor with an options object like #1.3: init with options:

2.1 Fallback for old browser

You can set defaults.textarea to a piece of HTML string, by default, it's <textarea name="content"></textarea>。This will be set as innerHTML of your #editor.

2.2 Change the editor class

Pen will add .pen to your editor by default, if you want to change the class, make sure to replace the class name pen to your own in src/pen.css.

2.3 Enable debug mode

If options.debug is set to true, Pen will output logs to the Console of your browser.

debugger

2.4 Customize the toolbar

You can set options.list to an Array, add the following strings to make your own:

  • blockquote, h2, h3, p, pre: create a tag as its literal meaning
  • insertorderedlist: create an ol>li list
  • insertunorderedlist: create a ul>li list
  • indent: indent list / blockquote block
  • outdent: outdent list / blockquote block
  • bold: wrap the text selection in a b tag
  • italic: wrap the text selection in an i tag
  • underline: wrap the text selection in a u tag
  • createlink: insert link to the text selection
  • inserthorizontalrule: insert a hr tag
  • insertimage: insert an image (img) tag

2.5 Add tooltips to the toolbar icons

You can set options.titles to an object with properties that match the toolbar actions. The value of each property will be used as the title attribute on the icon. Most browsers will display the title attribute as a tooltip when the mouse hovers over the icon.

options.title = {
    'blockquote': 'Blockquote'
    'createlink': 'Hyperlink'
    'insertimage': 'Image'
}

If you are using Bootstrap or jQueryUI, you can standardize the tooltip style by adding $('i.pen-icon').tooltip() to your JavaScript.

2.6 Prevent unsafe page redirect

By default, Pen will prevent unsafe page redirect when editing, to shut down it, specific options.stay to false.

NOTE: if defaults.debug is set to true and default.stay is not set: defaults.stay == !defaults.debug.

2.7 Disable and Re-enable editor

You can disable the pen editor by call destroy() method of the var pen = new Pen(options) object. like:

var pen = new Pen('#editor');

pen.destroy(); // return itself

And, there's a corresponding method called rebuild() to re-enable the editor:

pen.rebuild(); // return itself

2.8 Export content as markdown

It's an experimental feature

var pen = new Pen('#editor');

pen.toMd(); // return a markdown string

3. markdown syntax support

3.1 install

The syntax convertor will be enabled automatically by linking markdown.js after `pen.js:

<script src="src/pen.js"></script>
<script src="src/markdown.js"></script>

3.2 usage

To use it, you can type action cmd + space key at a line start. like:

### This will create a h3 tag

The following cmds are allowed:

  • Headings: type 1~6 # at the line start
  • Unordered List: type - or *
  • Ordered List: type 1.
  • Code block: type ```
  • Block Quote: type >
  • Horizontal Rule: more than 3 -, *, . will create a <hr />, like ......

4. license

Licensed under MIT.

5. trusted by *

Teambition

Comments
  • Add markdown hints

    Add markdown hints

    This adds a mode that shows hints of the markdown that was used to create the tags. This is a really useful way to teach people markdown.

    markdown-hints

    It is all just generated with :before and :after selectors on the elements.

    opened by bkeepers 9
  • Destroy function support ?

    Destroy function support ?

    Wanna know, How can I destroy Pen function ?

    Example :

    When I hover A element so

    var penA = new Pen({editor: document.querySelector('.A')});

    When mouseover how to destroy that ?

    enhancement 
    opened by l2aelba 9
  • Add title hints to Pen toolbar icons

    Add title hints to Pen toolbar icons

    This change adds a title attribute to each toolbar icon so that users can get a better idea what that icon will do. The title attribute is included in the options.list, separated from the command name by a vertical bar. list: [ 'blockquote|Blockquote', 'h3|Heading 3', 'h4|Heading 4', 'code|Code', 'insertunorderedlist|Unordered list', 'bold|Bold', 'italic|Italic', 'createlink|Hyperlink', 'insertimage|Image' ],

    opened by michalcarson 5
  • Is it possible to expose API of Pen to allow extending it?

    Is it possible to expose API of Pen to allow extending it?

    I want to use it with angularjs, hence, would want to extend the prototype of Pen with events and functions specific to angularjs.

    would you be interested in such a PR? do you have any suggestion regarding design?

    opened by adarshaj 5
  • Input element for form integration

    Input element for form integration

    Added a config element for 'input' to make it easier to integrate with forms in a site. It is supposed to be configured the same way other such config elements use like 'editor'.

    opened by lootic 4
  • update from teambition

    update from teambition

    1. 隐藏 Pen 所有的私有方法,通过闭包函数实现私有方法;
    2. 完善事件机制,destroy/rebuild 不再产生内存泄露;
    3. 优化 menu 激活机制;
    4. 增加标签、属性黑名单,可以自动清理黑名单的标签、属性;
    5. 增加 change 事件,监听编辑器内容变化;
    6. 增加 placeholder;
    7. 增加多个使用方法;

    具体见下面代码解释。

    opened by zensh 4
  • Switch to using Sass for CSS files

    Switch to using Sass for CSS files

    This set of commits adds a few additional build targets to make development easier, and it also switches to using Sass for generating the CSS. This will allow for some abstractions down the road and also make the project more extensible.

    opened by Nycto 4
  • fix for jshint: missing hasOwnProperty in for-in loop

    fix for jshint: missing hasOwnProperty in for-in loop

    D:\test\pen>grunt
    Running "jshint:files" (jshint) task
    Linting src/pen.js ...ERROR
    [L817:C5] W089: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
        for(var p in regs) {
    
    Warning: Task "jshint:files" failed. Use --force to continue.
    
    Aborted due to warnings.
    

    And the test passed ;) would be happy if merged

    opened by fritx 2
  • Pen focus issue

    Pen focus issue

    Heya,

    Basically, I have a problem where Pen won't allow me to edit my content as it unfocuses my current <div> when i hover on the tooltip (you can tell by the green / grey border change) e.g.

    gl5r4gpgz3

    The reason for this is because Pen is being appended onto the document body...

        <div class="info ng-scope pen pen-placeholder"  contenteditable="true">...</div>
        <div class="pen-menu pen-menu">...</div>
    </body>
    

    ... rather than injecting somewhere such as inside this current <div>:

        <div class="info ng-scope pen pen-placeholder"  contenteditable="true">
            <div class="pen-menu pen-menu">...</div>
            ....
        </div>
    </body>
    

    For reference, here is my initialisation code:

    console.log($element[0]);
    var pen = new Pen({
        editor: $element[0], // <div class="info ng-scope pen pen-placeholder"  contenteditable="true">...</div>
        debug: true,
        list: ['bold', 'italic', 'underline', 'insertunorderedlist', 'createlink']
    });
    

    I believe the solution to this is to add a property which defines where the Pen element will be injected (document body by default).

    opened by haydenbleasel 2
  • Fix double click visual discontinuity.

    Fix double click visual discontinuity.

    In some browsers the toolbar briefly flashes in the top left corner before being correctly placed when the user double clicks. This is because the range rectangle has all of its values set to 0. Here we detect if the offset defined has a width and height of 0, if this is so we can safely assume the toolbar should not yet be rendered. Works as expected.

    opened by calebmer 2
  • Uncaught Error: Can't find config

    Uncaught Error: Can't find config

    <link rel="stylesheet" type="text/css" href="/assets/pen/pen.css" />
    <script src="/assets/pen/pen.js"></script>
    <script src="/assets/pen/markdown.js"></script>
    
    <script type="text/javascript">
      var editor = new Pen(document.getElementById('my_elem'));
    </script>
    
    
    

    Error:

    pen.js:485 Uncaught Error: Can't find config
        at new Pen (pen.js:485)
        at edit:102
    
    opened by GildedHonour 0
  • Does not actually generate valid Markdown for bold, italic or bold-italic

    Does not actually generate valid Markdown for bold, italic or bold-italic

    There's an issue in the rendering of Markdown for Bold, Italic or Bold-Italic.

    The Markdown clearly specification states that *Italic* should produce italic, **bold** will produce bold, and therefore ***bold-italic*** produces bold-italic .

    However, there is code in pen.js that states 'italic' is ***italic*** and bold-italic is **bold-italic** which is wrong (it produces Bold-Italic and Bold respectively).

    If you pasted the result of the generated code into any markdown processor it would not reproduce what you'd typed correctly.

    opened by richjeffery 1
  • Display the toolbar on touchscreens

    Display the toolbar on touchscreens

    Use touch events to detect selection as well as mouse events. Always display the toolbar at the bottom because the browser's built-in toolbar appears at the top most of the time.

    (BTW, I'm also working on a Custom Elements wrapper for Pen.)

    opened by valpackett 1
  • toMd() improved

    toMd() improved

    Improved toMd output quality. Regex-based converter doesn't work well on recursive nodes like nested lists, code, etc. Now it replaced with DOM visiting.

    Please review code accurately: I'm C++ programmer and I don't know best practicies and coding style in Javascript.

    opened by sergey-shambir 0
  • Project abandoned?

    Project abandoned?

    Hi, seems like this is the best editor fitting my needs, however I can see that it hasn't been maintained in almost a year, issues and PRs are ignored. Is this project abandoned?

    Thanks :)

    opened by ignasbernotas 7
  • doesn't work on a textarea

    doesn't work on a textarea

    Hey,

    I wanted to initialize pen on a textarea, but the toolbar doesn't show up.

    after having investigated the problem, it seems that selection.isCollapsed is always true if you select text in a textarea.

    that seems more like a chrome bug, but I can't get it working this way.

    no push, I'll use another MD editor, just letting this issue here.

    opened by karolyi 0
Releases(0.2.3)
Owner
小鱼
Still hiring creatives.
小鱼
A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.

SimpleMDE - Markdown Editor A drop-in JavaScript textarea replacement for writing beautiful and understandable Markdown. The WYSIWYG-esque editor allo

Sparksuite 9.3k Jan 4, 2023
Enjoy creating cover image for your hashnode blog like never before, get started in seconds 🎉

Slickr ✨️ View Demo · Report Bug · Request Feature Introducing Slickr ✌️ Slick is the most powerful and the easiest app to create beautiful cover imag

Savio Martin 469 Dec 21, 2022
The world's #1 JavaScript library for rich text editing. Available for React, Vue and Angular

TinyMCE TinyMCE is the world's most advanced open source core rich text editor. Trusted by millions of developers, and used by some of the world's lar

Tiny 12.4k Jan 4, 2023
A markdown editor. http://lab.lepture.com/editor/

Editor A markdown editor you really want. Sponsors Editor is sponsored by Typlog. Overview Editor is not a WYSIWYG editor, it is a plain text markdown

Hsiaoming Yang 2.8k Dec 19, 2022
🍞📝 Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.

TOAST UI Editor v3 major update planning ?? ?? ?? TOAST UI Editor is planning a v3 major update for 2021. You can see our detail RoadMap here! GFM Mar

NHN 15.5k Jan 3, 2023
:notebook: Our cool, secure, and offline-first Markdown editor.

Monod Hi! I'm Monod, the Markdown Editor! Monod is a (relatively) secure and offline-first Markdown editor we have built at TailorDev in order to lear

TailorDev 877 Dec 4, 2022
Easily convert markdown files to PDF

ezPDF What's this? This is a simple markdown to pdf parser that supports custom CSS stylesheets. In the future, ezPDF will allow you to preview files

Matheus 12 Oct 11, 2022
In-browser Markdown editor

StackEdit Full-featured, open-source Markdown editor based on PageDown, the Markdown library used by Stack Overflow and the other Stack Exchange sites

Benoit Schweblin 19.9k Jan 9, 2023
A file based wiki that uses markdown

wikmd What is it? It’s a file-based wiki that aims to simplicity. The documents are completely written in Markdown which is an easy markup language th

linbreux 161 Jan 2, 2023
A markdown editor using Electron, ReactJS, Vite, CodeMirror, and Remark

updated: Saturday, 5th February 2022 A modern looking application built with Electron-Vite-React ?? ✨ Markdown Editor Introduction This application s

Kryptonite 5 Sep 7, 2022
Tina is an open source editor that brings visual editing into React websites. Tina empowers developers to give their teams a contextual and intuitive editing experience without sacrificing code quality.

Tina is an open-source toolkit for building content management directly into your website. Community Forum Getting Started Checkout the tutorial to ge

Tina 8.2k Jan 1, 2023
Tina is an open source editor that brings visual editing into React websites. Tina empowers developers to give their teams a contextual and intuitive editing experience without sacrificing code quality.

Tina is an open source editor that brings visual editing into React websites. Tina empowers developers to give their teams a contextual and intuitive editing experience without sacrificing code quality.

Tina 8.3k Jan 9, 2023
Hello! Welcome to Our own Live Code Editor 2!! This is supported tabs and full-screen editing, Console, tabs and more are coming. We uses this one in our all tutorials. Made by @E-Coders & @Genius398

Live Code Editor 2 Hello! this is our live code editor an another second release version of our main Resporibity. This have style as tabs and more fea

Educational Websites 5 Nov 18, 2021
A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.

SimpleMDE - Markdown Editor A drop-in JavaScript textarea replacement for writing beautiful and understandable Markdown. The WYSIWYG-esque editor allo

Sparksuite 9.3k Jan 4, 2023
Bootstrap plugin for markdown editing

Bootstrap Markdown Markdown editing meets Bootstrap. Demo and documentation available at http://toopay.github.io/bootstrap-markdown/ Compatibility Ver

Refactory 2k Dec 27, 2022
Welcome to the LEGO Games Repository, where you can enjoy anytime, anywhere. This is the 2021 KNU Advanced Web Programming team project.

Welcome to LEGO git repository! Here are some useful information about LEGO service. 0. Docker image Link : https://hub.docker.com/r/leibniz21c/legoga

Heesung Yang 16 Jul 21, 2022
Enjoy creating cover image for your hashnode blog like never before, get started in seconds 🎉

Slickr ✨️ View Demo · Report Bug · Request Feature Introducing Slickr ✌️ Slick is the most powerful and the easiest app to create beautiful cover imag

Savio Martin 469 Dec 21, 2022
This project is a countdown system made with HTML, CSS and JavaScript, enjoy it! :)

This project is a countdown system that starts at 10 minutes made with HTML, CSS and JavaScript, enjoy it! ?? You can check the project working on thi

Daniel Burgoa 1 Dec 25, 2021
Formfunctional2021 - This was my very last project of 2021 I just made more revisions to it so yeah enjoy!

FORM FUNCTIONAL 2021 Hello everyone! This project was inspired by the Traversy Media React Crash Course 2021! Basically, what I did was that I took th

Carl Serquiña 1 Jan 2, 2022