How to use the post parser(s) installed as if what you want parsed is a post
-
Say I want the following text parsed:
Blah blah blah **bold** and stuff Markdown is fun ----------- [link](http://example.com)
And to come out like this:
Blah blah blah bold and stuff
Markdown is fun
How would I do this with the enabled post parser in NodeBB?
I imagine it requires triggering a hook.
-
@julian Listen for it? But inside my plugin, I want to parse some stuff with the installed parser(s)
-
@pitaj sometime ago I searched the same, and I found it in @Schamper 's plugin Shoutbox https://github.com/Schamper/nodebb-plugin-shoutbox/blob/master/lib/backend.js#L107-L122
By the way why you all are using
@julian said:
var plugins = module.parent.require('./plugins');
such strange pattern for requiring modules?
In some places of my plugins, I'd have to do
var db = module.parent.parent.parent.parent.parent.require( './database' );
Of course this way works, but personally I prefer the method which looks purer
var db = require.main.require( './src/database' );
@julian @baris @psychobunny tell me please, is there any special reasons, why don't use require.main?
-
You're correct
-
is there any special reasons, why don't use require.main?
You're correct
Could you explain please?
-
@Mega I'm guessing that they didn't know about it, and neither did I
-
@Schamper Majide? O_ O
http://nodejs.org/api/modules.html#modules_accessing_the_main_module
In a nutshell, inside all plugins, as well as inside all core modules
require.main
is always equals tomodule
variable that live insideNodeBB/app.js
One important question: Is there the same behaviour in cluster-mode?
So it needs a confirmation from core developers.@julian @baris @psychobunny pleeease
-
@Mega as @Schamper said, I only discovered this last week, so we use
require.parent.parent/etc
for everything, butrequire.main
works just as well.Keep in mind
require.main
's "scope" isapp.js
, so you'd have to dorequire.main.require('./src/groups.js');
if you want access to the groups lib.require.main
will always beapp.js
for plugins, since plugins are only called by NodeBB.