typewriterjs icon indicating copy to clipboard operation
typewriterjs copied to clipboard

­ should render a hyphen, if the browser breaks the word

Open dsdsdsdsdsds opened this issue 4 years ago โ€ข 9 comments

When a soft hyphen (­) is rendered by typeString(), it correctly breaks the word at the specified point (if needed), but it doesnโ€™t draw the hyphen itself. Have a look at this example.

Also, if the string that is passed to typeString() does not include any HTML elements, then ­ is not decoded and thus rendered as text (possibly related: https://github.com/tameemsafi/typewriterjs/issues/79).

dsdsdsdsdsds avatar Oct 08 '20 14:10 dsdsdsdsdsds

Yep, same happening here for me!

ryangittings avatar Nov 20 '20 17:11 ryangittings

I think this might be a problem overall for html character entity names. I've been trying to render the > sign using > but it's just rendered as >.

rewong03 avatar Jan 04 '21 16:01 rewong03

I think this might be a problem overall for html character entity names. I've been trying to render the > sign using > but it's just rendered as >.

Did you manage to solve this issue ? I tried so hard display "<" and I get constantly get <

flowbartek93 avatar Apr 27 '21 15:04 flowbartek93

I am also running into this problem, specifically I want to render >.

My (messy) work around for now is to inject the value after the fact:

typewriter
  .typeString("<span class='.close-bracket'></span>")
  .callFunction(() => {
    document.querySelector('.close-bracket').innerHTML = '> '
   })

hope this helps

llibdude avatar Apr 30 '21 17:04 llibdude

I'm not sure how it could be solved since the library literally deconstructs letters and adds them the DOM one by one, but this definitely needs to be solved.

ShayanTheNerd avatar Jul 07 '23 15:07 ShayanTheNerd

I am also running into this problem, specifically I want to render >.

My (messy) work around for now is to inject the value after the fact:

typewriter
  .typeString("<span class='.close-bracket'></span>")
  .callFunction(() => {
    document.querySelector('.close-bracket').innerHTML = '> '
   })

hope this helps

Thanks for sharing

ShayanTheNerd avatar Jul 07 '23 15:07 ShayanTheNerd

When a soft hyphen (&shy;) is rendered by typeString(), it correctly breaks the word at the specified point (if needed), but it doesnโ€™t draw the hyphen itself. Have a look at this example.

Also, if the string that is passed to typeString() does not include any HTML elements, then &shy; is not decoded and thus rendered as text (possibly related: #79).

It's funny because I just came across a robust solution (after using this workaround for a couple days) to solve the problem, and also found out that it's been answered at #140. So, basically, instead of using the character itself or its HTML Entity, we need to use the escaped Unicode representation of the character. For example, typewriter.typeString('\u00AD') in your case.

ShayanTheNerd avatar Jul 09 '23 12:07 ShayanTheNerd

if you want render this: ๐Ÿ˜„

typewriter.typeString('<span>A&B</span>')

but got ๏ผš๐Ÿ˜ 

<span>A&ampB</span>

you can try use this ๏ผš๐Ÿ˜‹

typewriter.typeString('<span>A&B<span>')

Intentionally omitting the closing tag slash, allowing typewriter to automatically complete close for you.๐Ÿ‘Œ

YangYongAn avatar Oct 18 '23 11:10 YangYongAn

if you want render this: ๐Ÿ˜„

typewriter.typeString('<span>A&B</span>')

but got ๏ผš๐Ÿ˜ 

<span>A&ampB</span>

you can try use this ๏ผš๐Ÿ˜‹

typewriter.typeString('<span>A&B<span>')

Intentionally omitting the closing tag slash, allowing typewriter to automatically complete close for you.๐Ÿ‘Œ

Despite messing with the HTML structure due to not closing the ending tag, it can be a neat trick given an appropriate context. Thanks for sharing.

ShayanTheNerd avatar Oct 21 '23 11:10 ShayanTheNerd