import { MarkdownPostProcessor } from "obsidian" ; import { emoji } from "./emojiList" ; export default class EmojiMarkdownPostProcessor { static emojiProcessor : MarkdownPostProcessor = ( el ) => { el . innerText . match ( /[:][^\s:][^ \n:]*[:]/g ) ?. forEach ( ( e ) => EmojiMarkdownPostProcessor . emojiReplace ( e , el ) ) ; } ; static emojiReplace ( shortcode , el ) { if ( ( typeof el . tagName === "string" ) && ( el . tagName . indexOf ( "CODE" ) !== - 1 || el . tagName . indexOf ( "MJX" ) !== - 1 ) ) { return false ; } if ( el . hasChildNodes ( ) ) { el . childNodes . forEach ( ( child ) => this . emojiReplace ( shortcode , child as HTMLElement ) ) ; } else { el . textContent = el . textContent . replace ( shortcode , emoji [ shortcode ] ?? shortcode ) ; } } }