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

Use Markdown in AI Summary tab implemented #12266

Open
wants to merge 15 commits 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- By double clicking on a local citation in the Citation Relations Tab you can now jump the linked entry. [#11955](https://github.com/JabRef/jabref/pull/11955)
- We use the menu icon for background tasks as a progress indicator to visualise an import's progress when dragging and dropping several PDF files into the main table. [#12072](https://github.com/JabRef/jabref/pull/12072)
- The PDF content importer now supports importing title from upto the second page of the PDF. [#12139](https://github.com/JabRef/jabref/issues/12139)
- We added support of `Markdown` in `AI Summary` tab by using the `CheckBox` next to `Regenerate` button. [#12266](https://github.com/JabRef/jabref/pull/12266)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As AI features are not currently released, we don't put them in CHANGLELOG.md


### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.TextFlow?>
<fx:root alignment="TOP_CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" spacing="10.0" type="VBox" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.ai.components.summary.SummaryShowingComponent">
<children>
<TextArea fx:id="summaryTextArea" editable="false" wrapText="true" VBox.vgrow="ALWAYS" />
<Button mnemonicParsing="false" onAction="#onRegenerateButtonClick" text="%Regenerate" />
<TextFlow textAlignment="CENTER">
<children>
<Text fx:id="summaryInfoText" strokeType="OUTSIDE" strokeWidth="0.0" text="%Generated at %0 by %1" />
</children>
</TextFlow>
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<?import javafx.scene.text.Text?>

<fx:root alignment="TOP_CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="400.0" minWidth="-Infinity" spacing="8.0" type="VBox" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.ai.components.summary.SummaryShowingComponent">
<children>
<BorderPane minHeight="30.0">
<left>
<CheckBox fx:id="markdownCheckbox" mnemonicParsing="false" onAction="#onMarkdownToggle" text="Markdown" />
</left>
<center>
<Button mnemonicParsing="false" onAction="#onRegenerateButtonClick" text="%Regenerate" translateX="-40" />
</center>
</BorderPane>
<Text fx:id="summaryInfoText" strokeType="OUTSIDE" strokeWidth="0.0" text="%Generated at %0 by %1" />
</children>
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
</padding>
</fx:root>
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@
import java.util.Locale;

import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebView;

import org.jabref.gui.theme.ThemeManager;
import org.jabref.logic.ai.summarization.Summary;
import org.jabref.logic.layout.format.MarkdownFormatter;
import org.jabref.logic.util.WebViewStore;

import com.airhacks.afterburner.views.ViewLoader;
import jakarta.inject.Inject;

public class SummaryShowingComponent extends VBox {
@FXML private TextArea summaryTextArea;
private static final MarkdownFormatter MARKDOWN_FORMATTER = new MarkdownFormatter();
@FXML private Text summaryInfoText;
@FXML private CheckBox markdownCheckbox;

@Inject private ThemeManager themeManager;

private WebView contentWebView;
private final Summary summary;
private final Runnable regenerateCallback;

Expand All @@ -32,20 +42,51 @@ public SummaryShowingComponent(Summary summary, Runnable regenerateCallback) {

@FXML
private void initialize() {
summaryTextArea.setText(summary.content());
initializeWebView();
updateContent(false); // Start in plain text mode
updateInfoText();
}

private void initializeWebView() {
contentWebView = WebViewStore.get();
VBox.setVgrow(contentWebView, Priority.ALWAYS);

themeManager.installCss(contentWebView.getEngine());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this doesn't work..

@calixtus, @koppor is there any way for browser to use JabRef's style? Font family and size specifically? Or should we leave the default font in WebView (I guess it's some Serif)?


getChildren().addFirst(contentWebView);
}

private void updateContent(boolean isMarkdown) {
String content = summary.content();
if (isMarkdown) {
contentWebView.getEngine().loadContent(MARKDOWN_FORMATTER.format(content));
} else {
contentWebView.getEngine().loadContent(
"<body style='margin: 0; padding: 5px; width: 100vw'>" +
"<div style='white-space: pre-wrap; word-wrap: break-word; width: 100vw'>" +
content +
"</div></body>"
);
}
}

private void updateInfoText() {
String newInfo = summaryInfoText
.getText()
.replaceAll("%0", formatTimestamp(summary.timestamp()))
.replaceAll("%1", summary.aiProvider().getLabel() + " " + summary.model());

summaryInfoText.setText(newInfo);
}

private static String formatTimestamp(LocalDateTime timestamp) {
return timestamp.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.getDefault()));
}

@FXML
private void onMarkdownToggle() {
updateContent(markdownCheckbox.isSelected());
}

@FXML
private void onRegenerateButtonClick() {
regenerateCallback.run();
Expand Down
Loading