-
Notifications
You must be signed in to change notification settings - Fork 12
Home
Welcome to M2MD Wiki / Documentation
I am not planning to make a proper Mathematica Documentation for this paclet, this should not come as a surprise to anyone who ever tried to do it.
I am aware this documentation is minimal, I will try to improve it in future.
The paclet comes with a palette. It is outdated and the only available button there will convert a selected notebook to a MD string. The updates are coming.
There are two main functions in M2MD`:
-
MDExportwhich exports to a file and -
M2MDwhich returns a Markdown string.
They share the same options.
MDExport[ fileName_String, source_, OptionsPattern[] ]source can be a NotebookObject, CellObject or a Cell
"IgnoredStyles" -> None | {__String}M2MD[EvaluationNotebook[], "IgnoredStyles" -> {"Code", "Input", "Output"}]The converter first creates a symbolic representation of a markdown e.g.: MDElement[“h1”, “a title”] and this option allows us to overwrite existing rules by which it is translated to the final string.
"MDElementTemplates" -> _AssociationM2MD[ EvaluationCell[] ]
(*"```mathematica\nM2MD[ EvaluationCell[] ]\n```"*)M2MD[ EvaluationCell[], "MDElementTemplates" -> <|"CodeBlock" -> "**``**"|> ]
(*"**M2MD[ EvaluationCell[], \"MDElementTemplates\" -> <|\"CodeBlock\" -> \"**``**\"|> ]**"*)Default tag/templates are:
<|
"LaTeXBlock" -> "$$``$$"
, "LaTeXInline"-> "$``$"
, "Image" -> ""
, "Hyperlink" -> "[``](``)"
, "Text" -> "``"
, "Bold" -> "**``**"
, "Italic" -> "*``*"
, "h1" -> "# <*StringReplace[#, \"\n\"->\"<br>\"]*>"
, "h2" -> "## <*StringReplace[#, \"\n\"->\"<br>\"]*>"
, "h3" -> "### <*StringReplace[#, \"\n\"->\"<br>\"]*>"
, "h4" -> "#### <*StringReplace[#, \"\n\"->\"<br>\"]*>"
, "h5" -> "##### <*StringReplace[#, \"\n\"->\"<br>\"]*>"
, "h6" -> "###### <*StringReplace[#, \"\n\"->\"<br>\"]*>"
, "Comment" -> "[//]: # (``)"
, "CodeBlock" -> TemplateExpression @ StringJoin["```mathematica\n", TemplateSlot[1], "\n```"]
, "Output" -> TemplateExpression @ StringJoin["```\n(*", TemplateSlot[1], "*)\n```"]
|>Images are created for:
-
Graphics/Graphics3Dboxes -
”Output”cells that are notTraditionalFormor simple enough to export as input string -
StandardFormboxes that have no built in MD interpretation
MD images end up in as ![name][url]
"ImagesExportURL" -> Automatic | _If an image is based on a CellObject then the Automatic setting means the name will be the first CellTag. If there’s no tag then the name is based on the content’s expression hash.
This way re-exporting won’t create new files each time it is run.
If anything else than Automatic is provided then it will be applied to the subject of image export and it is expected to return a string that can be used as a name.
"ImagesExportURL" -> Automatic | None | path_StringBy default images are exported to ./img.
None means no image is created and a path_ is expected directory.
"ImagesFetchURL" -> "Relative" | Automatic | _String | _URL | _FileThis option specifies what gets to the URL part of MD element.
-
“ImagesFetchURL” -> “Relative”
means the finalurlwill beFileNameJoin[{FileNameTake[exportDir], “name.png”}]`. -
Automaticmeans the absolute path to the exported file. -
path : _String | _Filemeans the finalurlwill beFileNameJoin[{ path, name<>extensions}]. -
_URLis an important one because it acts the same way as above but the path will be created usingURLBuildinstead ofFileNameJoin
"OverwriteImages" -> True | FalseIf the subject to export as image was not changed then a new image won’t be created by default.
"ImagesExportURL" -> Automatic
"ImagesExportURL" -> Automatic, "ImagesFetchURL" -> "Relative"
"ImagesExportURL" -> Automatic, "ImagesFetchURL" -> URL["Test"]
SetOptions[PreviousCell[], CellTags -> {"my-name"}];
M2MD[PreviousCell[], "ImagesExportURL" -> $TemporaryDirectory, "ImagesFetchURL" -> URL@"online"]
- while repeatedly exported images should be exported to the same path keep in mind that no one will (yet) clean up those which were not overwritten.