]> Untitled Git - lemmy.git/commitdiff
Adding support for spoilers.
authorDessalines <tyhou13@gmx.com>
Mon, 29 Apr 2019 17:16:43 +0000 (10:16 -0700)
committerDessalines <tyhou13@gmx.com>
Mon, 29 Apr 2019 17:16:43 +0000 (10:16 -0700)
- Fixes #104

example :
```
::: spoiler hidden stuff
*a bunch of spoilers here*
:::
```

ui/package.json
ui/src/utils.ts
ui/yarn.lock

index b5bb14ef95caf2070f53f9d220870600966f92ad..d806575c31de89ee41a688b255d9911dfc017188 100644 (file)
@@ -19,6 +19,7 @@
     "@types/js-cookie": "^2.2.1",
     "@types/jwt-decode": "^2.2.1",
     "@types/markdown-it": "^0.0.7",
+    "@types/markdown-it-container": "^2.0.2",
     "autosize": "^4.0.2",
     "classcat": "^1.1.3",
     "dotenv": "^6.1.0",
@@ -27,6 +28,7 @@
     "js-cookie": "^2.2.0",
     "jwt-decode": "^2.2.0",
     "markdown-it": "^8.4.2",
+    "markdown-it-container": "^2.0.0",
     "moment": "^2.24.0",
     "rxjs": "^6.4.0"
   },
index 4199f09ceecc804da6a86542a161aaea1d204316..3baf2367d319df840ecfdd87515f833893e05eea 100644 (file)
@@ -1,5 +1,6 @@
 import { UserOperation, Comment, User, SortType, ListingType } from './interfaces';
 import * as markdown_it from 'markdown-it';
+import * as markdown_it_container from 'markdown-it-container';
 
 export let repoUrl = 'https://github.com/dessalines/lemmy';
 
@@ -12,6 +13,23 @@ var md = new markdown_it({
   html: true,
   linkify: true,
   typographer: true
+}).use(markdown_it_container, 'spoiler', {
+  validate: function(params: any) {
+    return params.trim().match(/^spoiler\s+(.*)$/);
+  },
+
+  render: function (tokens: any, idx: any) {
+    var m = tokens[idx].info.trim().match(/^spoiler\s+(.*)$/);
+
+    if (tokens[idx].nesting === 1) {
+      // opening tag
+      return '<details><summary>' + md.utils.escapeHtml(m[1]) + '</summary>\n';
+
+    } else {
+      // closing tag
+      return '</details>\n';
+    }
+  }
 });
 
 export function hotRank(comment: Comment): number {
index 5756a444b0ab14ae8a714c334de413cb2a625311..2b29b787a50807fdeb896af9a59c24377a6934eb 100644 (file)
   resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-2.1.0.tgz#ea3dd64c4805597311790b61e872cbd1ed2cd806"
   integrity sha512-Q7DYAOi9O/+cLLhdaSvKdaumWyHbm7HAk/bFwwyTuU0arR5yyCeW5GOoqt4tJTpDRxhpx9Q8kQL6vMpuw9hDSw==
 
-"@types/markdown-it@^0.0.7":
+"@types/markdown-it-container@^2.0.2":
+  version "2.0.2"
+  resolved "https://registry.yarnpkg.com/@types/markdown-it-container/-/markdown-it-container-2.0.2.tgz#0e624653415a1c2f088a5ae51f7bfff480c03f49"
+  integrity sha512-T770GL+zJz8Ssh1NpLiOruYhrU96yb8ovPSegLrWY5XIkJc6PVVC7kH/oQaVD0rkePpWMFJK018OgS/pwviOMw==
+  dependencies:
+    "@types/markdown-it" "*"
+
+"@types/markdown-it@*", "@types/markdown-it@^0.0.7":
   version "0.0.7"
   resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-0.0.7.tgz#75070485a3d8ad11e7deb8287f4430be15bf4d39"
   integrity sha512-WyL6pa76ollQFQNEaLVa41ZUUvDvPY+qAUmlsphnrpL6I9p1m868b26FyeoOmo7X3/Ta/S9WKXcEYXUSHnxoVQ==
@@ -1674,6 +1681,11 @@ map-visit@^1.0.0:
   dependencies:
     object-visit "^1.0.0"
 
+markdown-it-container@^2.0.0:
+  version "2.0.0"
+  resolved "https://registry.yarnpkg.com/markdown-it-container/-/markdown-it-container-2.0.0.tgz#0019b43fd02eefece2f1960a2895fba81a404695"
+  integrity sha1-ABm0P9Au7+zi8ZYKKJX7qBpARpU=
+
 markdown-it@^8.4.2:
   version "8.4.2"
   resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54"