FEATURE: Add the title attribute to polls (PR #10759)

Adds an optional title attribute to polls. The rationale for this addition is that polls themselves didn’t contain context/question and relied on post body to explain them. That context wasn’t always obvious (e.g. when there are multiple polls in a single post) or available (e.g. when you display the poll breakdown - you see the answers, but not the question)

As a side note, here’s a word on how poll plugin works:

We have a markdown poll renderer, which we use in the builder UI and the composer preview, but… when you submit a post, raw markdown is cooked into html (twice), then we extract data from the generated html and save it to the database. When it’s render time, we first display the cooked html poll, and then extract some data from that html, get the data from the post’s JSON (and identify that poll using the extracted html stuff) to then render the poll using widgets and the JSON data.

Screen Shot 2020-09-28 at 14 44 45 Screen Shot 2020-09-28 at 15 09 53

Screen Shot 2020-09-28 at 15 10 30

GitHub

That would be a perfect case for using the ternary operator.

    return pollTitle ? htmlSafe(pollTitle) : topicTitle;

Also, why does the pollTitle require htmlSafe and not topicTitle?

:heart: it when we removed TODO :clap:

In Ruby, you can merge both lines

          if title_element = p.css(".poll-title").first

Niice :+1:

LGTM :+1:

I personally avoid this construct, seeing it triggers my mental autocorrect “Did you mean… ==?” :wink:

1 Like

pollTitle inherits all properties of markdown heading, like ability to add bold/italic sections, links, inline code blocks, etc, so it emits full html. Topic titles are more restricted as they are not parsed at all.