├── .gitattributes
├── .gitignore
├── Documentation
├── FAQ.m
└── Home.m
├── M2MD.iml
├── M2MD.nb
├── M2MD
├── Kernel
│ └── init.m
├── M2MD.m
└── PacletInfo.m
├── README.md
├── Tests
└── Basic.m
└── build.m
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.m linguist-language=Mathematica
2 | *.wlt linguist-language=Mathematica
3 | *.wls linguist-language=Mathematica
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/*
2 | *.paclet
3 | */FrontEnd/*/*.nb
4 |
5 |
--------------------------------------------------------------------------------
/Documentation/FAQ.m:
--------------------------------------------------------------------------------
1 | (* ::Package:: *)
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Documentation/Home.m:
--------------------------------------------------------------------------------
1 | (* ::Package:: *)
2 |
3 | (* ::Title:: *)
4 | (*M2MD Wiki*)
5 |
6 |
7 | (* ::Text:: *)
8 | (*Welcome to M2MD Wiki / Documentation*)
9 |
10 |
11 | (* ::Text:: *)
12 | (*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.*)
13 |
14 |
15 | (* ::Text:: *)
16 | (*I am aware this documentation is minimal, I will try to improve it in future. *)
17 |
18 |
19 | (* ::Text:: *)
20 | (*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.*)
21 |
22 |
23 | (* ::Title:: *)
24 | (*Quick documentation*)
25 |
26 |
27 | (* ::Text:: *)
28 | (*There are two main functions in M2MD`: *)
29 |
30 |
31 | (* ::Text:: *)
32 | (*- `MDExport` which exports to a file and *)
33 |
34 |
35 | (* ::Text:: *)
36 | (*- `M2MD` which returns a Markdown string.*)
37 |
38 |
39 | (* ::Text:: *)
40 | (*They share the same options.*)
41 |
42 |
43 | (* ::Section:: *)
44 | (*MDExport*)
45 |
46 |
47 | (* ::Subsection:: *)
48 | (*Usage*)
49 |
50 |
51 | MDExport[ fileName_String, source_, OptionsPattern[] ]
52 |
53 |
54 | (* ::Text:: *)
55 | (*source can be a `NotebookObject`, `CellObject` or a `Cell`*)
56 |
57 |
58 | (* ::Subsection:: *)
59 | (*Options*)
60 |
61 |
62 | (* ::Subsubsection:: *)
63 | (*`"IgnoredStyles"` - cells of which styles should be ignored *)
64 |
65 |
66 | "IgnoredStyles" -> None | {__String}
67 |
68 |
69 | M2MD[EvaluationNotebook[], "IgnoredStyles" -> {"Code", "Input", "Output"}]
70 |
71 |
72 | (* ::Subsubsection:: *)
73 | (*`"MDElementTemplates"`*)
74 |
75 |
76 | (* ::Text:: *)
77 | (*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.*)
78 |
79 |
80 | "MDElementTemplates" -> _Association
81 |
82 |
83 | M2MD[ EvaluationCell[] ]
84 |
85 |
86 | M2MD[ EvaluationCell[], "MDElementTemplates" -> <|"CodeBlock" -> "**``**"|> ]
87 |
88 |
89 | (* ::Text:: *)
90 | (*Default tag/templates are:*)
91 |
92 |
93 | <|
94 | "LaTeXBlock" -> "$$``$$"
95 | , "LaTeXInline"-> "$``$"
96 | , "Image" -> ""
97 | , "Hyperlink" -> "[``](``)"
98 | , "Text" -> "``"
99 | , "Bold" -> "**``**"
100 | , "Italic" -> "*``*"
101 |
102 | , "h1" -> "# <*StringReplace[#, \"\n\"->\"
\"]*>"
103 | , "h2" -> "## <*StringReplace[#, \"\n\"->\"
\"]*>"
104 | , "h3" -> "### <*StringReplace[#, \"\n\"->\"
\"]*>"
105 | , "h4" -> "#### <*StringReplace[#, \"\n\"->\"
\"]*>"
106 | , "h5" -> "##### <*StringReplace[#, \"\n\"->\"
\"]*>"
107 | , "h6" -> "###### <*StringReplace[#, \"\n\"->\"
\"]*>"
108 |
109 | , "Comment" -> "[//]: # (``)"
110 | , "CodeBlock" -> TemplateExpression @ StringJoin["```mathematica\n", TemplateSlot[1], "\n```"]
111 | , "Output" -> TemplateExpression @ StringJoin["```\n(*", TemplateSlot[1], "*)\n```"]
112 |
113 | |>
114 |
115 |
116 | (* ::Subsection:: *)
117 | (*Options - image export related*)
118 |
119 |
120 | (* ::Text:: *)
121 | (*Images are created for:*)
122 | (*- `Graphics/Graphics3D` boxes*)
123 | (*- `"Output"` cells that are not `TraditionalForm` or simple enough to export as input string*)
124 | (*- `StandardForm` boxes that have no built in MD interpretation*)
125 | (**)
126 | (*MD images end up in as `![name][url]`*)
127 |
128 |
129 | (* ::Subsubsection:: *)
130 | (*`"ImageNameFunction"`*)
131 |
132 |
133 | "ImagesExportURL" -> Automatic | _
134 |
135 |
136 | (* ::Text:: *)
137 | (*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.*)
138 | (*This way re-exporting won't create new files each time it is run.*)
139 | (**)
140 | (*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.*)
141 |
142 |
143 | (* ::Subsubsection:: *)
144 | (*`"ImagesExportURL"`*)
145 |
146 |
147 | "ImagesExportURL" -> Automatic | None | path_String
148 |
149 |
150 | (* ::Text:: *)
151 | (*By default images are exported to `./img`. *)
152 | (*None means no image is created and a `path_` is expected directory.*)
153 |
154 |
155 | (* ::Subsubsection:: *)
156 | (*`"ImagesFetchURL"`*)
157 |
158 |
159 | "ImagesFetchURL" -> "Relative" | Automatic | _String | _URL | _File
160 |
161 |
162 | (* ::Text:: *)
163 | (*This option specifies what gets to the URL part of MD element. *)
164 | (**)
165 | (*- "ImagesFetchURL" -> "Relative"` means the final `url` will be `FileNameJoin[{FileNameTake[exportDir], "name.png"}]`.*)
166 | (**)
167 | (*- `Automatic` means the absolute path to the exported file.*)
168 | (**)
169 | (*- `path : _String | _File` means the final `url` will be `FileNameJoin[{ path, name<>extensions}]`.*)
170 | (**)
171 | (*- `_URL` is an important one because it acts the same way as above but the path will be created using `URLBuild` instead of `FileNameJoin`*)
172 | (**)
173 |
174 |
175 | (* ::Subsubsection:: *)
176 | (*`"OverwriteImages"`*)
177 |
178 |
179 | "OverwriteImages" -> True | False
180 |
181 |
182 | (* ::Text:: *)
183 | (*If the subject to export as image was not changed then a new image won't be created by default.*)
184 |
185 |
186 | (* ::Subsection:: *)
187 | (*Examples*)
188 |
189 |
190 | "ImagesExportURL" -> Automatic
191 |
192 |
193 | (* ::Text:: *)
194 | (*\!\[image-76f31cc4-1dc6-4bc7-bbe8-0631e2681af6\]\(C:\Users\user\Documents\img\image-76f31cc4-1dc6-4bc7-bbe8-0631e2681af6.png\)*)
195 |
196 |
197 | "ImagesExportURL" -> Automatic, "ImagesFetchURL" -> "Relative"
198 |
199 |
200 | (* ::Text:: *)
201 | (*\!\[image-303bcb72-bb88-430f-9ba1-62ee0d928d33\]\(img\image-303bcb72-bb88-430f-9ba1-62ee0d928d33.png\)*)
202 |
203 |
204 | "ImagesExportURL" -> Automatic, "ImagesFetchURL" -> URL["Test"]
205 |
206 |
207 | (* ::Text:: *)
208 | (*\!\[image-822b8334-f5fd-43b2-8274-3a40165fe89c\]\(Test/image-822b8334-f5fd-43b2-8274-3a40165fe89c.png\)*)
209 |
210 |
211 | SetOptions[PreviousCell[], CellTags -> {"my-name"}];
212 | M2MD[PreviousCell[], "ImagesExportURL" -> $TemporaryDirectory, "ImagesFetchURL" -> URL@"online"]
213 |
214 |
215 | (* ::Text:: *)
216 | (*\!\[my-name\]\(online/my-name.png\)*)
217 |
218 |
219 | (* ::Section:: *)
220 | (*Possible issues*)
221 |
222 |
223 | (* ::Text:: *)
224 | (*- 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.*)
225 |
226 |
227 | SetDirectory@NotebookDirectory[];
228 |
229 |
230 | MDExport["Home.md", EvaluationNotebook[]]
231 |
232 |
233 | SystemOpen@%
234 |
--------------------------------------------------------------------------------
/M2MD.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/M2MD.nb:
--------------------------------------------------------------------------------
1 | Notebook[{
2 |
3 | Cell[CellGroupData[{
4 | Cell["M2MD", "Title",ExpressionUUID->"6d30d064-6ad5-4d00-ad1b-e90016088dff"],
5 |
6 | Cell[BoxData[{
7 | RowBox[{"PacletDirectoryAdd", " ", "@", " ",
8 | RowBox[{"NotebookDirectory", "[", "]"}]}], "\n",
9 | RowBox[{"SetDirectory", "@",
10 | RowBox[{"NotebookDirectory", "[", "]"}]}]}], "Input",
11 | CellLabel->"In[1]:=",ExpressionUUID->"5384612b-2fdb-4dd0-896d-9c2a84aa7f4e"],
12 |
13 | Cell[BoxData[
14 | RowBox[{"\[IndentingNewLine]",
15 | RowBox[{"<<", "M2MD`"}]}]], "Input",
16 | CellLabel->"In[3]:=",ExpressionUUID->"aeb9f136-81cb-44fa-b647-6baeefdfeb0d"],
17 |
18 | Cell[BoxData[
19 | RowBox[{"M2MD", "[",
20 | RowBox[{
21 | RowBox[{"Cell", "[",
22 | RowBox[{"\"\\"", ",", " ", "\"\\""}], "]"}], ",", " ",
23 | RowBox[{"\"\\"", " ", "\[Rule]", " ",
24 | RowBox[{"<|",
25 | RowBox[{"\"\\"", "\[Rule]", "\"\<\>\""}], "|>"}]}]}],
26 | "]"}]], "Input",
27 | CellLabel->"In[4]:=",ExpressionUUID->"b07a7c12-8c95-4337-8025-bd973939e722"],
28 |
29 | Cell[BoxData[
30 | RowBox[{
31 | RowBox[{"CreateDocument", "[", "\[IndentingNewLine]",
32 | RowBox[{"{",
33 | RowBox[{"Cell", "[",
34 | RowBox[{
35 | RowBox[{"M2MD", " ", "@", " ",
36 | RowBox[{"EvaluationNotebook", "[", "]"}]}], ",", "\"\\""}],
37 | "]"}], "}"}], "\[IndentingNewLine]", "]"}],
38 | "\[IndentingNewLine]"}]], "Input",
39 | CellLabel->
40 | "In[305]:=",ExpressionUUID->"dabb488c-d0c3-44a6-a3f4-9ac1cddbec74"],
41 |
42 | Cell[CellGroupData[{
43 |
44 | Cell["build", \
45 | "Subsection",ExpressionUUID->"106fee2a-c44e-4872-85cf-70e13c705c5d"],
46 |
47 | Cell[BoxData[
48 | RowBox[{"<<", "build.m"}]], "Input",
49 | CellLabel->"In[7]:=",ExpressionUUID->"5ac09f12-8b81-4f73-916d-f0b2c0360f4b"],
50 |
51 | Cell[BoxData[
52 | RowBox[{"PreviousCell", "[", "]"}]], "Input",
53 | CellLabel->"In[37]:=",ExpressionUUID->"abfe85b0-5012-404f-85cc-97d95d6924f5"],
54 |
55 | Cell[BoxData[
56 | RowBox[{"SetDirectory", "@", "$TemporaryDirectory"}]], "Input",
57 | CellLabel->"In[20]:=",ExpressionUUID->"92e6ee82-80c3-472c-87a3-4f585b0f016a"],
58 |
59 | Cell[BoxData[{
60 | RowBox[{"Directory", "[", "]"}], "\[IndentingNewLine]",
61 | RowBox[{"nb", "=",
62 | RowBox[{
63 | RowBox[{"Notebooks", "[", "]"}], "[",
64 | RowBox[{"[", "2", "]"}], "]"}]}]}], "Input",
65 | CellLabel->"In[26]:=",ExpressionUUID->"7a977348-f0c9-4ecf-ac42-bfe37b019021"],
66 |
67 | Cell[BoxData[
68 | RowBox[{
69 | RowBox[{"MDExport", "[",
70 | RowBox[{"\"\\"", ",", "nb", ",",
71 | RowBox[{"\"\\"", "\[Rule]", "\"\\""}]}],
72 | "]"}], "//", "AbsoluteTiming"}]], "Input",
73 | CellLabel->"In[28]:=",ExpressionUUID->"025f7c36-8f61-4289-819d-b87d43162bb0"],
74 |
75 | Cell[BoxData[
76 | RowBox[{"SystemOpen", "@",
77 | RowBox[{"%", "[",
78 | RowBox[{"[", "2", "]"}], "]"}]}]], "Input",
79 | CellLabel->"In[29]:=",ExpressionUUID->"e33cf853-1695-46b7-8632-2c3284124825"],
80 |
81 | Cell[BoxData[
82 | RowBox[{
83 | RowBox[{"Notebooks", "[", "]"}], "[",
84 | RowBox[{"[", "2", "]"}], "]"}]], "Input",
85 | CellLabel->
86 | "In[150]:=",ExpressionUUID->"71e89637-89d5-43c2-a335-281fa7a21993"],
87 |
88 | Cell[BoxData[
89 | RowBox[{"PrintDefinitions", "@", "M2MD"}]], "Input",
90 | CellLabel->"In[1]:=",ExpressionUUID->"0099416c-8c5d-4497-9915-73781789714b"]
91 | }, Open ]],
92 |
93 | Cell[CellGroupData[{
94 |
95 | Cell["tests", \
96 | "Section",ExpressionUUID->"d6f7fe7e-3205-41c8-bb96-753bc71c7aa5"],
97 |
98 | Cell[BoxData[
99 | RowBox[{"reports", "=",
100 | RowBox[{"TestReport", " ", "/@", " ",
101 | RowBox[{"FileNames", "[",
102 | RowBox[{"\"\<*.m\>\"", ",", " ",
103 | RowBox[{"{",
104 | RowBox[{"FileNameJoin", "[",
105 | RowBox[{"{",
106 | RowBox[{
107 | RowBox[{"NotebookDirectory", "[", "]"}], ",", " ", "\"\\""}],
108 | "}"}], "]"}], "}"}]}], "]"}]}]}]], "Input",
109 | CellLabel->"In[28]:=",ExpressionUUID->"5b53fe5f-f56a-432c-b96f-b38c91a9e46a"],
110 |
111 | Cell[BoxData[
112 | RowBox[{
113 | RowBox[{"reports", "[",
114 | RowBox[{"[", "1", "]"}], "]"}], "[", "\"\\"", "]"}]], "Input",
115 | CellLabel->"In[29]:=",ExpressionUUID->"d22e7dbc-33d2-4263-aca5-976ce47d7d6e"],
116 |
117 | Cell[BoxData[
118 | RowBox[{"Internal`InheritedBlock", "[",
119 | RowBox[{
120 | RowBox[{"{",
121 | RowBox[{
122 | RowBox[{"$MDEnvironment", " ", "=", " ", "True"}], ",", " ", "M2MD"}],
123 | "}"}], ",", " ",
124 | RowBox[{
125 | RowBox[{
126 | RowBox[{"Attributes", "[", "M2MD", "]"}], "=",
127 | RowBox[{"{", "}"}]}], ";", "\n", " ",
128 | RowBox[{"Nest", "[", "\n", " ",
129 | RowBox[{
130 | RowBox[{"ReplaceAll", "[",
131 | RowBox[{"DownValues", "[", "M2MD", "]"}], "]"}], "\n", " ", ",", " ",
132 | RowBox[{"Hold", " ", "@", " ",
133 | RowBox[{"M2MD", " ", "@", " ",
134 | RowBox[{"Cell", "[",
135 | RowBox[{"\"\<1+\\n2\>\"", ",", " ", "\"\\""}], "]"}]}]}],
136 | "\n", " ", ",", " ", "2"}], "\n", " ", "]"}]}]}], "\n",
137 | "]"}]], "Code",ExpressionUUID->"acda713c-39b6-43f6-9906-9a4d1b4bd2dc"],
138 |
139 | Cell[BoxData[
140 | RowBox[{"Internal`InheritedBlock", "[",
141 | RowBox[{
142 | RowBox[{"{",
143 | RowBox[{
144 | RowBox[{"$MDEnvironment", " ", "=", " ", "True"}], ",", " ", "M2MD"}],
145 | "}"}], ",", " ",
146 | RowBox[{
147 | RowBox[{
148 | RowBox[{"Attributes", "[", "M2MD", "]"}], "=",
149 | RowBox[{"{", "}"}]}], ";", "\n", " ",
150 | RowBox[{"MatchQ", "[", "\n", " ",
151 | RowBox[{
152 | RowBox[{"Hold", " ", "@", " ",
153 | RowBox[{"M2MD", "[",
154 | RowBox[{"\"\\"", ",", " ",
155 | RowBox[{"Cell", "[",
156 | RowBox[{"\"\<1+\\n2\>\"", ",", " ", "\"\\""}], "]"}]}],
157 | " ", "]"}]}], ",", "\n", " ",
158 | RowBox[{
159 | RowBox[{"Verbatim", "[", "Hold", "]"}], " ", "@", " ",
160 | RowBox[{
161 | RowBox[{"Verbatim", "[", "M2MD", "]"}], "[", " ",
162 | RowBox[{
163 | RowBox[{"_", "?",
164 | RowBox[{"(",
165 | RowBox[{"Echo", "@*", "InputStyleQ", "@*", "Echo"}], ")"}]}], ",",
166 | " ", "cell_"}], "]"}]}]}], "\n", " ", "]"}]}]}], "\n",
167 | "]"}]], "Code",ExpressionUUID->"b660457c-2bdc-4366-8399-11881b371d72"],
168 |
169 | Cell[BoxData[
170 | RowBox[{
171 | RowBox[{"docsCell", "=", " ",
172 | RowBox[{"Cell", "[",
173 | RowBox[{
174 | RowBox[{"TextData", "[",
175 | RowBox[{"{", "\n", " ",
176 | RowBox[{"\"\\"", ",", "\n", " ",
177 | RowBox[{"Cell", "[",
178 | RowBox[{
179 | RowBox[{"BoxData", "[", "\n", " ",
180 | RowBox[{"TemplateBox", "[",
181 | RowBox[{
182 | RowBox[{"{",
183 | RowBox[{
184 | RowBox[{"Cell", "[", "\n", " ",
185 | RowBox[{"TextData", "[", "\"\\"", "]"}], "]"}],
186 | ",", "\"\\""}], "}"}], ",", "\n", " ",
187 | "\"\\"", ",", "\n", " ",
188 | RowBox[{"BaseStyle", "->",
189 | RowBox[{"{", "\"\\"", "}"}]}]}], "]"}], "]"}],
190 | ",", " ", "\"\\"", ",", "\n", " ",
191 | RowBox[{"FontFamily", "->", "\"\\""}]}], "]"}],
192 | ",", "\n", " ", "\"\<:\>\""}], "\n", "}"}], "]"}], ",", " ",
193 | "\"\\"", ",", "\n", " ",
194 | RowBox[{"CellID", "->", "480966610"}]}], "]"}]}],
195 | ";"}]], "Code",ExpressionUUID->"17228c84-e586-4f6b-a13f-f29ffa583483"],
196 |
197 | Cell[BoxData[
198 | RowBox[{"M2MD", " ", "@", " ",
199 | "docsCell"}]], \
200 | "Code",ExpressionUUID->"b15620a5-c442-4376-8866-06558d8c78f5"],
201 |
202 | Cell[BoxData[{
203 | RowBox[{
204 | RowBox[{"ClearAll", "@", "foo"}], ";"}], "\n",
205 | RowBox[{
206 | RowBox[{"foo", "[",
207 | RowBox[{"lbl_String", ",", " ", "url_String"}], "]"}], ":=",
208 | RowBox[{
209 | RowBox[{"StringTemplate", "[", "\"\<[``](``)\>\"", "]"}], "[",
210 | RowBox[{"lbl", ",", " ", "url"}], "]"}]}], "\n",
211 | RowBox[{
212 | RowBox[{
213 | RowBox[{"foo", "[",
214 | RowBox[{"lbl_String", ",", " ",
215 | RowBox[{"url_String", "?",
216 | RowBox[{"(",
217 | RowBox[{"StringContainsQ", "[", "\"\\"", "]"}],
218 | ")"}]}]}], " ", "]"}], ":=", " ",
219 | RowBox[{"(", "\n", " ",
220 | RowBox[{"(*",
221 | RowBox[{"do", " ", "whatever"}], "*)"}], "\n", " ", "url", "\n",
222 | ")"}]}], "\n"}], "\n",
223 | RowBox[{"M2MD", "[", "\n", " ",
224 | RowBox[{"docsCell", ",", " ", "\n", " ",
225 | RowBox[{"\"\\"", " ", "->", " ",
226 | RowBox[{"<|", "\n", " ",
227 | RowBox[{"\"\\"", " ", "->", " ", "\"\<<*foo[#, #2]*>\>\""}],
228 | "\n", " ", "|>"}]}]}], "\n",
229 | "]"}]}], "Code",ExpressionUUID->"e891cb52-c138-477c-9943-ba5593fe1b49"],
230 |
231 | Cell[BoxData[
232 | RowBox[{"Block", "[",
233 | RowBox[{
234 | RowBox[{"{",
235 | RowBox[{"M2MD`Private`$MDEnvironment", " ", "=", " ", "True"}], "}"}],
236 | ",", "\n", " ",
237 | RowBox[{
238 | RowBox[{"Hold", " ", "@", " ",
239 | RowBox[{"M2MD", " ", "@", " ",
240 | RowBox[{"Cell", "[",
241 | RowBox[{"\"\\"", ",", " ", "\"\- \""}], "]"}]}]}], " ", "/.",
242 | " ",
243 | RowBox[{"DownValues", "[", "M2MD", "]"}]}]}], " ", "\n",
244 | "]"}]], "Code",ExpressionUUID->"2d9c47f4-7372-416e-864c-74f5b40d1194"],
245 |
246 | Cell[BoxData[
247 | RowBox[{"M2MD`Private`ItemStyleQ", "@",
248 | "\"\
- \""}]], \
249 | "Code",ExpressionUUID->"1726243c-4ed4-43f6-8674-c1eac603b6d6"],
250 |
251 | Cell[BoxData[
252 | RowBox[{"PrintDefinitions", " ", "@", " ",
253 | "M2MD"}]], "Code",ExpressionUUID->"90270b62-de2c-4b73-b046-f207223282eb"],
254 |
255 | Cell[BoxData[
256 | RowBox[{"M2MD", " ", "@", " ",
257 | RowBox[{"Cell", "[",
258 | RowBox[{
259 | RowBox[{"BoxData", "[", "\n", " ",
260 | RowBox[{"RowBox", "[",
261 | RowBox[{"{", " ",
262 | RowBox[{
263 | RowBox[{"RowBox", "[",
264 | RowBox[{"{",
265 | RowBox[{
266 | "\"\\"", ",", " ", "\"\<=\>\"", ",", " ", "\"\< \>\"", ",",
267 | " ",
268 | RowBox[{"GraphicsBox", "[",
269 | RowBox[{"DiskBox", "[",
270 | RowBox[{"{",
271 | RowBox[{"0", ",", " ", "0"}], "}"}], "]"}], "]"}]}], "}"}],
272 | "]"}], ",", " ", "\"\<;\>\""}], "}"}], "]"}], "]"}], ",", " ",
273 | "\"\
\""}], " ",
274 | "]"}]}]], "Code",ExpressionUUID->"0b323a58-8dc8-45ca-90b5-1899b05c0f4a"],
275 |
276 | Cell[BoxData[
277 | RowBox[{"M2MD", " ", "@", " ",
278 | RowBox[{"Cell", "[",
279 | RowBox[{
280 | RowBox[{"TextData", "[",
281 | RowBox[{"{", "\n", " ",
282 | RowBox[{"\"\\"", ",", "\n", " ",
283 | RowBox[{"Cell", "[",
284 | RowBox[{"BoxData", "[", "\n", " ",
285 | RowBox[{"GraphicsBox", "[",
286 | RowBox[{
287 | RowBox[{"DiskBox", "[",
288 | RowBox[{"{",
289 | RowBox[{"0", ",", " ", "0"}], "}"}], "]"}], ",", " ",
290 | RowBox[{"ImageSize", " ", "->", " ", "20"}]}], "]"}], "]"}], " ",
291 | "]"}]}], "\n", "}"}], "]"}], ",", " ", "\"\\""}],
292 | "]"}]}]], "Code",ExpressionUUID->"0fc696eb-cc54-4fa0-9592-990669609c7b"],
293 |
294 | Cell[CellGroupData[{
295 |
296 | Cell["style rules", \
297 | "Subsection",ExpressionUUID->"f717b148-997b-430a-82e6-35c156df8026"],
298 |
299 | Cell[BoxData[
300 | RowBox[{"SetDirectory", "@", "$TemporaryDirectory"}]], "Input",
301 | CellLabel->"In[16]:=",ExpressionUUID->"1715cf84-6479-4d8c-923f-d86b5f270f40"],
302 |
303 | Cell[BoxData[{
304 | RowBox[{"M2MD", "[", " ",
305 | RowBox[{"Cell", "[",
306 | RowBox[{"\"\\"", ",", " ", "\"\\""}], "]"}], "]"}], "\n",
307 | RowBox[{"M2MD", "[", " ",
308 | RowBox[{
309 | RowBox[{"Cell", "[",
310 | RowBox[{"\"\\"", ",", " ", "\"\\""}], "]"}], ",", " ",
311 | RowBox[{"\"\\"", " ", "\[Rule]", " ",
312 | RowBox[{"<|",
313 | RowBox[{"\"\\"", " ", "\[Rule]", " ", "\"\\""}],
314 | "|>"}]}]}], "]"}], "\n",
315 | RowBox[{"M2MD", "[", " ",
316 | RowBox[{
317 | RowBox[{"Cell", "[",
318 | RowBox[{"\"\\"", ",", " ", "\"\\""}], "]"}], ",", " ",
319 | RowBox[{"\"\\"", " ", "\[Rule]", " ",
320 | RowBox[{"<|",
321 | RowBox[{"\"\\"", " ", "\[Rule]", " ",
322 | RowBox[{"{",
323 | RowBox[{"\"\\"", ",", " ",
324 | RowBox[{
325 | RowBox[{"BoxesToTeXString", "[", "#", "]"}], "&"}]}], "}"}]}],
326 | "|>"}]}]}], "]"}], "\n",
327 | RowBox[{"M2MD", "[", " ",
328 | RowBox[{
329 | RowBox[{"Cell", "[",
330 | RowBox[{"\"\\"", ",", " ", "\"\\""}], "]"}], ",", " ",
331 | RowBox[{"\"\\"", " ", "\[Rule]", " ",
332 | RowBox[{"<|",
333 | RowBox[{"\"\\"", " ", "\[Rule]", " ",
334 | RowBox[{"{",
335 | RowBox[{"\"\\"", ",", " ",
336 | RowBox[{
337 | RowBox[{"ToImageElement", "[", "#", "]"}], "&"}]}], "}"}]}],
338 | "|>"}]}]}], "]"}]}], "Code",
339 | CellLabel->"In[17]:=",ExpressionUUID->"eaf31bfc-43b5-4ee1-9b62-dbe6f3ef2ecd"],
340 |
341 | Cell[" specification {tag_, parsers___} translates to ", \
342 | "Text",ExpressionUUID->"7ed0adeb-bc69-4543-9cad-b1be780426dc"],
343 |
344 | Cell[BoxData[
345 | RowBox[{"MDElement", "[",
346 | RowBox[{"tag", ",", " ",
347 | RowBox[{"parser1", "[",
348 | RowBox[{"cell_", ",", " ", "style_"}], "]"}], ",", " ",
349 | RowBox[{"parser2", "[",
350 | RowBox[{"cell_", ",", " ", "style_"}], "]"}], ",", " ", "___"}],
351 | "]"}]], "Code",ExpressionUUID->"ea446a9d-91d4-454c-9818-c9eeba495d9e"],
352 |
353 | Cell["\<\
354 | Built-in parsers :
355 | BoxesToMDString
356 | BoxesToInputString
357 | ToImageElement
358 | BoxesToTeXString
359 |
360 | But you can use whatever you want as long as it returns something that \
361 | MDElementTemplate for given tag can handle.\
362 | \>", "Text",ExpressionUUID->"1a0ae989-cd03-44cf-a988-9fc47f4c2a9f"],
363 |
364 | Cell["We can go even further and define a brand new conversion:", \
365 | "Text",ExpressionUUID->"5de9ed14-c9e5-41b7-9bd9-867373faab85"],
366 |
367 | Cell[BoxData[
368 | RowBox[{"\n",
369 | RowBox[{"M2MD", "[", " ",
370 | RowBox[{
371 | RowBox[{"Cell", "[",
372 | RowBox[{"\"\\"", ",", " ", "\"\\""}], "]"}], ",", " ",
373 | "\[IndentingNewLine]",
374 | RowBox[{"\"\\"", " ", "\[Rule]", " ",
375 | RowBox[{"<|",
376 | RowBox[{"\"\\"", " ", "\[Rule]", " ", "\"\\""}],
377 | "|>"}]}], ",", "\[IndentingNewLine]", " ",
378 | RowBox[{"\"\\"", "\[Rule]",
379 | RowBox[{"<|",
380 | RowBox[{"\"\\"", "\[Rule]", "\"\<# ((((``))))\\n---\>\""}],
381 | "|>"}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input",
382 | CellLabel->"In[25]:=",ExpressionUUID->"41679aa3-cd5b-4514-b3d6-a26534bf015b"],
383 |
384 | Cell["\<\
385 | Together with \[OpenCurlyDoubleQuote]IgnoredStyles\[CloseCurlyDoubleQuote] \
386 | option you can probably get a lot done with standard documentation notebooks\
387 | \>", "Text",ExpressionUUID->"a2c7340a-2a89-4013-8189-ddf7fb74b415"],
388 |
389 | Cell[BoxData[{
390 | RowBox[{
391 | RowBox[{"nb", "=",
392 | RowBox[{"NotebookPut", "@",
393 | RowBox[{"Notebook", "@",
394 | RowBox[{"List", "@",
395 | RowBox[{"Cell", "[",
396 | RowBox[{
397 | RowBox[{"BoxData", "@",
398 | RowBox[{"ToBoxes", "@",
399 | RowBox[{"Graphics", "@",
400 | RowBox[{"Disk", "[", "]"}]}]}]}], ",", "\"\