configuration:

  • target_file: quartz/plugins/transformers/emoji.ts

plugin:

  • type: QuartzTransformerPlugin
  • phase: htmlPlugins
  • specification: rehype

behavior:

  • mechanism: map standard emojis to matching icons using unist-util-visit for AST traversal
  • identification: use emoji-regex to accurately capture full grapheme clusters and ZWJ sequences
  • optimization: use base64 image data or inline SVG to eliminate external network requests

hooks:

  • ast_traversal:
    • utility: unist-util-visit
    • target: walk text nodes in the hast tree
    • filters:
      • check_parents: ensure no ancestor element has a tagName of code or pre
      • ignore_context: skip if parent is an attribute node or non-renderable element
  • transformation:
    • step_1: match valid emojis via regex within the text node value
    • step_2: pass the matched literal emoji character to the getIconCode(char) utility in quartz/util/emoji.ts
    • step_3: retrieve the graphic data using loadEmoji(code) or an equivalent map
    • step_4: construct a new hast element node mapping to <img className="emoji">
    • step_5: split the original text node and insert the fragments and new icon node into the parent children array

replacement_schema:

  • type: element
  • tagName: img
  • properties:
    • className:
      • emoji
    • src: base64 data string
    • alt: literal emoji character