All Projects → samdark → codemirror-buttons

samdark / codemirror-buttons

Licence: other
CodeMirror buttons addon

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to codemirror-buttons

buttons
Make sharing fast and secure.
Stars: ✭ 18 (-40%)
Mutual labels:  buttons
dword
Web editor based on CodeMirror
Stars: ✭ 37 (+23.33%)
Mutual labels:  codemirror
liquid button
Liquify your buttons, web demo at website
Stars: ✭ 18 (-40%)
Mutual labels:  buttons
Bilibili-Column-Helper
bilibili专栏助手,已Archive,后续可能port到vscode插件。
Stars: ✭ 26 (-13.33%)
Mutual labels:  codemirror
TW5-codemirror-plus
An attempt to make a better writing experience for TW using codemirror.
Stars: ✭ 26 (-13.33%)
Mutual labels:  codemirror
react-code-preview
Code edit preview for React.
Stars: ✭ 52 (+73.33%)
Mutual labels:  codemirror
kirby-markdown-field
Super-sophisticated markdown editor for Kirby 3, community built.
Stars: ✭ 143 (+376.67%)
Mutual labels:  codemirror
codemirror-blocks
A library for building language-specific, CodeMirror-friendly editors that are a11y-friendly.
Stars: ✭ 22 (-26.67%)
Mutual labels:  codemirror
react-native-social-buttons
Declarative social button components for React Native.
Stars: ✭ 30 (+0%)
Mutual labels:  buttons
ink
The flexible TypeScript Markdown editor that powers https://octo.app
Stars: ✭ 82 (+173.33%)
Mutual labels:  codemirror
ClearWriter
A silent notepad.
Stars: ✭ 25 (-16.67%)
Mutual labels:  codemirror
buttons-collection.scss
[UNMANTAINED] A collection of buttons made with SASS.
Stars: ✭ 33 (+10%)
Mutual labels:  buttons
buttonbuddy
Learn about accessible button contrast then generate your own accessible button color palette
Stars: ✭ 60 (+100%)
Mutual labels:  buttons
getbuttons.io
Love Buttons? Get so many button designs. Click Click!!
Stars: ✭ 12 (-60%)
Mutual labels:  buttons
magento-advanced-code-editor
An advanced code editor that'll make it much easier to write clean markup for CMS pages, static blocks, product pages and Transactional Emails.
Stars: ✭ 19 (-36.67%)
Mutual labels:  codemirror
caucus
Realtime Collaborate Editor with Embedded Compiler
Stars: ✭ 278 (+826.67%)
Mutual labels:  codemirror
fongshen-editor
A highly customizable code-inserting editor for markdown or other languages
Stars: ✭ 35 (+16.67%)
Mutual labels:  codemirror
codemirror-promql
PromQL support for the CodeMirror code editor
Stars: ✭ 35 (+16.67%)
Mutual labels:  codemirror
phpPgAdmin6
PHP7+ Based administration tool for PostgreSQL 9.3+
Stars: ✭ 45 (+50%)
Mutual labels:  codemirror
smart borders
awesomewm full titlebar functionality without sacrificing space
Stars: ✭ 51 (+70%)
Mutual labels:  buttons

CodeMirror buttons addon

Adds a panel with buttons specified via config.

Usage

Include scripts needed into webpage.

<script src="bower_components/codemirror/lib/codemirror.js"></script>
<script src="bower_components/codemirror/addon/display/panel.js"></script>
<script src="bower_components/codemirror-buttons/buttons.js"></script>

Initialize CodeMirror specifying buttons as an array in buttons config property.

var editor = CodeMirror.fromTextArea(document.getElementById('text'), {
	mode: 'gfm',
	buttons: [
        {
            hotkey: 'Ctrl-B',
            class: 'bold',
            label: '<strong>B</strong>',
            callback: function (cm) {
                var selection = cm.getSelection();
                cm.replaceSelection('**' + selection + '**');
                if (!selection) {
                    var cursorPos = cm.getCursor();
                    cm.setCursor(cursorPos.line, cursorPos.ch - 2);
                }
            }
        },
        {
            hotkey: 'Ctrl-I',
            class: 'italic',
            label: '<i>I</i>',
            callback: function (cm) {
                var selection = cm.getSelection();
                cm.replaceSelection('*' + selection + '*');
                if (!selection) {
                    var cursorPos = cm.getCursor();
                    cm.setCursor(cursorPos.line, cursorPos.ch - 1);
                }
            }
        },
        {
            class: 'inline-code',
            label: 'code',
            callback: function (cm) {
                var selection = cm.getSelection();
                cm.replaceSelection("`" + selection + "`");
                if (!selection) {
                    var cursorPos = cm.getCursor();
                    cm.setCursor(cursorPos.line, cursorPos.ch - 1);
                }
            }
        },
        {
            class: 'block-php',
            label: '&lt;php&gt;',
            callback: function (cm) {
                var selection = cm.getSelection();
                cm.replaceSelection("```php\n<?php\n" + selection + "\n```\n");
                if (!selection) {
                    var cursorPos = cm.getCursor();
                    cm.setCursor(cursorPos.line - 2, 0);
                }
            }
        },
        {
            class: 'block-code',
            label: '&lt;-&gt;',
            callback: function (cm) {
                var selection = cm.getSelection();
                cm.replaceSelection("```\n" + selection + "\n```\n");
                if (!selection) {
                    var cursorPos = cm.getCursor();
                    cm.setCursor(cursorPos.line - 2, 0);
                }
            }
        },
        {
            class: 'quote',
            label: '>',
            callback: function (cm) {
                cm.replaceSelection("> " + cm.getSelection());
            }
        },
        {
            class: 'ul',
            label: 'ul',
            callback: function (cm) {
                cm.replaceSelection("- " + cm.getSelection());
            }
        },
        {
            class: 'ol',
            label: 'ol',
            callback: function (cm) {
                cm.replaceSelection("1. " + cm.getSelection());
            }
        },
        {
            class: 'a',
            label: 'a',
            callback: function (cm) {
                var selection = cm.getSelection();
                var text = '';
                var link = '';

                if (selection.match(/^https?:\/\//)) {
                    link = selection;
                } else {
                    text = selection;
                }
                cm.replaceSelection('[' + text + '](' + link + ')');

                var cursorPos = cm.getCursor();
                if (!selection) {
                    cm.setCursor(cursorPos.line, cursorPos.ch - 3);
                } else if (link) {
                    cm.setCursor(cursorPos.line, cursorPos.ch - (3 + link.length));
                } else {
                    cm.setCursor(cursorPos.line, cursorPos.ch - 1);
                }
            }
        }
    ],
});

Altrnatively, instead of setting individual options, you can supply either DOM node or a callback returning DOM node using el key:

{
    el: function(cm) {
        return document.getElementById('mybutton');
    }
}

Optionally use stylesheet included to make buttons look a bit better:

<link rel="stylesheet" href="bower_components/codemirror-buttons/buttons.css">
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].