Function Repository Resource:

ImportMarkdownString

Source Notebook

Convert a string in Markdown format to a formatted expression

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["ImportMarkdownString"]["markdown"]

imports "markdown" as a formatted expression.

ResourceFunction["ImportMarkdownString"]["markdown","prop"]

imports the specified property "prop" from "markdown".

Details

The value for "prop" can be any of the following:
Automatica formatted expression
"Cell"a Cell expression that represents the formatted content
"Notebook"a Notebook expression

Examples

Basic Examples (7) 

Import a markdown string as a formatted expression:

In[1]:=
ResourceFunction["ImportMarkdownString"]["**bold** and *italic* text"]
Out[1]=

Inline TEX formatting:

In[2]:=
ResourceFunction[
 "ImportMarkdownString"]["Math formatting: $$\\int_0^1 \\sin (\\sin (x)) \\, dx$$"]
Out[2]=

Hyperlinks:

In[3]:=
ResourceFunction[
 "ImportMarkdownString"]["Visit [this website](https://www.wolfram.com) for more information."]
Out[3]=

Automatic documentation links:

In[4]:=
ResourceFunction[
 "ImportMarkdownString"]["My favorite Wolfram Language symbols are `Plot` and `Table`."]
Out[4]=

Inline code and code blocks:

In[5]:=
ResourceFunction[
 "ImportMarkdownString"]["Plot a function `f[x]` with:
```wl
Plot[f[x], {x, -5, 5}]
```"]
Out[5]=

Images:

In[6]:=
ResourceFunction[
 "ImportMarkdownString"]["A markdown image: ![rose](http://exampledata.wolfram.com/rose.gif)"]
Out[6]=

Document structures:

In[7]:=
ResourceFunction["ImportMarkdownString"]["# My Title

## First section

* Item 1
* Item 2
  * Subitem 1
  * Subitem 2

## Second section

This is *really* cool.

---

That was a horizontal delimiter."]
Out[7]=

Scope (2) 

Get a Cell expression from a markdown string:

In[8]:=
ResourceFunction[
 "ImportMarkdownString"]["**bold** and *italic* text", "Cell"]
Out[8]=

Print it:

In[9]:=
CellPrint[%]

bold and italic text


Get a Notebook expression with content divided into multiple cells:

In[10]:=
Short[notebook = ResourceFunction["ImportMarkdownString"]["# My Title

## First section

Look at this cat:

```wl
ColorNegate[\[FreeformPrompt][\"picture of a cat\"]]
```

## Second section

![rose](http://exampledata.wolfram.com/rose.gif)", "Notebook"]]
Out[10]=

See the notebook:

In[11]:=
NotebookPut[%]
Out[11]=

Properties and Relations (2) 

For many simple markdown strings, ExportMarkdownString and ImportMarkdownString are effectively inverses of one another:

In[12]:=
ResourceFunction["ExportMarkdownString"][
 ResourceFunction["ImportMarkdownString"][
  "**bold** and *italic* text"]]
Out[12]=

ImportMarkdownString supports some additional special syntax for Wolfram Language code blocks:

In[13]:=
ResourceFunction["ImportMarkdownString"]["Natural language inputs:

```wl
GeoDistance[\[FreeformPrompt][\"Los Angeles, CA\"], \[FreeformPrompt][\"San Francisco, CA\"]]
```"]
Out[13]=

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.0 – 23 August 2024

Related Resources

License Information