duckduckgo / duckduckhack-docs

DuckDuckHack Instant Answer documentation for developers
http://docs.duckduckhack.com
Other
77 stars 75 forks source link

Document Cheat Sheet support for `\n` and `\t` #33

Closed moollaza closed 8 years ago

moollaza commented 8 years ago

Cheat Sheets now support newlines and tabs (useful for code blocks).

If you want to show a literal \n or \t in your JSON, you need to escape the slash: \\n or \\t

E.g. https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/share/goodie/cheat_sheets/json/common-escape-sequences.json#L48

talsraviv commented 8 years ago

@moollaza just to be clear when you mean a literal "\n", do you mean displaying "\n" or displaying "↵"?

Is it basically the same as how JSON.parse() would work (can I use that as a guide) or different than this:

screen shot 2016-03-02 at 11 05 46 am

and

screen shot 2016-03-02 at 11 06 23 am

talsraviv commented 8 years ago

Also - for literals in general - is this line correct?

To express a backslash, use a quadruple backslash: \\\\

moollaza commented 8 years ago

just to be clear when you mean a literal "\n", do you mean displaying "\n" or displaying "↵"?

I mean displaying the text: \n on the page like we do here: https://duckduckgo.com/?q=common+escape+sequences+cheat+sheet&ia=cheatsheet&iax=1

So, it's kinda different from JSON.parse() -- we're not using that FWIW.


Also - for literals in general - is this line correct?

To express a backslash, use a quadruple backslash: \\\\

Uh right now you need to use \\\\ to get a \ showing on the SERP, but that's actually kind of a bug. You should really only need \\. We can adjust the CheatSheet parser to better handle \\.

\\\\ when parsed as JSON becomes \\ which to our parser is an escaped \.

talsraviv commented 8 years ago

Btw - was playing in codio - is this the right usage of \n? I didn't get a line break, and just ran duckpan upgrade before it

screen shot 2016-03-04 at 9 45 28 am

screen shot 2016-03-04 at 9 45 40 am

(didn't work for code template or keyboard template either)