alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

Provide function for escaping rich text #559

Closed jacobweber closed 3 years ago

jacobweber commented 5 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[X] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

It would be useful to have a utility function for escaping rich text, for constructing strings to pass into Alexa.RichTextContentHelper.withPrimaryText().

Expected Behavior

Something like escapeRichText("a & \\ b"), which would return "a & \\\\ b". It would implement the rules here.

Current Behavior

We can't use escapeXmlCharacters from SsmlUtils. It tries to prevent characters from being encoded twice, which would mess with valid text, e.g. if you wanted to display a sample of HTML code to the user like &.

In any case, this isn't a standard HTML-encode, because of the \\ requirement.

Possible Solution

See above.

Context

Nice to have, but not essential.

Your Environment

Node.js and NPM Info

ShenChen93 commented 3 years ago

Looks like this util function is already exist in ask-sdk-core: https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/blob/2.0.x/ask-sdk-core/lib/index.ts#L49.

Closing this issue for now, please feel free free to reopen if it dosn't solve your problem :)

jacobweber commented 3 years ago

I don't think escapeXmlCharacters solves the problem, due to the issue I mentioned above. But I'm not working on this anymore, so I don't personally need it.