3 var trim = require('trim');
4 var decimal = require('is-decimal');
5 var trimTrailingLines = require('trim-trailing-lines');
6 var interrupt = require('../util/interrupt');
8 module.exports = paragraph;
16 /* Tokenise paragraph. */
17 function paragraph(eat, value, silent) {
19 var settings = self.options;
20 var commonmark = settings.commonmark;
21 var gfm = settings.gfm;
22 var tokenizers = self.blockTokenizers;
23 var interruptors = self.interruptParagraph;
24 var index = value.indexOf(C_NEWLINE);
25 var length = value.length;
32 while (index < length) {
33 /* Eat everything if there’s no following newline. */
39 /* Stop if the next character is NEWLINE. */
40 if (value.charAt(index + 1) === C_NEWLINE) {
44 /* In commonmark-mode, following indented lines
45 * are part of the paragraph. */
50 while (position < length) {
51 character = value.charAt(position);
53 if (character === C_TAB) {
56 } else if (character === C_SPACE) {
65 if (size >= TAB_SIZE) {
66 index = value.indexOf(C_NEWLINE, index + 1);
71 subvalue = value.slice(index + 1);
73 /* Check if the following code contains a possible
75 if (interrupt(interruptors, tokenizers, self, [eat, subvalue, true])) {
79 /* Break if the following line starts a list, when
80 * already in a list, or when in commonmark, or when
81 * in gfm mode and the bullet is *not* numeric. */
83 tokenizers.list.call(self, eat, subvalue, true) &&
87 (gfm && !decimal(trim.left(subvalue).charAt(0)))
94 index = value.indexOf(C_NEWLINE, index + 1);
96 if (index !== -1 && trim(value.slice(position, index)) === '') {
102 subvalue = value.slice(0, index);
104 if (trim(subvalue) === '') {
110 /* istanbul ignore if - never used (yet) */
116 subvalue = trimTrailingLines(subvalue);
118 return eat(subvalue)({
120 children: self.tokenizeInline(subvalue, now)