Implement bold/italic/strike-through support.
This commit is contained in:
parent
40f1ec4a54
commit
52fda37915
1 changed files with 43 additions and 11 deletions
|
@ -940,18 +940,50 @@ public final class YoutubeParsingHelper {
|
|||
}
|
||||
|
||||
final StringBuilder textBuilder = new StringBuilder();
|
||||
for (final Object textPart : textObject.getArray("runs")) {
|
||||
final String text = ((JsonObject) textPart).getString("text");
|
||||
if (html && ((JsonObject) textPart).has("navigationEndpoint")) {
|
||||
final String url = getUrlFromNavigationEndpoint(((JsonObject) textPart)
|
||||
.getObject("navigationEndpoint"));
|
||||
if (!isNullOrEmpty(url)) {
|
||||
textBuilder.append("<a href=\"").append(url).append("\">").append(text)
|
||||
.append("</a>");
|
||||
continue;
|
||||
for (final Object o : textObject.getArray("runs")) {
|
||||
final JsonObject run = (JsonObject) o;
|
||||
String text = run.getString("text");
|
||||
|
||||
if (html) {
|
||||
if (run.has("navigationEndpoint")) {
|
||||
final String url = getUrlFromNavigationEndpoint(run
|
||||
.getObject("navigationEndpoint"));
|
||||
if (!isNullOrEmpty(url)) {
|
||||
text = "<a href=\"" + url + "\">" + text + "</a>";
|
||||
}
|
||||
}
|
||||
|
||||
final boolean bold = run.has("bold")
|
||||
&& run.getBoolean("bold");
|
||||
final boolean italic = run.has("italics")
|
||||
&& run.getBoolean("italics");
|
||||
final boolean strikethrough = run.has("strikethrough")
|
||||
&& run.getBoolean("strikethrough");
|
||||
|
||||
if (bold) {
|
||||
textBuilder.append("<b>");
|
||||
}
|
||||
if (italic) {
|
||||
textBuilder.append("<i>");
|
||||
}
|
||||
if (strikethrough) {
|
||||
textBuilder.append("<s>");
|
||||
}
|
||||
|
||||
textBuilder.append(text);
|
||||
|
||||
if (strikethrough) {
|
||||
textBuilder.append("</s>");
|
||||
}
|
||||
if (italic) {
|
||||
textBuilder.append("</i>");
|
||||
}
|
||||
if (bold) {
|
||||
textBuilder.append("</b>");
|
||||
}
|
||||
} else {
|
||||
textBuilder.append(text);
|
||||
}
|
||||
textBuilder.append(text);
|
||||
}
|
||||
|
||||
String text = textBuilder.toString();
|
||||
|
@ -991,7 +1023,7 @@ public final class YoutubeParsingHelper {
|
|||
final StringBuilder textBuilder = new StringBuilder();
|
||||
int textStart = 0;
|
||||
|
||||
for (final Object commandRun: commandRuns) {
|
||||
for (final Object commandRun : commandRuns) {
|
||||
if (!(commandRun instanceof JsonObject)) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue