nodebb-plugin-markdown 13.2.6 → 13.2.8

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 CHANGED
@@ -13,6 +13,14 @@ const plugins = nodebb.require('./src/plugins');
13
13
  const SocketPlugins = nodebb.require('./src/socket.io/plugins');
14
14
  SocketPlugins.markdown = require('./websockets');
15
15
 
16
+ const strongCharRegex = /\p{L}/u;
17
+ const rtlCharRegex = /[\p{Script=Hebrew}\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}]/u;
18
+
19
+ function isRTL(text) {
20
+ const match = text.match(strongCharRegex);
21
+ return !!match && rtlCharRegex.test(match[0]);
22
+ }
23
+
16
24
  let parser;
17
25
  let app;
18
26
  const Markdown = {
@@ -272,9 +280,18 @@ const Markdown = {
272
280
 
273
281
  parser.use((md) => {
274
282
  md.core.ruler.before('linkify', 'autodir', (state) => {
275
- state.tokens.forEach((token) => {
283
+ state.tokens.forEach((token, index) => {
276
284
  if (token.type === 'paragraph_open') {
277
- token.attrJoin('dir', 'auto');
285
+ const inline = state.tokens[index + 1];
286
+ // `dir="auto"` resolves direction from the first strong character of the
287
+ // rendered HTML, which skips content isolated in `<bdi>` (e.g. mentions),
288
+ // so a paragraph containing only an RTL mention falls back to LTR.
289
+ // The source text still has that character, so detect RTL here instead.
290
+ if (inline && inline.type === 'inline' && isRTL(inline.content)) {
291
+ token.attrJoin('dir', 'rtl');
292
+ } else {
293
+ token.attrJoin('dir', 'auto');
294
+ }
278
295
  }
279
296
  });
280
297
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-markdown",
3
- "version": "13.2.6",
3
+ "version": "13.2.8",
4
4
  "description": "A Markdown parser for NodeBB",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -1,5 +1,5 @@
1
1
  <h2>Markdown</h2>
2
- <p>[[markdown:help-text]]</p>
2
+ <p>{{tx("markdown:help-text")}}</p>
3
3
 
4
4
  <table class="table markdown-reference">
5
5
  <thead>