From: Coma Grayce Date: Mon, 20 Jul 2020 22:06:22 +0000 (+0300) Subject: Add sub and sup Markdown tags. X-Git-Url: http://these/git/%7B%24%7B%60data:application/%22%7Burl%7D/%7Bthis.captchaPngSrc%28%29%7D?a=commitdiff_plain;h=6fbfb69ee4115577f440aee418eb87b3de4c343d;p=lemmy.git Add sub and sup Markdown tags. --- diff --git a/docs/src/about_guide.md b/docs/src/about_guide.md index 6f709b58..5422478e 100644 --- a/docs/src/about_guide.md +++ b/docs/src/about_guide.md @@ -35,6 +35,8 @@ Horizontal Rule
\--- | Horizontal Rule
\*\*\* | Horizontal Rule

\`Inline code\` with backticks | |`Inline code` with backticks \`\`\`
\# code block
print '3 backticks or'
print 'indent 4 spaces'
\`\`\` | ····\# code block
····print '3 backticks or'
····print 'indent 4 spaces' | \# code block
print '3 backticks or'
print 'indent 4 spaces' ::: spoiler hidden or nsfw stuff
*a bunch of spoilers here*
::: | |
hidden or nsfw stuff

a bunch of spoilers here

+Some ~subscript~ text | | Some subscript text +Some ^superscript^ text | | ome superscript text [CommonMark Tutorial](https://commonmark.org/help/tutorial/) diff --git a/ui/package.json b/ui/package.json index 1bd07e86..f59b8625 100644 --- a/ui/package.json +++ b/ui/package.json @@ -37,6 +37,8 @@ "markdown-it": "^10.0.0", "markdown-it-container": "^2.0.0", "markdown-it-emoji": "^1.4.0", + "markdown-it-sub": "^1.0.0", + "markdown-it-sup": "^1.0.0", "moment": "^2.24.0", "node-fetch": "^2.6.0", "prettier": "^2.0.4", diff --git a/ui/src/components/markdown-textarea.tsx b/ui/src/components/markdown-textarea.tsx index 2f6d0a7e..04838b2c 100644 --- a/ui/src/components/markdown-textarea.tsx +++ b/ui/src/components/markdown-textarea.tsx @@ -469,6 +469,16 @@ export class MarkdownTextArea extends Component< i.simpleInsert('#'); } + handleInsertSubscript(i: MarkdownTextArea, event: any) { + event.preventDefault(); + i.simpleInsert('~'); + } + + handleInsertSuperscript(i: MarkdownTextArea, event: any) { + event.preventDefault(); + i.simpleInsert('^'); + } + simpleInsert(chars: string) { if (!this.state.content) { this.state.content = `${chars} `; diff --git a/ui/src/utils.ts b/ui/src/utils.ts index 96047765..892516bf 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -49,6 +49,8 @@ import { UserService, WebSocketService } from './services'; import Tribute from 'tributejs/src/Tribute.js'; import markdown_it from 'markdown-it'; +import markdown_it_sub from 'markdown-it-sub'; +import markdown_it_sup from 'markdown-it-sup'; import markdownitEmoji from 'markdown-it-emoji/light'; import markdown_it_container from 'markdown-it-container'; import emojiShortName from 'emoji-short-name'; @@ -148,6 +150,8 @@ export const md = new markdown_it({ linkify: true, typographer: true, }) + .use(markdown_it_sub) + .use(markdown_it_sup) .use(markdown_it_container, 'spoiler', { validate: function (params: any) { return params.trim().match(/^spoiler\s+(.*)$/); diff --git a/ui/yarn.lock b/ui/yarn.lock index c39f1dc4..ad77fffd 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -4317,6 +4317,16 @@ markdown-it-emoji@^1.4.0: resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc" integrity sha1-m+4OmpkKljupbfaYDE/dsF37Tcw= +markdown-it-sub@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/markdown-it-sub/-/markdown-it-sub-1.0.0.tgz#375fd6026eae7ddcb012497f6411195ea1e3afe8" + integrity sha1-N1/WAm6ufdywEkl/ZBEZXqHjr+g= + +markdown-it-sup@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/markdown-it-sup/-/markdown-it-sup-1.0.0.tgz#cb9c9ff91a5255ac08f3fd3d63286e15df0a1fc3" + integrity sha1-y5yf+RpSVawI8/09YyhuFd8KH8M= + markdown-it@^10.0.0: version "10.0.0" resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-10.0.0.tgz#abfc64f141b1722d663402044e43927f1f50a8dc"