As you can see, when it hits the first apostrophe (or dash, etc.) the string cuts. I can understand why, itâs because itâs not being escaped. However using the URI Encode makes the string look funny and coverts the characters to &sdf4; (or whatever the heck it is).
Hi, you have to extract the text out of HTML code. You could pass your âquoteContentâ through an extractor like this one proposed by Rick Hitchcock, to obtain a plain text version of the quote. Iâm a newbie, and maybe this is not at all the best solution, but I hope this could be helpful.
Hi guys, thanks for the feedback. Removing the p tags worked perfectly. However I am still struggling to fix the bug where the string stops after encountering a strange character.
I figured out that the tweet stops because it encounters âCurly quotation marksâ. So I did a google and found this:
I tried his solution, however it still doesnât work. Here is a code snippet from the project:
I do, however the functionality isnât working working as expected. When generating a new quote it doesnât seem to appear. Perhaps it just needs to be run in your own environment; Iâm not sure.
Hi! To make it work, you have just to change http: to https: into your getJSON url.
For the other issue, you can add an extractor, something like extractor = function(parameter) { var span= $('<span/>'); tweet=span.html(parameter).text(); };
and then call it with quoteContent as the parameter. Then you have just to replace quoteComponent with tweet in the twitter buton handler.
You should probably replace your tweet button with an anchor tag with terget="_blank" instead of that âwindow.openâ. Take a look at the Twitter API documentation.
Thanks for your help, itâs almost there. Just a couple of questions:
var span = $('<span/>');
tweet = span.html(string).text();
How does creating and returning a span element help with my situation? I am struggling to get my head around it.
Also, the characters are being converted nicely when I console.log, however when I tweet the quote, the curly apostrophes are now replaced with â?â. See screenshot below:
@dem-sâ answer should work and is a better solution than your regex one - what if you find more unicode characters that break your code? Will you just add more and more regex replace?
The only reason you create a temporary span element and add your string as an HTML code (.html(string)) is to get its text content with .text(). This way you strip every unnecessary characters.
The reason your extractContent() function didnât work is because you never used that. You called it but its return value had never been assigned to your quoteContent variable: