-
Notifications
You must be signed in to change notification settings - Fork 0
/
paragraph.js
54 lines (44 loc) · 1.28 KB
/
paragraph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const {BaseBlock} = require('./base');
const {isLineEnd} = require('../util/scanner');
const Inline = require('../core/inline');
const {TextToken} = require('../tokens/text');
class ParagraphBlock extends BaseBlock {
constructor(contentTokens, isLastContent) {
super();
this.contentTokens = contentTokens;
this.isLastContent = isLastContent;
}
append(paragraph) {
this.contentTokens.push(new TextToken(' '));
this.contentTokens = this.contentTokens.concat(paragraph.contentTokens);
this.isLastContent = paragraph.isLastContent;
}
static parse(scanner, match, options) {
scanner.mark();
scanner.skipToLineEnd();
const content = scanner.pop();
const contentTokens = Inline.parse(content, options);
const isLastContent = (
scanner.isAtEnd ||
isLineEnd(scanner.getCharAtOffset(+1))
);
return new ParagraphBlock(contentTokens, isLastContent);
}
static integrate(results, prev, curr) {
if (prev instanceof ParagraphBlock && !prev.isLastContent) {
prev.append(curr);
} else {
results.push(curr);
}
}
render(options, callback) {
Inline.render(this.contentTokens, options, function(error, content) {
if (error) {
callback(error, null);
} else {
callback(null, `<p>${content}</p>`);
}
});
}
}
exports.ParagraphBlock = ParagraphBlock;