classify-character.js 880 B

123456789101112131415161718192021222324252627
  1. 'use strict'
  2. var codes = require('../character/codes.js')
  3. var markdownLineEndingOrSpace = require('../character/markdown-line-ending-or-space.js')
  4. var unicodePunctuation = require('../character/unicode-punctuation.js')
  5. var unicodeWhitespace = require('../character/unicode-whitespace.js')
  6. var constants = require('../constant/constants.js')
  7. // Classify whether a character is unicode whitespace, unicode punctuation, or
  8. // anything else.
  9. // Used for attention (emphasis, strong), whose sequences can open or close
  10. // based on the class of surrounding characters.
  11. function classifyCharacter(code) {
  12. if (
  13. code === codes.eof ||
  14. markdownLineEndingOrSpace(code) ||
  15. unicodeWhitespace(code)
  16. ) {
  17. return constants.characterGroupWhitespace
  18. }
  19. if (unicodePunctuation(code)) {
  20. return constants.characterGroupPunctuation
  21. }
  22. }
  23. module.exports = classifyCharacter