filter:post.parse and filter:post.parseSignature changes

NodeBB Development
  • If you have any plugins that use filter:post.parse or filter:post.parseSignature please read below on the changes coming in 0.6.0. If you have any questions about how to update to the new hooks please feel free to ask.

    filter:post.parse ->

    filter:post.parse used to take only a single parameter which was the string to be parsed this has been changed along with the hook name. The new filter name is and it takes an object as the parameter.

    plugins.fireHook('', {postData: postData, uid: uid}, callback);

    postData is the post being parsed, from your plugin you can access the content with data.postData.content. uid is the user who is calling this hook. Here is a sample plugin function.

    parsePost: function(data, callback) {
    	if (data && data.postData && data.postData.content) {
    		data.postData.content = parser.render(data.postData.content);
    	callback(null, data);

    filter:post.parseSignature -> filter:parse.signature

    Similar to filter:post.parse the hook name changed to filter:parse.signature and the parameter changed to an object.

    plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);

    The hook is passed a userData object and the user id of the user calling the hook. The signature is accessible from the plugin by data.userData.signature.

    filter:parse.raw (new hook)

    This is just to keep functionality from the previous versions. This hook just takes a string as a parameter and parses it.

    plugins.fireHook('filter:parse.raw', content, callback);

    Used in composer preview/help, chat message content etc.

    I will be updating the following plugins to work with these new filters.

    • nodebb-plugin-markdown
    • nodebb-plugin-mentions
    • nodebb-plugin-youtube
    • nodebb-plugin-twitter-hashtag
  • @baris Not sure if related, but trying to update my youtube plugin to support the changes gives me infinite loop crash. Is fine when I disable the plugin again.

    2014-11-08T12:40:21.717Z - error: /500
    Error: Failed to lookup view "footer" in views directory "/home/a_5mith/35hz/public/templates"
    at (/home/a_5mith/35hz/node_modules/express/lib/application.js:519:17)
    at Object.async.parallel.footer (/home/a_5mith/35hz/src/middleware/middleware.js:225:8)
    at /home/a_5mith/35hz/node_modules/async/lib/async.js:583:25
    at /home/a_5mith/35hz/node_modules/async/lib/async.js:125:13
    at Array.forEach (native)
    at _each (/home/a_5mith/35hz/node_modules/async/lib/async.js:46:24)
    at Object.async.each (/home/a_5mith/35hz/node_modules/async/lib/async.js:124:9)
    at _parallel (/home/a_5mith/35hz/node_modules/async/lib/async.js:582:20)
    at Object.async.parallel (/home/a_5mith/35hz/node_modules/async/lib/async.js:598:9)
    at middleware.buildHeader (/home/a_5mith/35hz/src/middleware/middleware.js:220:8)
  • hey, it seems like this breaks plugins that might operate on links.

    If its priority is too low, the html the plugin could output is escaped. If it is too high, the markdown auto-linkifier will run on the link which will feed our plugin some html where the original link would be.

  • @dwn Is that something you've experienced already? I was taking a look at @a_5mith 's youtube lite plugin but there doesn't even seem to be the notion of priority anymore.

  • @BDHarrington7 yeah, I'm trying to update his gfycat plugin to work. I have no idea how his youtube-lite plugin catches links before they're linkified, but this does not. It seems like they're functionally the same.

  • As far as I know, the functionality hasn't changed, it's just been renamed, and the arguments have been swapped around (that's what makes it a breaking change).

    Markdown listens on priority 5, listen on 6 or 4 if you want to handle links before or after (though for the life of me I can't remember which is which).

    Better bet would be to write a plugin for the underlying remarkable parser we use, although we don't have any examples of that yet...

  • @julian said:

    Markdown listens on priority 5, listen on 6 or 4 if you want to handle links before or after (though for the life of me I can't remember which is which).

    listening on a lower priority and adding HTML will result in the HTML being escaped by the markdown plugin on 5. listening on 5 or greater -- or not specifying a priority, results in your plugin seeing link HTML in many varied cases.

    the issue is pretty much certainly not related to this thread though. youtube-lite seems to work fine, I'm sure there is some trick to this in there.

  • @dwn been meaning to look at that. 😆 accepting PRs.

    The majority of my plugins don't use a priority, but do use callbacked:true. Unless there's some default behaviour when that happens, like only converting at the end for example, after markdown has parsed everything, I'm not sure. I'm not sure what made the gfycat plugin stop working. One day it worked, the next, less so. 😞

  • @dwn I see your problem (although, I'm not sure why your plugin was working before, maybe the defaults changed on the markdown plugin, defaulting to linkifying urls where it wasn't before?). Anyway, the way @a_5mith and I are handling it is assuming the link to be wrapped in the anchor tag, and then parsing that out, running at a priority > 5. You can write your regex in a way that handles either case, but the trick you need to implement is to look for "<a href=" before the actual url.

    Admittedly this is really hacky and we shouldn't be parsing html with regex in the first place, but that should get you up and running. If you need help, just ask, or take a look at the regex strings for youtube-lite or imgbed

    If you do go this route, don't try to do it on priority < 5, as the markdown parser will escape the html if the setting for that is on (but you already knew that).

  • I've updated the plugin for 0.6.0, got it running, just need to diagnose why it's not working. It's getting to the winston warn about raw coming back as false. Not sure why. Will do some digging, see what I can pull out.

    If anyone fancies taking a look at that, I'm pretty stumped.

    30/11 16:34 [11326] - warn: Encountered an error parsing gfycat embed code, not continuing false
    This is the data: false [ undefined ]

    Here ish

  • What is the error?

     else {
            winston.warn('Encountered an error parsing gfycat embed code, not continuing', raw);
            console.log('This is the data:', raw, gfycatinfo)
            callback(null, data);

    If it goes in there it means there is an error, try console.log(err.stack);

  • @baris Thanks Baris, that showed the issue, was using // as the URI instead of https which was incorrect apparently. 😆

    Plugin updated to 1.1.5 for 0.6.0 of NodeBB.

Suggested Topics