block-quote.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var blockQuote = {
  2. name: 'blockQuote',
  3. tokenize: tokenizeBlockQuoteStart,
  4. continuation: {tokenize: tokenizeBlockQuoteContinuation},
  5. exit: exit
  6. }
  7. export default blockQuote
  8. import codes from '../character/codes.mjs'
  9. import markdownSpace from '../character/markdown-space.mjs'
  10. import constants from '../constant/constants.mjs'
  11. import types from '../constant/types.mjs'
  12. import spaceFactory from './factory-space.mjs'
  13. function tokenizeBlockQuoteStart(effects, ok, nok) {
  14. var self = this
  15. return start
  16. function start(code) {
  17. if (code === codes.greaterThan) {
  18. if (!self.containerState.open) {
  19. effects.enter(types.blockQuote, {_container: true})
  20. self.containerState.open = true
  21. }
  22. effects.enter(types.blockQuotePrefix)
  23. effects.enter(types.blockQuoteMarker)
  24. effects.consume(code)
  25. effects.exit(types.blockQuoteMarker)
  26. return after
  27. }
  28. return nok(code)
  29. }
  30. function after(code) {
  31. if (markdownSpace(code)) {
  32. effects.enter(types.blockQuotePrefixWhitespace)
  33. effects.consume(code)
  34. effects.exit(types.blockQuotePrefixWhitespace)
  35. effects.exit(types.blockQuotePrefix)
  36. return ok
  37. }
  38. effects.exit(types.blockQuotePrefix)
  39. return ok(code)
  40. }
  41. }
  42. function tokenizeBlockQuoteContinuation(effects, ok, nok) {
  43. return spaceFactory(
  44. effects,
  45. effects.attempt(blockQuote, ok, nok),
  46. types.linePrefix,
  47. this.parser.constructs.disable.null.indexOf('codeIndented') > -1
  48. ? undefined
  49. : constants.tabSize
  50. )
  51. }
  52. function exit(effects) {
  53. effects.exit(types.blockQuote)
  54. }