Giter Site home page Giter Site logo

simplesyntaxjs's Introduction

SimpleSyntaxJs (v1.0.4)

A simple lightweight but powerful syntax highlighting library for textareas

SimpleSyntaxJs textarea appearance example:

Example Image

Installation

You can install SimpleSyntax-JS via npm:

npm install simplesyntax-js

Or use CDN inside html:

<link href="https://cdn.jsdelivr.net/npm/simplesyntax-js@latest/dist/simplesyntax.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/simplesyntax-js@latest/dist/simplesyntax.min.js"></script>

Or you can download the library and include it directly in your HTML:

<link href="path/to/simplesyntax.min.css" rel="stylesheet">
<script src="path/to/simplesyntax.min.js"></script>

If you installed via npm, this is how to import the library:

import simpleSyntax from 'simplesyntax-js';
import 'simplesyntax-js/dist/simplesyntax.min.css';

Initializing SimpleSyntaxJs:

Simply call the SimpleSyntax() function on a textarea to apply syntax highlighting to it.

const textarea = document.getElementById("textarea-id");
textarea.simpleSyntax();

to set the width and height of the textarea in pixels, just set it normally with css before initializing simpleSyntax, for example:

textarea { width: 600px; height: 400px; }

Configuration Options

copyButton : Add a copy button to the top right of the textarea. Default is false.

findAndReplace : Enable find and replace functionality. Default is false.

font : The font family to use for the code snippet. Default is 'monospace'.

language : The programming language of the textarea. Default is 'none'.

lineNumbers : Enable line numbers display. Default is false.

matchBraces : Enable matching braces highlighting. Default is false.

readOnly : Set the textarea as read-only. Default is false.

tabChars : The chars to type when pressing tab key. Default is '\t'.

theme : The theme for syntax highlighting. Default is 'light'. currently available theme choices: light, dark, nord, solarized-light, solarized-dark but you can create a custom css theme and use it if you want!

width : Set the width of the textarea, use this in case the textarea has a percentage width.

Example with Configuration options:

textarea.simpleSyntax({
    language: 'javascript',
    theme: 'dark',
    lineNumbers: true,
    width: '100%',
    matchBraces: true,
    findAndReplace: true,
    tabChars: '\t'
});

Functions:

To zoom in:

textarea.zoomIn();

To zoom out:

textarea.zoomOut();

To show Find toolbar: (you should first set findAndReplace to true when initializing)

textarea.showFind();

To show Replace toolbar: (you should first set findAndReplace to true when initializing)

textarea.showReplace();

To set the theme of the textarea after initializing:

textarea.setTheme(theme);

To insert text programatically into the textarea, and if focused, insert text at caret position:

textarea.insertText(textToInsert);

To insert html tag programatically into the textarea, and if part of textarea is selected, wrap it with the tag:

textarea.insertHtmlTag(htmlTagName);

To change the value of the textarea programatically:

textarea.value = newValue;
textarea.textChanged(); // Important: you must call this after changing the textarea's value programatically

License

SimpleSyntaxJs is licensed under the MIT License. See the LICENSE file for details.

Note: If you encounter any issues or have any feedback, please don't hesitate to open an issue. I'd love to hear from you! Feel free to submit reviews, bug reports, or feature requests!

simplesyntaxjs's People

Contributors

reemrizzk avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.