Skip to content

Commit

Permalink
Shorten RestructuredtextAnnotatedTextBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
valentjn committed Apr 18, 2021
1 parent 2278d9f commit 49c31a8
Showing 1 changed file with 15 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,30 +188,36 @@ public CodeAnnotatedTextBuilder addCode(String code) {

if (isStartOfLine) {
@Nullable Matcher matcher;
boolean blockFound = true;

if (matchExplicitBlock()) {
continue;
if ((matcher = matchFromPosition(footnotePattern)) != null) {
this.blockType = BlockType.FOOTNOTE;
addMarkup(matcher.group());
} else if ((matcher = matchFromPosition(directivePattern)) != null) {
this.blockType = BlockType.DIRECTIVE;
addMarkup(matcher.group());
} else if ((matcher = matchFromPosition(commentPattern)) != null) {
this.blockType = BlockType.COMMENT;
addMarkup(matcher.group());
} else if ((matcher = matchFromPosition(gridTableStartPattern)) != null) {
this.blockType = BlockType.GRID_TABLE;
addMarkup(matcher.group());
continue;
} else if ((matcher = matchFromPosition(simpleTableStartPattern)) != null) {
this.blockType = BlockType.SIMPLE_TABLE;
addMarkup(matcher.group());
continue;
} else if ((matcher = matchFromPosition(sectionTitleAdronmentPattern)) != null) {
addMarkup(matcher.group());
continue;
} else if ((matcher = matchFromPosition(lineBlockPattern)) != null) {
addMarkup(matcher.group());
continue;
} else if ((matcher = matchFromPosition(bulletListPattern)) != null) {
addMarkup(matcher.group());
continue;
} else if ((matcher = matchFromPosition(enumeratedListPattern)) != null) {
addMarkup(matcher.group());
continue;
} else {
blockFound = false;
}

if (blockFound) continue;
}

if ((this.blockType == BlockType.COMMENT) || (this.blockType == BlockType.GRID_TABLE)
Expand All @@ -224,60 +230,44 @@ public CodeAnnotatedTextBuilder addCode(String code) {

if ((matcher = matchInlineStartFromPosition(strongEmphasisPattern)) != null) {
addMarkup(matcher.group());
continue;
} else if ((matcher = matchInlineEndFromPosition(strongEmphasisPattern)) != null) {
addMarkup(matcher.group());
continue;
} else if ((matcher = matchInlineStartFromPosition(emphasisPattern)) != null) {
addMarkup(matcher.group());
continue;
} else if ((matcher = matchInlineEndFromPosition(emphasisPattern)) != null) {
addMarkup(matcher.group());
continue;
} else if ((matcher = matchInlineStartFromPosition(inlineLiteralPattern)) != null) {
addMarkup(matcher.group(), generateDummy());
this.inIgnoredMarkup = true;
continue;
} else if ((matcher = matchInlineEndFromPosition(inlineLiteralPattern)) != null) {
addMarkup(matcher.group());
this.inIgnoredMarkup = false;
continue;
} else if ((matcher = matchInlineStartFromPosition(interpretedTextStartPattern)) != null) {
addMarkup(matcher.group(), generateDummy());
this.inIgnoredMarkup = true;
continue;
} else if ((matcher = matchInlineEndFromPosition(interpretedTextEndPattern)) != null) {
addMarkup(matcher.group());
this.inIgnoredMarkup = false;
continue;
} else if (
(matcher = matchInlineStartFromPosition(inlineInternalTargetStartPattern)) != null) {
addMarkup(matcher.group(), generateDummy());
this.inIgnoredMarkup = true;
continue;
} else if ((matcher = matchInlineEndFromPosition(inlineInternalTargetEndPattern)) != null) {
addMarkup(matcher.group());
this.inIgnoredMarkup = false;
continue;
} else if ((matcher = matchInlineStartFromPosition(footnoteReferenceStartPattern)) != null) {
addMarkup(matcher.group(), generateDummy());
this.inIgnoredMarkup = true;
continue;
} else if ((matcher = matchInlineEndFromPosition(footnoteReferenceEndPattern)) != null) {
addMarkup(matcher.group());
this.inIgnoredMarkup = false;
continue;
} else if ((matcher = matchInlineStartFromPosition(hyperlinkReferenceStartPattern)) != null) {
addMarkup(matcher.group(), generateDummy());
this.inIgnoredMarkup = true;
continue;
} else if ((matcher = matchInlineEndFromPosition(hyperlinkReferenceEndPattern)) != null) {
addMarkup(matcher.group());
this.inIgnoredMarkup = false;
continue;
}

if (this.inIgnoredMarkup) {
} else if (this.inIgnoredMarkup) {
addMarkup(this.curString);
} else {
addText(this.curString);
Expand Down Expand Up @@ -357,26 +347,6 @@ public CodeAnnotatedTextBuilder addCode(String code) {
this.pos + matcher.group().length()) != null) ? matcher : null);
}

private boolean matchExplicitBlock() {
@Nullable Matcher matcher;

if ((matcher = matchFromPosition(footnotePattern)) != null) {
this.blockType = BlockType.FOOTNOTE;
addMarkup(matcher.group());
return true;
} else if ((matcher = matchFromPosition(directivePattern)) != null) {
this.blockType = BlockType.DIRECTIVE;
addMarkup(matcher.group());
return true;
} else if ((matcher = matchFromPosition(commentPattern)) != null) {
this.blockType = BlockType.COMMENT;
addMarkup(matcher.group());
return true;
}

return false;
}

private boolean isExplicitBlockType() {
return ((this.blockType == BlockType.FOOTNOTE)
|| (this.blockType == BlockType.DIRECTIVE)
Expand Down

0 comments on commit 49c31a8

Please sign in to comment.