-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some whitespaces not being stripped properly
- Loading branch information
1 parent
b5327e1
commit 34beef4
Showing
4 changed files
with
79 additions
and
3 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Mod Configuration | ||
mod_name=MineMark | ||
mod_id=minemark | ||
mod_version=1.2.1 | ||
mod_version=1.2.2 | ||
mod_description=Markdown rendering library | ||
mod_license=LGPL |
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
62 changes: 62 additions & 0 deletions
62
src/main/java/dev/dediamondpro/minemark/utils/PrefixedReader.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,62 @@ | ||
/* | ||
* This file is part of MineMark | ||
* Copyright (C) 2024 DeDiamondPro | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License Version 3 as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.dediamondpro.minemark.utils; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
|
||
|
||
/** | ||
* Utility class to add a prefix to a reader, used by MineMarkCore to trick the Markdown parser to activate early | ||
*/ | ||
public class PrefixedReader extends Reader { | ||
private final StringReader prefixReader; | ||
private final Reader mainReader; | ||
private boolean prefixDone; | ||
|
||
public PrefixedReader(String prefix, Reader mainReader) { | ||
this.prefixReader = new StringReader(prefix); | ||
this.mainReader = mainReader; | ||
this.prefixDone = false; | ||
} | ||
|
||
@Override | ||
public int read(char @NotNull [] cbuf, int off, int len) throws IOException { | ||
// Read from the prefixReader first | ||
if (!prefixDone) { | ||
int numRead = prefixReader.read(cbuf, off, len); | ||
if (numRead == -1) { | ||
prefixDone = true; // Prefix is done, switch to mainReader | ||
} else { | ||
return numRead; | ||
} | ||
} | ||
|
||
// Now read from the mainReader | ||
return mainReader.read(cbuf, off, len); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
prefixReader.close(); | ||
mainReader.close(); | ||
} | ||
} |