Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/guilhermelimak/react-codejar


https://github.com/guilhermelimak/react-codejar

Last synced: 7 days ago
JSON representation

Awesome Lists containing this project

README

        

README.html

body { box-sizing: border-box; max-width: 740px; width: 100%; margin: 40px auto; padding: 0 10px; } document.addEventListener('DOMContentLoaded', () => { document.body.classList.add('markdown-body'); document.querySelectorAll('pre[lang] > code').forEach((code) => { code.classList.add(code.parentElement.lang); }); document.querySelectorAll('pre > code').forEach((code) => { hljs.highlightBlock(code); }); });

react-codejar



React wrapper around the CodeJar library



NPM


Install


npm install --save react-codejar

Usage


import React, { Component, useState } from "react";

// You can choose to use the component or the hook
import { ReactCodeJar, useCodeJar } from "react-codejar";

const highlight = editor => {
let code = editor.textContent;
code = code.replace(/\((\w+?)(\b)/g, '(<font color="#8a2be2">$1</font>$2');
editor.innerHTML = code;
};

const ComponentExample = () => {
const [code, setCode] = useState('(format t "lisp example")');

return (
<ReactCodeJar
code={code} // Initial code value
onUpdate={setCode} // Update the text
highlight={highlight} // Highlight function, receive the editor
/>
);
};

const HookExample = () => {
const [code, setCode] = useState('(format t "lisp example")');

const editorRef = useCodeJar({
code, // Initial code value
onUpdate: setCode, // Update the text
highlight // Highlight function, receive the editor
});

return <div ref={editorRef}></div>;
};


License


GPL3 © guilhermelimak