FABLED.DAY

contents

Text Formatting (For Javascript Mostly)

So, uh, as you might have noticed while messing with Javascript… sometimes it doesn’t work if you’re inserting text or HTML containing quotation marks or line breaks. This is because Javascript itself relies on quotation marks (of one sort or another) as part of its own syntax. Even if the quotation mark is inside a string of text you’d like to display on your site, Javascript will usually parse it as part of, well, Javascript. This leads to utter disaster.

One important thing you need to remember about this? Some Javascript snippets you’ll find online will use " as part of their syntax; others use '. Almost all of the code I use on this site, particularly that I’ve compiled myself, uses ", but many others do not. Using either works for Javascript, as long as you use it consistently and don’t mix them. The issue is that using them inside fields within Javascript causes problems.

Originally, I was replacing them with character codes using this, but instead, I figured out how to add this "escape string" in Javascript to the converter code used on this page. Turns out, you must simply use the string escape thing twice to make it work? I’m still working on it, and if anyone has any suggestions for making it work better, contact me!

Anyways, enter the HTML or regular text you'd like transformed into a format decently worthy of Javascript in the form below. Click convert, and the results should properly appear below that.

Fun note: This sketchy little form does not account for curly quotes. Letting everyone know just in case, given issues with text editors and parsing them. I know that some will mysteriously transform them into normal quotes and cause problems, so compensating for that may be necessary. Be sure to check your code editor for this.

The Input


The Output

top