blob: 101483d9b4e166f6d63814c87805b85e0d7f0901 (
plain) (
blame)
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
55
56
57
58
59
60
61
62
63
64
65
|
/*******************************************************************************
* Copyright (c) 2012, 2013 Stefan Seelmann and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Stefan Seelmann - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.markdown.core.block;
import org.eclipse.mylyn.wikitext.core.parser.Attributes;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
/**
* Markdown default paragraph.
*
* @author Stefan Seelmann
*/
public class ParagraphBlock extends NestableBlock {
private int blockLineCount = 0;
@Override
public boolean canStart(String line, int lineOffset) {
blockLineCount = 0;
return true;
}
@Override
protected int processLineContent(String line, int offset) {
// start of block
if (blockLineCount == 0) {
builder.beginBlock(BlockType.PARAGRAPH, new Attributes());
}
// empty line: start new block
if (markupLanguage.isEmptyLine(line.substring(offset))) {
setClosed(true);
return offset;
}
// next line, does not convert to line break
if (blockLineCount > 0) {
builder.characters("\n"); //$NON-NLS-1$
}
getMarkupLanguage().emitMarkupLine(getParser(), state, line, offset);
blockLineCount++;
return -1;
}
@Override
public void setClosed(boolean closed) {
if (closed && !isClosed()) {
builder.endBlock();
builder.characters("\n"); //$NON-NLS-1$
}
super.setClosed(closed);
}
}
|