Oracle APEX Reactive Markdown Plug-in #JoelKallmanDay

Display rich Markdown in Oracle APEX that reacts to changes of referenced page items.

TL;DR: I created a plug-in that renders Markdown in APEX and reacts to changes of referenced page items. Click here for demo and download links.

My pain with displaying rich text in APEX

Most of our applications probably don’t provide clear context or help text explaining their functionality. To solve this we can create a static content region, change the template and put some HTML in there. Easy, but as I am used to Markdown, writing a lot <p>, <li>, or <b> tags is a bit tedious.

For my Practical AI in PL/SQL Made Easy webinar I wanted to display the JSON response of the AI nicely formatted in a region. Additionally the JSON gets generated from a dynamic action without any submits so it needs to update automatically.

At that point I thought “probably possible with native APEX but too difficult”. So I decided to put my pain to rest and build a plug-in that solves this.

How does it work?

It is a region plug-in with three attributes.

Template

In the template attribute you can define what Markdown template should be rendered.

You can directly write Markdown into the attribute or reference a page item that contains some value. During rendering the plug-in will evaluate all values of the referenced page items.

1Hello! My name is `:P3050_NAME`. I am **:P3050_AGE** years old. I live in :P3050_CITY.
2

You could also put everything into a text item and just reference it. You can easily build a side-by-side editor with a textarea and the preview.

1:P3050_TEXT_INPUT
2

Reactivity Mode

APEX client-side features work on an event-based system. This means you have to manually add dynamic actions that run on change of item X to update item or region Y. This can be tedious if you have a lot of items that should trigger an update like a manual page filter.

Modern frontend frameworks are reactive (giving the React framework its name). That means you mark a variable and the framework automatically updates everything that depends on it. This is way more convenient.

The plug-in offers three reactivity modes:

  • change: the plug-in will update when a referenced page item changes (leave input)
  • input: the plug-in will update on every input (while typing)
  • off: no reactivity, only initial rendering

This is how it behaves in the input mode:

When typing in the input field, the markdown preview updates in real-time to reflect the changes.

Theme

The plug-in uses the GitHub Markdown CSS styles by default. There are light and dark theme variants. Additionally I built a Universal Theme variant that uses your APEX theme colors. Under the hood it uses the APEX CSS variables.

Noteworthy Markdown Features

In addition to the standard Markdown features, the plug-in supports:

  • Tables (not yet supported by the APEX_MARKDOWN package)
  • Code blocks with syntax highlighting for various languages
  • Math formulas
  • Alerts

This is the underlying markdown for the above screenshot:

1#### Code Block Example H4
2
3(remove # before ``` - my blog does not support nested code blocks...)
4#```sql
5SELECT
6    employee_id,
7    first_name,
8    last_name,
9    salary
10FROM
11    employees
12WHERE
13    salary > 50000;
14#```
15
16
17##### Table Example H5
18
19| Header 1         |   Header 2   |     Header 3 |
20| :--------------- | :----------: | -----------: |
21| Data Row 1A Long |   Data 1B    |      Data 1C |
22| Data Row 2A      | Data 2B Long | Long Data 2C |
23| Data Row 3A      |   Data 3B    |      Data 3C |
24
25###### Mathematics Example H6
26
27$$ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$
28
29###### Alerts
30
31> [!NOTE]
32> This is a note. It's often used for general information,
33> something to remember, or a side point.
34>
35> You can also include multiple paragraphs within a note
36> as long as each line starts with `>`.
37
38> [!TIP]
39> This is a tip! Remember to commit your changes frequently
40> to avoid losing your work.
41>
42> **Pro-tip:** Use `git status` often to stay aware of your
43> repository's state.
44
45> [!IMPORTANT]
46> This is an important piece of information.
47>
48> Please ensure you have backed up your database before
49> proceeding with any major schema changes.
50
51> [!WARNING]
52> This is a warning!
53>
54> Deleting this file will permanently remove user
55> configuration settings. Proceed with caution.
56
57> [!CAUTION]
58> This is a caution!
59>
60> Running this script without administrator privileges could
61> lead to system instability and data corruption.
62
63

Demo and Download

You can try out the plug-in in our United Codes Community Plug-Ins Sample App. We have 31 other free community plug-ins there as well.

You can download the plug-in for free from apex.world (currently pending approval) or from our Plug-Ins-Pro website.

The plug-in works with any version of APEX 19.2 and higher.