4.0.1 • Published 1 year ago

@patternslib/pat-code-editor v4.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

pat-code-editor

Documentation

This is code editor pattern based on CodeJar and PrismJS.


Note:

When prefilling the textarea, please add HTML escaped content to the template to avoid any XSS security issues or nesting errors with existing HTML.

Example to escape content in Python:

import html
escaped_html = html.escape(unescaped_html)

Example to escape content in JavaScript:

const escaped_html = unescaped_html
    .replaceAll("&", "&")
    .replaceAll("&lt;", "<")
    .replaceAll("&gt;", ">")
    .replaceAll("&quot;", '"');

Options reference

PropertyDefault ValueTypeDescription
languagenullString, nullProgramming language to use.
linenumbersfalseBooleanShow line numbers.
themenullStringName of PrismJS theme.
tab"' '"StringCharacters to use as tab. Use "\t" for a tab character, spaces in quotes (e.g. "' '") for spaces
indent-on{$StringRegex pattern where the next line is indented.
spellcheckfalseBooleanActivate spellchecking.
catch-tabtrueBooleanCatch a tab keystroke and indent.
preserve-indenttrueBooleanPreserve indentation of original source.
add-closingtrueBooleanAutomatically add closing brackets.
historytrueBooleanActivate undo history.

Examples

Invocation on a contenteditable div

<div class="pat-code-editor" data-pat-code-editor="language: javascript" contenteditable>
import Pattern from "./code-editor";
Pattern.init(document.querySelector(".pat-code-editor"));
</div>

Invocation on a textarea

This will create a div where the code editor is finally initialized and changes are synchronized back to the text editor.

<textarea class="pat-code-editor" data-pat-code-editor="language: css">
body {
  background-color: black;
  color: blue;
}
</textarea>
4.0.1

1 year ago

4.0.0

1 year ago

3.0.0-alpha.0

2 years ago

3.0.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago