These are chat archives for jescalan/roots

13th
Mar 2017
Tom Kraak
@tkraak
Mar 13 2017 00:00
@JonathanReeve … can’t be passed to the teamplate in the same way?
Jonathan Reeve
@JonathanReeve
Mar 13 2017 00:03
marked is a funtion from the start, so I can do markdown = require 'marked' and then locals: md: marked, but you can't just substitute markdown-it, because if you do, you're just passing the module, not a function.
If you run markdown = require 'marked' and then markdown('*test*'), you get <em>test</em>, as expected. But to do the sme for markdown-it, you have to run markdownIt = require 'marked', markdown = new markdownIt, and then markdown.renderInline('*test*'). So if you try to pass the renderInlinefunction to the template, via locals:, it gives an error related to the fact, I think, that it doesn't have its associated objet.
*object
Tom Kraak
@tkraak
Mar 13 2017 00:38
md = require('markdown-it')() … that won’t work?
Covington Doan
@covingtondoan
Mar 13 2017 00:39
Have you tried | {{{ marked(content) }}}?
I think that gets around the need to wrap in a p tag
Jonathan Reeve
@JonathanReeve
Mar 13 2017 00:42
md = require('markdown-it')() works too, but you still can't seem to pass the template a markdown-rendering function, as far as I can tell.
@covingtondoan, I'm not sure I understand where to use that.
Covington Doan
@covingtondoan
Mar 13 2017 00:47
In your template, instead of p {{{ marked(content) }}}
Jonathan Reeve
@JonathanReeve
Mar 13 2017 01:14
@covingtondoan, the issue is that marked automatically wraps strings in <p>--it's not in my template. I'm just doing span!= md(data). If you run marked('*test*') on its own, you get <p><em>test</em></p> instead of <em>test</em>, as expected.
Jeff Escalante
@jescalan
Mar 13 2017 04:53
@JonathanReeve its a scope issue
md.renderInline.bind(md) will solve it
since you are passing a function that is called with a context, when it goes through the function params it loses the context
so you need to bind it before passing
sorry for the late response here!
Jonathan Reeve
@JonathanReeve
Mar 13 2017 14:14
Ah thanks! As a Javascript beginner, I had no idea about .bind(). Will try that.
Jeff Escalante
@jescalan
Mar 13 2017 16:08
Yeah it's definitely a unique feature to JavaScript, but super important! Might make some videos on this kind of stuff, bc i know not everyone coming in to use roots and spike is in super deep with js