Worksheet
FromMarkdown
convert a markdown document to a Maple worksheet
Calling Sequence
Parameters
Description
Examples
Compatibility
FromMarkdown(str)
FromMarkdown(str, opts)
str
-
the Markdown source as a string or symbol, or the path to a file that contains the Markdown source
opts
(optional) equation(s) of the form source = s or output = o, where s is one of string, file, or auto and o is one of xml, insert, or display
The FromMarkdown command converts a Markdown file to a Maple worksheet.
The source document can be given as a string directly in the command, or as the name of a file that contains the source. This is determined by the source = s option:
When the option source = string is given, Maple interprets str itself as the Markdown source.
When the option source = file is given, Maple interprets str as the path to a file containing the Markdown source.
When the option source = auto is given, Maple checks if there is a file named str (using FileTools:-Exists). If so, it acts as if source = file was given. If not, it acts as if source = string was given.
The default behavior is given by the option source = auto.
The result can be returned as XML, inserted into the current worksheet, or displayed as a new worksheet. This is determined by the output = o option:
When the option output = xml is given, this command returns the resulting worksheet as XML. This is the only value of the output option that can be used in the command-line version of Maple.
When the option output = insert is given, this command inserts the resulting worksheet into the current worksheet using the DocumentTools:-InsertContent command.
When the option output = display is given, this command shows the resulting worksheet as a new, separate worksheet.
The default behaviour is given by the option output = xml.
with⁡Worksheet:
Here is how you can parse a simple Markdown string to an XML representation of a worksheet.
doc≔This is some *markdown*.
FromMarkdown⁡doc
_XML_Worksheet⁡_XML_Group⁡view=presentation,hide-input=false,hide-output=false,inline-output=false,drawlabel=true,_XML_Input⁡_XML_Text-field⁡alignment=left,style=Text,layout=Normal,This is some ,_XML_Font⁡italic=true,size=12,mathsize=12,mathvariant=normal,style=Text,background=[255,255,255],mathbackground=[255,255,255],foreground=[0,0,0],mathcolor=[0,0,0],family=Times New Roman,markdown,.
To insert this into the current worksheet, run this code instead.
FromMarkdown⁡doc,output=insert
This is some markdown.
To use a source file instead of a string, do the following. First, print the contents of the file so you can see what it looks like.
file≔FileTools:-JoinPath⁡example,markdown.md,:-base=:-datadir:
line≔FileTools:-Text:-ReadLine⁡file:
whileline≠NULLdoprintf⁡%s\n,line;line≔FileTools:-Text:-ReadLine⁡fileenddo:
A big heading ============= Here is a paragraph of text with *italics* and **bold text**. ## A smaller heading Another paragraph. Note that line breaks and multiple spaces are ignored. Here is a [link](https://www.maplesoft.com/) to Maplesoft's home page, and here is the Markdown logo: . Here is a third paragraph. ## Another small heading Note that the Markdown parser also supports limited LaTeX formulas, like $(x + y)/z^2$.
FileTools:-Text:-Close⁡file
Now parse the file and display it as a new worksheet.
FromMarkdown⁡file,output=display
Error, (in Python:-ImportModule) unable to start Python: could not create process, mpython
See Also
DocumentTools:-InsertContent
Worksheet:-Display
Download Help Document