Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ void writeLiteral(Literal token) {
}

void writeMarkdownFencedCodeBlock(MarkdownFencedCodeBlock token) {
if (wroteAnythingSignificant && !atStartOfLine) {
// A reminder that atStartOfLine is still true after `-␣` because it is a StartOfLineToken.
requestBlankLine();
}
flushWhitespace();
output.append(token.start());
token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.googlejavaformat.java.javadoc.Token.MarkdownFencedCodeBlock;
import com.google.googlejavaformat.java.javadoc.Token.ParagraphCloseTag;
import com.google.googlejavaformat.java.javadoc.Token.ParagraphOpenTag;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.commonmark.node.BulletList;
Expand Down Expand Up @@ -128,12 +129,16 @@ private void visitFencedCodeBlock(FencedCodeBlock fencedCodeBlock) {
// indentation gets subtracted from FencedCodeBlock.getLiteral(), which is the actual text
// represented by the code block.
int start = startPosition(fencedCodeBlock) + fencedCodeBlock.getFenceIndent();
int closingLength =
Objects.requireNonNullElse(
fencedCodeBlock.getClosingFenceLength(), fencedCodeBlock.getOpeningFenceLength());
// We have observed getClosingFenceLength() returning null in some cases.
MarkdownFencedCodeBlock token =
new MarkdownFencedCodeBlock(
input.substring(start, endPosition(fencedCodeBlock)),
fencedCodeBlock.getFenceCharacter().repeat(fencedCodeBlock.getOpeningFenceLength())
+ fencedCodeBlock.getInfo(),
fencedCodeBlock.getFenceCharacter().repeat(fencedCodeBlock.getClosingFenceLength()),
fencedCodeBlock.getFenceCharacter().repeat(closingLength),
fencedCodeBlock.getLiteral());
positionToToken.get(start).addLast(token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ default int length() {

/**
* Tokens that are always pinned to the following token. For example, {@code <p>} in {@code <p>Foo
* bar} (never {@code <p> Foo bar} or {@code <p>\nFoo bar}).
* bar} (never {@code <p> Foo bar} or {@code <p>\nFoo bar}); or {#code
* <li>} or {@code -␣} in {@code <li>Foo bar} or {@code -␣Foo bar}.
*
* <p>This is not the only kind of "pinning" that we do: See also the joining of Literal tokens
* done by the lexer. The special pinning here is necessary because these tokens are not of type
* Literal (because they require other special handling).
* <p>This is not the only kind of "pinning" that we do: See also the joining of Literal
* tokens done by the lexer. The special pinning here is necessary because these tokens are
* not of type Literal (because they require other special handling).
*/
interface StartOfLineToken {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1739,9 +1739,14 @@ public void markdownFencedCodeBlocks() {
/// ```
///
/// - flibbertigibbet
/// ```
/// code block in a list after text with no blank line intervening (one will be inserted)
/// ```
///
/// - flibbertigibbet
///
/// ```
/// code block in a list after text
/// code block in a list after text with a blank line intervening
/// ```
///
/// ~~~java
Expand All @@ -1767,8 +1772,16 @@ class Test {}
/// in a list
/// ```
///
/// - flibbertigibbet```
/// code block in a list after text
/// - flibbertigibbet
///
/// ```
/// code block in a list after text with no blank line intervening (one will be inserted)
/// ```
///
/// - flibbertigibbet
///
/// ```
/// code block in a list after text with a blank line intervening
/// ```
///
/// ~~~java
Expand Down
Loading