-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add markdown support for bold and italic
- Loading branch information
Showing
4 changed files
with
206 additions
and
57 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
ui/src/main/java/io/xeres/ui/support/contentline/ContentEmphasis.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,60 @@ | ||
/* | ||
* Copyright (c) 2023 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.ui.support.contentline; | ||
|
||
import javafx.scene.Node; | ||
import javafx.scene.text.Text; | ||
|
||
import java.util.Set; | ||
|
||
public class ContentEmphasis implements Content | ||
{ | ||
public enum Style | ||
{ | ||
BOLD, | ||
ITALIC | ||
} | ||
|
||
private final Text node; | ||
|
||
public ContentEmphasis(String text, Set<Style> style) | ||
{ | ||
node = new Text(text); | ||
var css = ""; | ||
if (style.contains(Style.BOLD)) | ||
{ | ||
css += "-fx-font-weight: bold;"; | ||
} | ||
if (style.contains(Style.ITALIC)) | ||
{ | ||
css += "-fx-font-style: italic;"; | ||
} | ||
if (!css.isEmpty()) | ||
{ | ||
node.setStyle(css); | ||
} | ||
} | ||
|
||
@Override | ||
public Node getNode() | ||
{ | ||
return node; | ||
} | ||
} |
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
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,73 @@ | ||
/* | ||
* Copyright (c) 2023 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.ui.support.util; | ||
|
||
import java.util.regex.Matcher; | ||
|
||
/** | ||
* Helper class to handle ranges of text. Provide a matcher then you can find the start and end of the range but | ||
* also the surrounding parts. | ||
*/ | ||
public class Range | ||
{ | ||
private final int start; | ||
private final int end; | ||
|
||
public Range(Matcher matcher) | ||
{ | ||
start = matcher.start(1); | ||
end = matcher.end(); | ||
} | ||
|
||
public Range(int start, int end) | ||
{ | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
public boolean hasRange() | ||
{ | ||
return end > start; | ||
} | ||
|
||
public Range outerRange(Range other) | ||
{ | ||
if (other.start > start) | ||
{ | ||
// other is after us | ||
return new Range(end, other.start); | ||
} | ||
else | ||
{ | ||
// other is before us | ||
return new Range(other.end, start); | ||
} | ||
} | ||
|
||
public int start() | ||
{ | ||
return start; | ||
} | ||
|
||
public int end() | ||
{ | ||
return end; | ||
} | ||
} |