---
nav_order: 0036
parent: Decision Records
---

# Use Markdown rendering for Chat Message Content

## Context and Problem Statement

This decision record concerns the UI component that is used for rendering the content of chat messages.

## Decision Drivers

* Looks good (renders Markdown)
* User can select and copy text
* Has good performance

## Considered Options

* Use `TextArea`
* Use a [third-party package](https://github.com/JPro-one/jpro-platform)
* Use a Markdown parser and convert AST nodes to JavaFX TextFlow elements
* Use a Markdown parser to convert content into HTML and use a WebView for one message
* Use a Markdown parser and WebView for the whole chat history

## Decision Outcome

Chosen option: (modified) "Use a Markdown parser and convert AST nodes to JavaFX TextFlow elements".
In JabRef there is a component `SelectableTextFlow` which allows to create a formatted text and to select it. This makes possible to use a Markdown parser that converts the content into JavaFX nodes and adds the feature selecting the text.

## Pros and Cons of the Options

### Use TextArea

* Good, because it is easy to implement
* Good, because it supports text selection and copying
* Bad, because it does not offer rich text. Thus, Markdown can only be displayed in a plain text form.
* Bad, because default JavaFX's `TextArea` shrinks

### Use a third-party package

There seems to be [only one package](https://github.com/JPro-one/markdown-javafx-renderer) for JavaFX that provides a ready-to-use UI node for Markdown rendering.

* Good, because it is easy to implement
* Good, because it renders Markdown
* Good, because it renders Markdown to JavaFX nodes (does not use a `WebView`)
* Good, because complex elements from Markdown are supported (tables, code blocks, etc.)
* Bad, because it has very strange issues and architectural flaws with styling
* Bad, because it does not support text selection and copying (because of underlying JavaFX `Text` nodes)

### Use a Markdown parser and convert AST nodes to JavaFX TextFlow elements

* Good, because we will support Markdown
* Good, because no need to write a Markdown parser from scratch
* Good, because does not use a WebView
* Good, because easy styling
* Bad, because we need some time to implement Markdown AST -> JavaFX nodes converter
* Bad, because rendering tables and code blocks may be hard
* Bad, because it will not support text selection and copying

### Use a Markdown parser to convert content into HTML and use a WebView for one message

* Good, because there are libraries to convert Markdown to HTML
* Good, because may be easier to implement than other choices (except `TextArea`)
* Good, because it supports text selection and copying
* Bad, because it may be a problem to connect JavaFX CSS to `WebView`
* Bad, because one `WebView` for one message is resourceful

### Use a Markdown parser and WebView for the whole chat history

* Good, because there are libraries to convert Markdown to HTML
* Good, because it supports text selection and copying
* Bad, because it may be a problem to connect JavaFX CSS to `WebView`
* Bad, because it may be a problem to correctly communicate with Java code and `WebView` to add new messages

## More Information

This ADR is highly linked to [ADR-0042](./0042-use-markdowntextflow-for-summarization-content.md).

Actually we used an `ExpandingTextArea` from `GemsFX` package so the content can occupy
as much space as it needs in the `ScrollPane`.

About the selection and copying, this goes down to fundamental issue from JavaFX.
`Text` and `Label` as a whole or a part [cannot be selected and/or copied](https://bugs.openjdk.org/browse/JDK-8091644).
