Strange encoding issue

Plugin Development
  • Plugin & Theme Dev

    Trying to write a nodebb plugin but I'm experiencing some strange result when trying to parse a post (0.7.0 latest).

    I'm picking up the data from data.postData.content which contains a a-tag with url like this:

    <a href="">

    But the parameter-separator & of the url turn into &amp; which makes it really hard to pick up the parameter-values.;p=4711

    Are there any preprocessing going on before handing over the parse post data? It happens to all urls in the post with parameters.

    (I've moved up my plugin to run first of all in the prio queue)

  • Plugin & Theme Dev

    Hasn't anyone noticed this problem?

    All link processing in a plugins will become much more hackey where I have to

    Embed.parse = function(data, callback) {
        var match = /<a\s+[^>]*href="([^"]*)"[^>]*>/i.exec(data.postData.content);
        var url = match[1];    // <-- In this url all parameter is separated by &amp; instead of &
        // Ugly fix
        realUrl = replace(/\&amp;/g, '&');
        // Should I change it back to &amp; before doing callback?

    Somewhere in the pipe after plugin.parse url:s get translated back by NodeBB so this isn't visible in the forum. But I want to manipulate the url parameter on-it's-way to the end-user.

  • GNU/Linux

    At default priority (5) and run before markdown, you should be seeing the link before it turns into an anchor tag. Make sure your plugin is executed before markdown (though it does seem like you did that already...)

    Maybe if you set priority of 4 for the hook, that might do it.

  • Plugin & Theme Dev

    Yes, that's it! Setting prio 4 gives access to the markup.

    I'd also like to add a custom "card" at the bottom of the post (like in github-issue plugin). But what happens if I start inserting a html template in this phase? Guess it will mess up markup parsing in a later phase? The plugin.json looks like this:

        "id": "nodebb-plugin-affiliate",
        "name": "Affiliate",
        "description": "Earn money on your user generated content. Converts links in posts to affiliate variants (ebay, aliexpress, amazon, banggood, ...). With an optional box showing product image, price and stock availablility.",
        "url": "",
        "library": "./index.js",
        "templates": "templates",
        "less": [
        "hooks": [
            { "hook": "", "method": "parse", "priority": 4 },
            { "hook": "filter:parse.raw", "method": "parse", "priority": 4  },
            { "hook": "static:app.load", "method": "init" },
            { "hook": "", "method": "buildMenu" }
        "staticDirs": {
            "static": "./static"
  • GNU/Linux

    If you add html at priority level 4, it would get stripped out by the markdown plugin... so we're back to the original problem with the escaped &...

  • Plugin & Theme Dev

    Yeah, just realised that... I'd better go back to my old strategy.

  • GNU/Linux

    If the markdown plugin turns the & into &amp;, does it end up showing up incorrectly in the final parsed HTML?

  • Plugin & Theme Dev

    Yepp.. I convert it back after parsing manipulating the url.

Suggested Topics

| | | |