-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to escape
@
at the start of a line.
- Loading branch information
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
doclet/src/main/java/ch/raffael/doclets/pegdown/pdrepair/AtSymbolRepair2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ch.raffael.doclets.pegdown.pdrepair; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
|
||
/** | ||
* AtSymbolRepair2 aims to provide a workaround for `@` signs at the beginning of | ||
* a line: Prepend an `at` at the start of a line with a `.`. To actually start | ||
* the line with `.@`, just add another dot. | ||
* | ||
* *Demo:* | ||
* | ||
* ```java | ||
* .@MyAnnotation | ||
* class MyClass { | ||
* } | ||
* ``` | ||
* | ||
* And a single dot followed by an at on the beginning of the line: | ||
* | ||
* ``` | ||
* .@starts with `.@` in the source | ||
* ..@starts with `..@` in the source | ||
* ...@starts with `...@` in the source | ||
* ``` | ||
* | ||
* @author Raffael Herzog | ||
*/ | ||
public class AtSymbolRepair2 extends DefaultMarkdownRepair { | ||
|
||
private final Pattern LITERAL_AT = Pattern.compile("([\r\n]\\s*)\\.(\\.*)@"); | ||
private final String REPLACEMENT = "$1$2{@}"; | ||
|
||
@Override | ||
public String beforeMarkdownParser(String markup) { | ||
StringBuffer buf = new StringBuffer(); | ||
Matcher matcher = LITERAL_AT.matcher(markup); | ||
boolean didMatch = false; | ||
while ( matcher.find() ) { | ||
matcher.appendReplacement(buf, REPLACEMENT); | ||
didMatch = true; | ||
} | ||
matcher.appendTail(buf); | ||
return buf.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters