appdotnet / api-spec

App.net API Documentation is on the web at https://developers.app.net. Source for these docs is in the new-docs branch here. Please use the issue tracker and submit pull requests! Help us build the real-time social service where users and developers come first, not advertisers.
https://developers.app.net
950 stars 98 forks source link

Linebreaks in HTML #111

Closed edent closed 11 years ago

edent commented 12 years ago

If a user writes a post with newline characters (usually \n) that character is passed along in the 'text' field of the API response.

In the HTML response, it is also passed as "\n". I would expect that newlines be converted to <br> in the HTML representation.

Otherwise, clients have to implement nl2br (or their language's equivalent).

See https://alpha.app.net/edent/post/103821 for an example.

abitgone commented 12 years ago

Might I suggest that instead of converting to <br>, it's converted to <br/>. I know that HTML5 doesn't require the XHTML-style self-closing tag, but having the self-closing tag means you won't piss off developers who are still bound to doctypes that require it.

cgiffard commented 12 years ago

Semantically speaking, it's probably better to \n to <br/> and \n\n to <p>(content of line)</p>.

Also agree about the self-closing tag. HTML5 supports an XML-parseable polyglot syntax, and the self-closing style is allowed under the doctype.

abitgone commented 12 years ago

Also suggest that even single line posts are wrapped in a <p> element.

That said, I'm not sure I'm totally keen on having a HTML version of the post content sent with the original content (I'm fairly certain this has already been discussed in issues #8 and #20) as then you're responsible for multiple versions of the same content.

Additionally, who's responsible for setting this? The client (which has to generate and send multiple versions of the same content)? The API (which has to generate multiple versions server-side)? Is it open to abuse? How about we have a markdown version of each post?

I'm going off the topic of this issue here.

edent commented 12 years ago

I agree with <br/>. I can see the rationale for <p> as well, but are there restrictions in nesting <p> in other tags?

@abitgone I would expect clients to send plain text. The generated HTML is a best effort designed to reduce developer overhead & increase consistency.

abitgone commented 12 years ago

@edent Marvellous. That's exactly what I would expect.

cgiffard commented 12 years ago

@edent Ideally, a post - especially a multiline post - should be contained in a block-level element, and if somebody's doing anything different to it, they probably won't be interested in the HTML anyway. <p> will happily nest inside any block.

abitgone commented 12 years ago

@edent Exactly what @cgiffard said – a <p> element will happily nest inside any block-level element. Generally speaking, as long as the API and the output is clearly defined, designers will know what to do and what to expect.

mthurman commented 11 years ago

We now translate \n ->
. This helps clients quickly present posts as html that looks very similar to the underlying post text. If clients want a more complex text -> html processing, they can customize that.

mthurman commented 11 years ago

\n -> <br> :) since I didn't remember you can type html here