index.js 832 B

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