-
Notifications
You must be signed in to change notification settings - Fork 940
Coderwall: Update to handle markdown content from API (fixes #2548) #2632
Coderwall: Update to handle markdown content from API (fixes #2548) #2632
Conversation
@xaviervalarino Hey! Thanks for taking the time to contribute! We really appreciate it. We work closely with every contributor to make Instant Answers the best they can be, so we appreciate your patience as we look over your code. From here, the process usually goes like this:
If you have any questions along the way, feel free to ask them here. Our staff and community are also available on Slack to answer any questions you may have. If you'd like to join us there please send an email to [email protected].
Thanks! |
CoderwallDescription: Display information about a coderwall.com user Example Query: [coderwall jpcamara](https://beta.duckduckgo.com/?q=coderwall jpcamara) Tab Name: Social Source: These are the important fields from the IA page. Please check these for errors or missing information and update the IA page This is an automated message which will be updated as changes are made to the IA page |
}; | ||
|
||
Handlebars.registerHelper("parseMD", function(content){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you get this from anywhere? If so it'd be useful to include a link to reference so peeps can check out more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an original handlebars helper. It might be best to switch it out with something that is tried-and-true. The only search result that seemed promising to me was helper-markdown, which has remarkable as a dependency.
0d4c2ab
to
8cc142a
Compare
I force pushed this branch. I realized doing so is strongly discouraged only after reading through the original PR for this IA. Sorry! |
@xaviervalarino Don't look at any of my PRs 😉 |
Deploying to beta... |
@xaviervalarino I'm getting a JS error in the console: |
@xaviervalarino false alarm, it looks like the code on Beta is still old... it's failing on |
@xaviervalarino alright the correct code is there now, but we have another problem. the input to the ellipsis function is causing problems. I think you're going to need to use the |
@moollaza I've been having trouble with both helpers! I update the Even when I just return a normal string, these helpers are still counting the characters in the HTML tags, which results in incomplete and malformed tags: condense
ellipsis |
line = line.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>') // bold | ||
.replace(/(?:_(.+?)_|\*(.+?)\*)/g, '<em>$1$2</em>') // italicize | ||
.replace(/`(.+?)`/g, '<code>$1</code>') // monospace | ||
.replace(/~~(.+?)~~/g, '<del>$1</del>') // strikethrough |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need any help with HTML escaping check out MarkdownReference - I found a pretty good helper for it a while back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! I can definitely see myself referring to those entities in the future. What do you mean by escaping the HTML, though? Wouldn't escaping it turn the description into a garbled mess of markup + text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For code
blocks you can use it to ensure HTML doesn't decide to take it upon itself to start changing things. If you look in the Handlebars for MarkdownReference you'll see what I mean.
You might not need it, but it is there if you do.
@moollaza I have a couple of ideas for how to work around this: Short Term
Long TermCreate issues and/or PRs to
{{condense (parseMD description) maxleng='300' ignoretags='true' truncation='...'}}
...
{{ellipsis (parseMD description) 300 ignoreTags}} Then come back and clean up the Codewall IA (Sorry if this is a little didactic, I just had the impression we wanted to get this out the door sooner rather than later since #2548 is marked as a high priority issue.) |
@xaviervalarino thanks again for improving the Coderwall Spice! You’ve been doing a really good job here and we'd like you to help our community tackle the next big challenge - our mission to become the best search engine for programmers: https://duck.co/blog/post/297/help-for-programmers. When you're ready to move on, please:
OR
Detailed instructions explaining how you can help are available at the top of this page. Thanks again! |
EDIT: Coderwall changed the API object (again).latest commit fixes this issue. |
Coderwall has changed some of the keys on their API. ( i.e., api_result.data --> api_result.user api_result.avatar.url --> api_result.thumbnail ) Small changes, but frustrating to have to fix them in less than a 2 month time span.
- Cleans up some soft tabs from 2 to 4 - Handlebars helper is registered with Spice - Handlesbars helper is namespaced
Some of the older user avatars on coderwall have a 20px border around them that looks god-awful with the iconImage template. This CSS file enlarges the image ~120% in order hide that border.
@zachthompson I remember reading in your PR that there was some issues with the white border on the profile images for older account. The custom CSS in the latest commit should fix this. |
This commit adds minor fixes to the Markdown Handlebars helper. Specifically, the replace methods used to parse italics and bold. Coderwall's markdown parser seems to be based on Github's. Although italics and bold don't result in any visual change on their site, the parser is still marking up the <em> and <strong> tags. So, as of writing this, Coderwall will markup this syntax: *word* --> italic _word_ --> italic __word__ --> bold **word** --> bold `word` --> monospace/code ~~word~~ --> strikethrough [word](url) --> link They are also parsing ordered/unordered lists and headers. My inclination is to not parse these, as it seems (anecdotally) that this is not commonly used by users when they author their descriptions, and, mainly, because rendering the lists and headers will very quickly bloat div.cz-main and eat up a lot of vertically space. Coderwall does _NOT_ parsing images or tables.
{{#coderwall_substr_html}} is a custom block helper that trims HTML text to a specific length. It does this by parsing the context/string into HTML. The helper then iterates through each text node, and then, if the textContent is longer than the specified character limit, the text is trimmed to the closest word. Once the limit is hit, all remaining nodes are exluded. Ideally, this custom helper will be a temporary solution until the built-in {{#condense}} block helper supports markup.
@moollaza i've created a custom block helper that trims any description over 250 characters to the closest word. I also created a Codepen that uses these helpers so that you can play around with different character limits and custom markdown. That sort of closes out everything I wanted to do for this IA. |
LGTM 👍 |
This PR fixes the issue described in #2548
Fixes include:
normalize
to match the new Coderwall API responsedescription
iconImage
@moollaza suggested also using
chompContent
to hide descriptions that are too long, but I am not sure how to implement it.CC: @GuiltyDolphin
IA Page: https://duck.co/ia/view/coderwall