index.js 803 B

123456789101112131415161718192021222324252627
  1. /**
  2. * @import {Code} from 'micromark-util-types'
  3. */
  4. import { markdownLineEndingOrSpace, unicodePunctuation, unicodeWhitespace } from 'micromark-util-character';
  5. /**
  6. * Classify whether a code represents whitespace, punctuation, or something
  7. * else.
  8. *
  9. * Used for attention (emphasis, strong), whose sequences can open or close
  10. * based on the class of surrounding characters.
  11. *
  12. * > 👉 **Note**: eof (`null`) is seen as whitespace.
  13. *
  14. * @param {Code} code
  15. * Code.
  16. * @returns {typeof constants.characterGroupWhitespace | typeof constants.characterGroupPunctuation | undefined}
  17. * Group.
  18. */
  19. export function classifyCharacter(code) {
  20. if (code === null || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) {
  21. return 1;
  22. }
  23. if (unicodePunctuation(code)) {
  24. return 2;
  25. }
  26. }