nodebb-plugin-markdown 13.0.0-pre.8 → 13.0.0
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/index.js +28 -10
- package/package-lock.json +2161 -775
- package/package.json +1 -1
- package/public/languages/de/markdown.json +1 -1
- package/public/languages/en-GB/markdown.json +1 -1
- package/public/languages/fr/markdown.json +1 -1
- package/public/languages/pl/markdown.json +1 -1
- package/public/languages/ru/markdown.json +1 -1
- package/public/languages/tr/markdown.json +1 -1
- package/public/templates/modals/markdown-help.tpl +3 -0
package/index.js
CHANGED
|
@@ -8,7 +8,6 @@ const nconf = require.main.require('nconf');
|
|
|
8
8
|
const winston = require.main.require('winston');
|
|
9
9
|
const meta = require.main.require('./src/meta');
|
|
10
10
|
const activitypub = require.main.require('./src/activitypub');
|
|
11
|
-
const translator = require.main.require('./src/translator');
|
|
12
11
|
const plugins = require.main.require('./src/plugins');
|
|
13
12
|
|
|
14
13
|
const SocketPlugins = require.main.require('./src/socket.io/plugins');
|
|
@@ -136,6 +135,7 @@ const Markdown = {
|
|
|
136
135
|
if (env.parse && data && data.postData && data.postData.content && parser) {
|
|
137
136
|
data.postData.content = parser.render(data.postData.content, env || {});
|
|
138
137
|
}
|
|
138
|
+
|
|
139
139
|
return Markdown.afterParse(data);
|
|
140
140
|
},
|
|
141
141
|
|
|
@@ -160,17 +160,20 @@ const Markdown = {
|
|
|
160
160
|
beforeParse: async (data) => {
|
|
161
161
|
let env = {
|
|
162
162
|
parse: true,
|
|
163
|
+
type: data.type,
|
|
163
164
|
images: new Map(), // is this still used?
|
|
164
165
|
};
|
|
165
166
|
|
|
166
167
|
({ env } = await plugins.hooks.fire('filter:markdown.beforeParse', { env, data: Object.freeze({ ...data }) }));
|
|
167
168
|
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
if (activitypub.helpers.isUri(data.postData.pid)) {
|
|
170
|
+
if (data.postData.sourceContent) {
|
|
171
|
+
data.content = data.sourceContent;
|
|
172
|
+
delete data.sourceContent;
|
|
173
|
+
} else {
|
|
174
|
+
// content contained is likely already html, bypass parsing
|
|
175
|
+
env.parse = false;
|
|
176
|
+
}
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
return env;
|
|
@@ -205,10 +208,8 @@ const Markdown = {
|
|
|
205
208
|
},
|
|
206
209
|
|
|
207
210
|
renderHelp: async function (helpContent) {
|
|
208
|
-
const translated = await translator.translate('[[markdown:help-text]]');
|
|
209
|
-
const parsed = await plugins.hooks.fire('filter:parse.raw', `## Markdown\n${translated}`);
|
|
210
211
|
const html = await app.renderAsync('modals/markdown-help', {});
|
|
211
|
-
helpContent +=
|
|
212
|
+
helpContent += html;
|
|
212
213
|
return helpContent;
|
|
213
214
|
},
|
|
214
215
|
|
|
@@ -294,6 +295,10 @@ const Markdown = {
|
|
|
294
295
|
parser.renderer.rules.image = function (tokens, idx, options, env, self) {
|
|
295
296
|
const token = tokens[idx];
|
|
296
297
|
const attributes = new Map(token.attrs);
|
|
298
|
+
if (env.type === 'plaintext') {
|
|
299
|
+
const filename = path.basename(attributes.get('src'));
|
|
300
|
+
return `[image: ${filename}]`;
|
|
301
|
+
}
|
|
297
302
|
|
|
298
303
|
// Validate the url
|
|
299
304
|
if (!Markdown.isUrlValid(attributes.get('src'))) { return ''; }
|
|
@@ -304,6 +309,10 @@ const Markdown = {
|
|
|
304
309
|
};
|
|
305
310
|
|
|
306
311
|
parser.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
|
312
|
+
if (env.type === 'plaintext') {
|
|
313
|
+
return '';
|
|
314
|
+
}
|
|
315
|
+
|
|
307
316
|
const attributes = new Map(tokens[idx].attrs);
|
|
308
317
|
|
|
309
318
|
if (attributes.has('href') && Markdown.isExternalLink(attributes.get('href'))) {
|
|
@@ -337,6 +346,15 @@ const Markdown = {
|
|
|
337
346
|
return renderLink(tokens, idx, options, env, self);
|
|
338
347
|
};
|
|
339
348
|
|
|
349
|
+
parser.renderer.rules.link_close = function (...args) {
|
|
350
|
+
const [,,, env, self] = args;
|
|
351
|
+
if (env === 'plaintext') {
|
|
352
|
+
return '';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return self.renderToken(...args);
|
|
356
|
+
};
|
|
357
|
+
|
|
340
358
|
parser.renderer.rules.table_open = function (tokens, idx, options, env, self) {
|
|
341
359
|
const classIdx = tokens[idx].attrIndex('class');
|
|
342
360
|
|