index.js 961 B

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