0.1.3 • Published 11 months ago
chitter v0.1.3
Chitter
Preview a working example at https://asm-chitter.vercel.app/
Example repository: https://github.com/najmiter/chitter-example
Getting started
npm i chitterThen do your imports
import init, { chittify } from 'chitter';!IMPORTANT
If you're usingreact, you can do theinit()in auseEffectlike:
useEffect(() => {
init();
}, []);The chittify should return styled html that you can assign to the innerHTML.
const div = document.querySelector('#code-container');
const code = 'mov rax, 10';
const highlightedHtml = chittify(code);
if (div) {
// null check
div.innerHTML = highlightedHtml;
}Or if case of react, you can do something like this:
//.......
//....
// this should be some state that's attached to the `Textarea` (see example project on github)
const code = 'mov rax, 10';
const highlight = useCallback(
(source: string) => (source ? chittify(source) : 'Output will appear here'),
[]
);
//.......
//....
<div dangerouslySetInnerHTML={{ __html: highlightedHtml }} />;
//....
//.......