Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

忽略frontmatter #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = com.lilittlecat.plugin.intellij-pangu
pluginName = Pangu
# SemVer format -> https://semver.org
pluginVersion = 1.2.3
pluginVersion = 1.2.4

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/com/lilittlecat/plugin/pangu/Pangu.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,30 @@ public void spacingFile(File inputFile, File outputFile) throws IOException {
BufferedWriter bw = new BufferedWriter(fw);

try {
String line = br.readLine(); // readLine() do not contain newline char
String line = br.readLine(); // readLine() does not contain newline char
boolean inFrontmatter = false;
boolean frontmatterStarted = false;

while (line != null) {
line = spacingText(line);

// TODO: keep file's raw newline char from difference OS platform
if (line.trim().equals("---") && !frontmatterStarted) {
inFrontmatter = true;
frontmatterStarted = true;
line = br.readLine();
continue;
}

if (line.trim().equals("---") && frontmatterStarted) {
inFrontmatter = false;
frontmatterStarted = false;
line = br.readLine();
continue;
}

if (!inFrontmatter) {
line = spacingText(line);
}

// TODO: keep file's raw newline char from different OS platforms
bw.write(line);
bw.newLine();

Expand Down