nodebb-plugin-markdown 12.2.8 → 13.0.0-pre.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jshintrc +85 -85
- package/README.md +9 -9
- package/index.js +37 -5
- package/package-lock.json +4148 -0
- package/package.json +3 -4
- package/public/languages/de/markdown.json +12 -12
- package/public/languages/en-GB/markdown.json +12 -12
- package/public/languages/fa-IR/markdown.json +11 -11
- package/public/languages/fr/markdown.json +11 -11
- package/public/languages/he/markdown.json +12 -12
- package/public/languages/pl/markdown.json +11 -11
- package/public/languages/tr/markdown.json +11 -11
- package/public/languages/zh-CN/markdown.json +11 -11
package/.jshintrc
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
{
|
|
2
|
-
// JSHint Default Configuration File (as on JSHint website)
|
|
3
|
-
// See http://jshint.com/docs/ for more details
|
|
4
|
-
|
|
5
|
-
"maxerr" : 50, // {int} Maximum error before stopping
|
|
6
|
-
|
|
7
|
-
// Enforcing
|
|
8
|
-
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
|
|
9
|
-
"camelcase" : false, // true: Identifiers must be in camelCase
|
|
10
|
-
"curly" : true, // true: Require {} for every new block or scope
|
|
11
|
-
"eqeqeq" : true, // true: Require triple equals (===) for comparison
|
|
12
|
-
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
|
|
13
|
-
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
|
|
14
|
-
"indent" : 4, // {int} Number of spaces to use for indentation
|
|
15
|
-
"latedef" : false, // true: Require variables/functions to be defined before being used
|
|
16
|
-
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
|
|
17
|
-
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
|
|
18
|
-
"noempty" : true, // true: Prohibit use of empty blocks
|
|
19
|
-
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
|
|
20
|
-
"plusplus" : false, // true: Prohibit use of `++` & `--`
|
|
21
|
-
"quotmark" : false, // Quotation mark consistency:
|
|
22
|
-
// false : do nothing (default)
|
|
23
|
-
// true : ensure whatever is used is consistent
|
|
24
|
-
// "single" : require single quotes
|
|
25
|
-
// "double" : require double quotes
|
|
26
|
-
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
|
|
27
|
-
"unused" : true, // true: Require all defined variables be used
|
|
28
|
-
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
|
|
29
|
-
"trailing" : false, // true: Prohibit trailing whitespaces
|
|
30
|
-
"maxparams" : false, // {int} Max number of formal params allowed per function
|
|
31
|
-
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
|
|
32
|
-
"maxstatements" : false, // {int} Max number statements per function
|
|
33
|
-
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
|
|
34
|
-
"maxlen" : false, // {int} Max number of characters per line
|
|
35
|
-
|
|
36
|
-
// Relaxing
|
|
37
|
-
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
|
|
38
|
-
"boss" : false, // true: Tolerate assignments where comparisons would be expected
|
|
39
|
-
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
|
|
40
|
-
"eqnull" : false, // true: Tolerate use of `== null`
|
|
41
|
-
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
|
|
42
|
-
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
|
|
43
|
-
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
|
|
44
|
-
// (ex: `for each`, multiple try/catch, function expression…)
|
|
45
|
-
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
|
|
46
|
-
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
|
|
47
|
-
"funcscope" : false, // true: Tolerate defining variables inside control statements"
|
|
48
|
-
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
|
|
49
|
-
"iterator" : false, // true: Tolerate using the `__iterator__` property
|
|
50
|
-
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
|
|
51
|
-
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
|
|
52
|
-
"laxcomma" : false, // true: Tolerate comma-first style coding
|
|
53
|
-
"loopfunc" : false, // true: Tolerate functions being defined in loops
|
|
54
|
-
"multistr" : false, // true: Tolerate multi-line strings
|
|
55
|
-
"proto" : false, // true: Tolerate using the `__proto__` property
|
|
56
|
-
"scripturl" : false, // true: Tolerate script-targeted URLs
|
|
57
|
-
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
|
|
58
|
-
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
|
|
59
|
-
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
|
|
60
|
-
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
|
|
61
|
-
"validthis" : false, // true: Tolerate using this in a non-constructor function
|
|
62
|
-
|
|
63
|
-
// Environments
|
|
64
|
-
"browser" : true, // Web Browser (window, document, etc)
|
|
65
|
-
"couch" : false, // CouchDB
|
|
66
|
-
"devel" : true, // Development/debugging (alert, confirm, etc)
|
|
67
|
-
"dojo" : false, // Dojo Toolkit
|
|
68
|
-
"jquery" : true, // jQuery
|
|
69
|
-
"mootools" : false, // MooTools
|
|
70
|
-
"node" : true, // Node.js
|
|
71
|
-
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
|
|
72
|
-
"prototypejs" : false, // Prototype and Scriptaculous
|
|
73
|
-
"rhino" : false, // Rhino
|
|
74
|
-
"worker" : false, // Web Workers
|
|
75
|
-
"wsh" : false, // Windows Scripting Host
|
|
76
|
-
"yui" : false, // Yahoo User Interface
|
|
77
|
-
|
|
78
|
-
// Legacy
|
|
79
|
-
"nomen" : false, // true: Prohibit dangling `_` in variables
|
|
80
|
-
"onevar" : false, // true: Allow only one `var` statement per function
|
|
81
|
-
"passfail" : false, // true: Stop on first error
|
|
82
|
-
"white" : false, // true: Check against strict whitespace and indentation rules
|
|
83
|
-
|
|
84
|
-
// Custom Globals
|
|
85
|
-
"globals" : {} // additional predefined global variables
|
|
1
|
+
{
|
|
2
|
+
// JSHint Default Configuration File (as on JSHint website)
|
|
3
|
+
// See http://jshint.com/docs/ for more details
|
|
4
|
+
|
|
5
|
+
"maxerr" : 50, // {int} Maximum error before stopping
|
|
6
|
+
|
|
7
|
+
// Enforcing
|
|
8
|
+
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
|
|
9
|
+
"camelcase" : false, // true: Identifiers must be in camelCase
|
|
10
|
+
"curly" : true, // true: Require {} for every new block or scope
|
|
11
|
+
"eqeqeq" : true, // true: Require triple equals (===) for comparison
|
|
12
|
+
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
|
|
13
|
+
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
|
|
14
|
+
"indent" : 4, // {int} Number of spaces to use for indentation
|
|
15
|
+
"latedef" : false, // true: Require variables/functions to be defined before being used
|
|
16
|
+
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
|
|
17
|
+
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
|
|
18
|
+
"noempty" : true, // true: Prohibit use of empty blocks
|
|
19
|
+
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
|
|
20
|
+
"plusplus" : false, // true: Prohibit use of `++` & `--`
|
|
21
|
+
"quotmark" : false, // Quotation mark consistency:
|
|
22
|
+
// false : do nothing (default)
|
|
23
|
+
// true : ensure whatever is used is consistent
|
|
24
|
+
// "single" : require single quotes
|
|
25
|
+
// "double" : require double quotes
|
|
26
|
+
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
|
|
27
|
+
"unused" : true, // true: Require all defined variables be used
|
|
28
|
+
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
|
|
29
|
+
"trailing" : false, // true: Prohibit trailing whitespaces
|
|
30
|
+
"maxparams" : false, // {int} Max number of formal params allowed per function
|
|
31
|
+
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
|
|
32
|
+
"maxstatements" : false, // {int} Max number statements per function
|
|
33
|
+
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
|
|
34
|
+
"maxlen" : false, // {int} Max number of characters per line
|
|
35
|
+
|
|
36
|
+
// Relaxing
|
|
37
|
+
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
|
|
38
|
+
"boss" : false, // true: Tolerate assignments where comparisons would be expected
|
|
39
|
+
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
|
|
40
|
+
"eqnull" : false, // true: Tolerate use of `== null`
|
|
41
|
+
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
|
|
42
|
+
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
|
|
43
|
+
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
|
|
44
|
+
// (ex: `for each`, multiple try/catch, function expression…)
|
|
45
|
+
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
|
|
46
|
+
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
|
|
47
|
+
"funcscope" : false, // true: Tolerate defining variables inside control statements"
|
|
48
|
+
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
|
|
49
|
+
"iterator" : false, // true: Tolerate using the `__iterator__` property
|
|
50
|
+
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
|
|
51
|
+
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
|
|
52
|
+
"laxcomma" : false, // true: Tolerate comma-first style coding
|
|
53
|
+
"loopfunc" : false, // true: Tolerate functions being defined in loops
|
|
54
|
+
"multistr" : false, // true: Tolerate multi-line strings
|
|
55
|
+
"proto" : false, // true: Tolerate using the `__proto__` property
|
|
56
|
+
"scripturl" : false, // true: Tolerate script-targeted URLs
|
|
57
|
+
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
|
|
58
|
+
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
|
|
59
|
+
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
|
|
60
|
+
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
|
|
61
|
+
"validthis" : false, // true: Tolerate using this in a non-constructor function
|
|
62
|
+
|
|
63
|
+
// Environments
|
|
64
|
+
"browser" : true, // Web Browser (window, document, etc)
|
|
65
|
+
"couch" : false, // CouchDB
|
|
66
|
+
"devel" : true, // Development/debugging (alert, confirm, etc)
|
|
67
|
+
"dojo" : false, // Dojo Toolkit
|
|
68
|
+
"jquery" : true, // jQuery
|
|
69
|
+
"mootools" : false, // MooTools
|
|
70
|
+
"node" : true, // Node.js
|
|
71
|
+
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
|
|
72
|
+
"prototypejs" : false, // Prototype and Scriptaculous
|
|
73
|
+
"rhino" : false, // Rhino
|
|
74
|
+
"worker" : false, // Web Workers
|
|
75
|
+
"wsh" : false, // Windows Scripting Host
|
|
76
|
+
"yui" : false, // Yahoo User Interface
|
|
77
|
+
|
|
78
|
+
// Legacy
|
|
79
|
+
"nomen" : false, // true: Prohibit dangling `_` in variables
|
|
80
|
+
"onevar" : false, // true: Allow only one `var` statement per function
|
|
81
|
+
"passfail" : false, // true: Stop on first error
|
|
82
|
+
"white" : false, // true: Check against strict whitespace and indentation rules
|
|
83
|
+
|
|
84
|
+
// Custom Globals
|
|
85
|
+
"globals" : {} // additional predefined global variables
|
|
86
86
|
}
|
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# NodeBB Markdown Parser
|
|
2
|
-
|
|
3
|
-
This NodeBB plugin is a parser that allows users to write posts using [Markdown](https://daringfireball.net/projects/markdown/).
|
|
4
|
-
|
|
5
|
-
To customise options for the parser, please consult the "Markdown" page in the administration panel, under the "Plugins" heading.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
npm install nodebb-plugin-markdown
|
|
1
|
+
# NodeBB Markdown Parser
|
|
2
|
+
|
|
3
|
+
This NodeBB plugin is a parser that allows users to write posts using [Markdown](https://daringfireball.net/projects/markdown/).
|
|
4
|
+
|
|
5
|
+
To customise options for the parser, please consult the "Markdown" page in the administration panel, under the "Plugins" heading.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
npm install nodebb-plugin-markdown
|
package/index.js
CHANGED
|
@@ -7,9 +7,9 @@ const path = require('path');
|
|
|
7
7
|
const nconf = require.main.require('nconf');
|
|
8
8
|
const winston = require.main.require('winston');
|
|
9
9
|
const meta = require.main.require('./src/meta');
|
|
10
|
+
const activitypub = require.main.require('./src/activitypub');
|
|
10
11
|
const translator = require.main.require('./src/translator');
|
|
11
12
|
const plugins = require.main.require('./src/plugins');
|
|
12
|
-
const cacheCreate = require.main.require('./src/cacheCreate');
|
|
13
13
|
|
|
14
14
|
const SocketPlugins = require.main.require('./src/socket.io/plugins');
|
|
15
15
|
SocketPlugins.markdown = require('./websockets');
|
|
@@ -133,9 +133,10 @@ const Markdown = {
|
|
|
133
133
|
|
|
134
134
|
parsePost: async function (data) {
|
|
135
135
|
const env = await Markdown.beforeParse(data);
|
|
136
|
-
if (data && data.postData && data.postData.content && parser) {
|
|
136
|
+
if (env.parse && data && data.postData && data.postData.content && parser) {
|
|
137
137
|
data.postData.content = parser.render(data.postData.content, env || {});
|
|
138
138
|
}
|
|
139
|
+
|
|
139
140
|
return Markdown.afterParse(data);
|
|
140
141
|
},
|
|
141
142
|
|
|
@@ -157,11 +158,25 @@ const Markdown = {
|
|
|
157
158
|
return Markdown.afterParse(raw);
|
|
158
159
|
},
|
|
159
160
|
|
|
160
|
-
beforeParse: async (
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
beforeParse: async (data) => {
|
|
162
|
+
let env = {
|
|
163
|
+
parse: true,
|
|
164
|
+
type: data.type,
|
|
165
|
+
images: new Map(), // is this still used?
|
|
163
166
|
};
|
|
164
167
|
|
|
168
|
+
({ env } = await plugins.hooks.fire('filter:markdown.beforeParse', { env, data: Object.freeze({ ...data }) }));
|
|
169
|
+
|
|
170
|
+
if (activitypub.helpers.isUri(data.postData.pid)) {
|
|
171
|
+
if (data.postData.sourceContent) {
|
|
172
|
+
data.content = data.sourceContent;
|
|
173
|
+
delete data.sourceContent;
|
|
174
|
+
} else {
|
|
175
|
+
// content contained is likely already html, bypass parsing
|
|
176
|
+
env.parse = false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
165
180
|
return env;
|
|
166
181
|
},
|
|
167
182
|
|
|
@@ -283,6 +298,10 @@ const Markdown = {
|
|
|
283
298
|
parser.renderer.rules.image = function (tokens, idx, options, env, self) {
|
|
284
299
|
const token = tokens[idx];
|
|
285
300
|
const attributes = new Map(token.attrs);
|
|
301
|
+
if (env.type === 'plaintext') {
|
|
302
|
+
const filename = path.basename(attributes.get('src'));
|
|
303
|
+
return `[image: ${filename}]`;
|
|
304
|
+
}
|
|
286
305
|
|
|
287
306
|
// Validate the url
|
|
288
307
|
if (!Markdown.isUrlValid(attributes.get('src'))) { return ''; }
|
|
@@ -293,6 +312,10 @@ const Markdown = {
|
|
|
293
312
|
};
|
|
294
313
|
|
|
295
314
|
parser.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
|
315
|
+
if (env.type === 'plaintext') {
|
|
316
|
+
return '';
|
|
317
|
+
}
|
|
318
|
+
|
|
296
319
|
const attributes = new Map(tokens[idx].attrs);
|
|
297
320
|
|
|
298
321
|
if (attributes.has('href') && Markdown.isExternalLink(attributes.get('href'))) {
|
|
@@ -326,6 +349,15 @@ const Markdown = {
|
|
|
326
349
|
return renderLink(tokens, idx, options, env, self);
|
|
327
350
|
};
|
|
328
351
|
|
|
352
|
+
parser.renderer.rules.link_close = function (...args) {
|
|
353
|
+
const [,,, env, self] = args;
|
|
354
|
+
if (env === 'plaintext') {
|
|
355
|
+
return '';
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return self.renderToken(...args);
|
|
359
|
+
};
|
|
360
|
+
|
|
329
361
|
parser.renderer.rules.table_open = function (tokens, idx, options, env, self) {
|
|
330
362
|
const classIdx = tokens[idx].attrIndex('class');
|
|
331
363
|
|