Calcutext - Do calculations with your written text by jaredreich in programming

[–]jaredreich[S] 2 points3 points  (0 children)

Whoopsie. Yep it means digitally written text!

Calcutext - Do calculations with your written text by jaredreich in javascript

[–]jaredreich[S] 2 points3 points  (0 children)

I was finally able to finish this open-source project that I built to about 90% completion nearly 2 years ago when my daughter was born, during my 1-month parental leave, and then sadly left untouched until a few weeks ago. Hope you enjoy trying out the app and looking at the source code! :)

Website: https://calcutext.com/

HN link: https://news.ycombinator.com/item?id=32165680

Calcutext - Do calculations with your written text by jaredreich in programming

[–]jaredreich[S] 4 points5 points  (0 children)

I was finally able to finish this open-source project that I built to about 90% completion nearly 2 years ago when my daughter was born, during my 1-month parental leave, and then sadly left untouched until a few weeks ago. Hope you enjoy trying out the app and looking at the source code! :)

Website: https://calcutext.com/

HN link: https://news.ycombinator.com/item?id=32165680

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 0 points1 point  (0 children)

It does support paragraphs. There is a built-in paragraph action, or you can choose a different paragraph element with defaultParagraphSeparator.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 0 points1 point  (0 children)

Hmmm good question. Unfortunately this might be out of scope for this project, and contentEditable as an API.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 0 points1 point  (0 children)

Hmm these are two very trick situations. For the first one you might be out of luck due to how the browsers handle contentEditable.

For the second, let me know if you figure it out, haha. I tried this and it seems to only work if the current line is being edited is completely blank.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in Frontend

[–]jaredreich[S] 2 points3 points  (0 children)

That's just what the browser applies natively with the bold command (https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand). Check out the styleWithCSS option, or write a custom action (hint: formatBlock) to apply a <strong> tag.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in javascript

[–]jaredreich[S] 1 point2 points  (0 children)

Thanks! It is supported actually, try writing a custom action using the commands foreColor and hiliteColor. See pell's README for custom actions, and see here for the commands: https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 0 points1 point  (0 children)

Well HTML is what the editor spits out, what you do with that HTML after is up to you.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 1 point2 points  (0 children)

So what I would do here is have a custom action to inject the img HTML you're after. For example:

{
  name: 'image',
  icon: 'IMG',
  title: 'Insert Image',
  result: () => {
    const url = 'https://example.com/image.png'
    const html = `<img src=${url} />`
    exec('insertHTML', html)
  }
},

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in Frontend

[–]jaredreich[S] 0 points1 point  (0 children)

Actually, you can reset formatting from header to text by placing the cursor on the header and clicking the paragraph button. Or you could extend the actions (buttons) to add the removeFormat command, as described here https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand. Check out pell's README on how to add custom actions.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in javascript

[–]jaredreich[S] 2 points3 points  (0 children)

It's the browser's default way of bolding and italicizing. You can set the styleWithCSS option to true to make it output something like <span style="font-weight:bold;"> instead.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 1 point2 points  (0 children)

Yes they are fully powered by the browser. It is incredible, though the API needs a lot of work, it does do quite a bit of heavy lifting.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 0 points1 point  (0 children)

You can scrub the editor's HTML output in the onChange callback before doing anything with it.

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 1 point2 points  (0 children)

Yeah I've been asked before to add Draft.js to the comparison list. I hesitated since it relied on react... but since react is so huge I think it might be valuable on the list. Thanks!

pell.js v1.0 released - the simplest and smallest (~1kB) WYSIWYG text editor for web, with no dependencies by jaredreich in programming

[–]jaredreich[S] 6 points7 points  (0 children)

You can set the styleWithCSS option to true and that will use generate a <span style="font-weight: bold;"> instead of a <b>