mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 02:06:29 -05:00
Use twitter emojis for markdown-it-emoji
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
parent
1cf5a3d375
commit
cf64110134
3 changed files with 21 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
import equal from 'deep-equal'
|
||||
import { DomElement } from 'domhandler'
|
||||
import { Data } from 'emoji-mart/dist-es/utils/data'
|
||||
import yaml from 'js-yaml'
|
||||
import MarkdownIt from 'markdown-it'
|
||||
import abbreviation from 'markdown-it-abbr'
|
||||
|
@ -62,6 +63,7 @@ import { QuoteOptionsReplacer } from './replace-components/quote-options/quote-o
|
|||
import { TocReplacer } from './replace-components/toc/toc-replacer'
|
||||
import { VimeoReplacer } from './replace-components/vimeo/vimeo-replacer'
|
||||
import { YoutubeReplacer } from './replace-components/youtube/youtube-replacer'
|
||||
import emojiData from 'emoji-mart/data/twitter.json'
|
||||
|
||||
export interface MarkdownRendererProps {
|
||||
content: string
|
||||
|
@ -72,6 +74,15 @@ export interface MarkdownRendererProps {
|
|||
onFirstHeadingChange?: (firstHeading: string | undefined) => void
|
||||
}
|
||||
|
||||
const markdownItTwitterEmojis = Object.keys((emojiData as unknown as Data).emojis)
|
||||
.reduce((reduceObject, emojiIdentifier) => {
|
||||
const emoji = (emojiData as unknown as Data).emojis[emojiIdentifier]
|
||||
if (emoji.b) {
|
||||
reduceObject[emojiIdentifier] = `&#x${emoji.b};`
|
||||
}
|
||||
return reduceObject
|
||||
}, {} as { [key: string]: string })
|
||||
|
||||
export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content, onMetaDataChange, onFirstHeadingChange, onTocChange, className, wide }) => {
|
||||
const [tocAst, setTocAst] = useState<TocAst>()
|
||||
const [lastTocAst, setLastTocAst] = useState<TocAst>()
|
||||
|
@ -142,7 +153,9 @@ export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content, onM
|
|||
} else {
|
||||
md.use(plantumlError)
|
||||
}
|
||||
md.use(emoji)
|
||||
md.use(emoji, {
|
||||
defs: markdownItTwitterEmojis
|
||||
})
|
||||
md.use(abbreviation)
|
||||
md.use(definitionList)
|
||||
md.use(subscript)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
declare module 'markdown-it-emoji' {
|
||||
import MarkdownIt from 'markdown-it/lib'
|
||||
const markdownItEmoji: MarkdownIt.PluginSimple
|
||||
import { EmojiOptions } from './interface'
|
||||
const markdownItEmoji: MarkdownIt.PluginWithOptions<EmojiOptions>
|
||||
export = markdownItEmoji
|
||||
}
|
||||
|
|
5
src/external-types/markdown-it-emoji/interface.d.ts
vendored
Normal file
5
src/external-types/markdown-it-emoji/interface.d.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
export interface EmojiOptions {
|
||||
defs?: { [key: string]: string },
|
||||
enabled: string[],
|
||||
shortcuts?: { [key: string]: string }
|
||||
}
|
Loading…
Reference in a new issue