Adding syntax highlighting to an input field can be a hard task. supports neither styling of individual characters or words, nor HTML tags within itself, there is no fully supported native solution for that. Most editors work with
contenteditableto actually render a fully marked up code snippet and let the user edit its content. This requires a lot of work to get it accessible (as in restore all the native functions of a textarea) and still adds a lot of complexity.
If you don't want that and are just looking for a quick, dead-simple solution: Here's how to colorize a textarea.
The trick is to separate the input element from the displayed one. We can't color the content of a textarea, but we can make it invisible and replace it with marked up content. This works with monospaced fonts and fonts with a uniform width across normal, bold and italic characters. I'm using this for code and markdown, so that's perfectly acceptable for me. We also need to be careful to match the dimensions of the textarea exactly while only using font-relative units like
em, to ensure that the highlight element scales well with the invisible textarea. The cursor is still in the textarea's context, while the text itself is rendered in the highlight element. We want to match every character of the textarea to match the highlighted one on a pixel-perfect basis.
I also need to auto-resize my textarea. Since textareas usually scroll vertically, that would mess up the position matching with the highlight element. Auto-resizing seems like a graceful workaround to me.
The highlghting itself would work with every code parser. I'm using highlight.js to convert markdown to syntax-highlighted HTML. I listen for content changes in the textarea and parse new rendered code on every input. To counter the worst performance hits, I'll just use
requestAnimationFrame. Debouncing isn't an option here, because the user would only see what they've written after they've finished typing. That'd be very poor UX.
Note that this example also displays the rendered Markdown in a separate element. I'll use the change listener that I already have to splice in a Markdown renderer: Showdown.
- as accessible as a textarea
- is a progressively enhanced feature
- can be styled exactly to your needs
- dead simple solution compared to a rich text editor
- has performance issues with large texts (as do textareas in general)
- works only with monospaced fonts
- works only with auto-sizing textareas
This article was written in a textarea :)
Create PDF documents using web technologiesProject mention: Beautiful PDFs from HTML | news.ycombinator.com | 2021-04-04
A few years ago I started an alternative to PrinceXML called ReLaXed.js , it's always been sufficient for my reports but it may lack some pagination/layout features that Paged.js may have as they seem to have given this much more thoughts (still wrapping my head around whether paged.js could be "plugged into" Relaxed).
Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.
Advanced html to text converterProject mention: [TECH] Hugo で React + TypeScript を利用してサクッとウェブサイトに RSS リーダーを追加する ⛳ | dev.to | 2021-03-20
html-to-text/node-html-to-text: Advanced html to text converter
[av-converter.com] Convert audio/video files to another format. Powered by FFmpeg and WebAssembly.Project mention: Issue with the FFMPEG app. | reddit.com/r/ffmpeg | 2021-12-29
You can use my website (it uses FFmpeg) and it will work on your phone as long as you use the Firefox Nightly browser which is on Google Play. https://av-converter.com
Convert Genshin Impact audio files into a playable formatProject mention: Where can i find Genshin Impact Sound Effects? (Of Inazuma Electro Stuff, and of the Raiden Shogun Elemental Skill and Elemental Burst sound effects without the voice lines?) I need them for a Genshin Impact Minecraft Mod Im Making.... | reddit.com/r/Genshin_Impact | 2021-11-23
A tool to convert the files into a normal format.
Convert tweets to imagesProject mention: Convert Tweets to Images | news.ycombinator.com | 2021-01-31
A converter between the CSV format of Dutch banks and the YNAB format. Or sync your bank statement directly with YNAB!Project mention: Dutch bank statement synchronization with YNAB! | reddit.com/r/ynab | 2021-10-04
I am the creator of [YNABGoingDutch](https://github.com/DanielsWrath/YNABGoingDutch), a tool which automatically creates ready-to-go CSV files from your horrendous Dutch CSV files!
OPS - Build and Run Open Source Unikernels. Quickly and easily build and deploy open source unikernels in tens of seconds. Deploy in any language to any cloud.
Convert portions of text to fancy text using unicode fonts for use on Twitter and other sites that don't support rich text
A modern & simple audio converter for video filesProject mention: How do i encode my videos multiple audio tracks | reddit.com/r/ffmpeg | 2021-11-30
You can find more on the website or on the GitHub repository
Townscaper clipboard data format converter.Project mention: Reversing LZ91 from Commander Keen | news.ycombinator.com | 2021-08-17
You're both right.
I've used Ghidra to reverse-engineer a game's serialization format and, even though the C-ish result was better than manually tracking registers across the disassembly, it was far from understandable. A great deal of the work was cleaning up the resulting C into something that a human would've written.
:wrench: A command-line utility to convert between binary Tibia maps and human-readable forms of the map data.Project mention: Best place to get maps? | reddit.com/r/TibiaMMO | 2022-01-08
This script converts the marker file to a text file: https://github.com/tibiamaps/tibia-maps-script/blob/main/src/from-minimap.mjs
An online YNAB converter for your Indonesian bank statements. No install, no sign-up. Currently covering: BCA, BNI, BSI, Jenius.Project mention: Anyone here uses YNAB with Indonesian banks? | reddit.com/r/ynab | 2021-04-01
It is a Rails web app, so all you need to do is select your Indonesian bank + statement, hit convert, and BAM! the YNAB-compatible CSV is automatically downloaded. No installation required, and also unlinked by design, for YNAB users like me who are wary about connecting their financial information to third party apps. Your statement is also deleted once conversion is done - no file is stored in the server (check the source code in GitHub).
An icy currency converter.Project mention: Icy – An Icy Currency Converter | news.ycombinator.com | 2021-12-01
Issue with the FFMPEG app.
1 project | reddit.com/r/ffmpeg | 29 Dec 2021
My website that allows you to convert an audio/video file to another format. Flask backend.
2 projects | reddit.com/r/Python | 29 Dec 2021
Where can i find Genshin Impact Sound Effects? (Of Inazuma Electro Stuff, and of the Raiden Shogun Elemental Skill and Elemental Burst sound effects without the voice lines?) I need them for a Genshin Impact Minecraft Mod Im Making....
1 project | reddit.com/r/Genshin_Impact | 23 Nov 2021
Can someone tell me the name of this OST? I can't seem to find it on the Official OST. I know it's a variation of Dream Aria, but which one?
1 project | reddit.com/r/Genshin_Impact | 2 Oct 2021
Beautiful PDFs from HTML
13 projects | news.ycombinator.com | 4 Apr 2021
Anyone here uses YNAB with Indonesian banks?
1 project | reddit.com/r/ynab | 1 Apr 2021
Convert Tweets to Images
1 project | news.ycombinator.com | 31 Jan 2021
Are you hiring? Post a new remote job listing for free.