Socket
Socket
Sign inDemoInstall

@patternslib/pat-code-editor

Package Overview
Dependencies
2
Maintainers
7
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @patternslib/pat-code-editor

A pattern for a code-editor


Version published
Maintainers
7
Install size
7.67 MB
Created

Changelog

Source

4.0.1 (2022-12-12)

Bug Fixes

  • Add fallback for okaidia theme which exists in PrismJS but not in Highlight.js (6f5c9d8)

  • Await for styles import, otherwise theme might not be applied. (441033d)

Maintenance

  • Include dist/ and src/ in the npm package. (d96dc89)

  • Update demo - fully escape HTML example, remove debugging markup. (ae39fc2)

  • Use browserslist defaults. (5c0f314)

Readme

Source

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

import Pattern from "./code-editor"; Pattern.init(document.querySelector(".pat-code-editor"));
<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.

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

Keywords

FAQs

Last updated on 12 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc