From: Dessalines Date: Mon, 29 Apr 2019 17:16:43 +0000 (-0700) Subject: Adding support for spoilers. X-Git-Url: http://these/git/%24%7Bsite?a=commitdiff_plain;h=d13a95da27c847e3f53b0bcf38d77d79f67891ad;p=lemmy.git Adding support for spoilers. - Fixes #104 example : ``` ::: spoiler hidden stuff *a bunch of spoilers here* ::: ``` --- diff --git a/ui/package.json b/ui/package.json index b5bb14ef..d806575c 100644 --- a/ui/package.json +++ b/ui/package.json @@ -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" }, diff --git a/ui/src/utils.ts b/ui/src/utils.ts index 4199f09c..3baf2367 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -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 '
' + md.utils.escapeHtml(m[1]) + '\n'; + + } else { + // closing tag + return '
\n'; + } + } }); export function hotRank(comment: Comment): number { diff --git a/ui/yarn.lock b/ui/yarn.lock index 5756a444..2b29b787 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -38,7 +38,14 @@ 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"