Skip to content

Commit 772f546

Browse files
authored
Add support for markdown -> XAML parsing (#17585)
This adds support to the Terminal for parsing Markdown to XAML. We're using https://github.com/github/cmark-gfm as our parser, so that we can support the fullness of github-flavored markdown. The parser parses the markdown to produce a `RichTextBlock`, which covers just about all the scenarios we need. Since we're initially just targeting using this for "Release notes", I didn't implement _everything_ in markdown[^1]. But headers, bold & italic, unordered lists, images, links, code spans & blocks - all that works. We can work on additional elements as we need them. The parser is encapsulated into `Microsoft.Terminal.UI.Markdown.dll`, so that we won't load it on startup, only when the pane is actually made the first time. To test this out, I've added a `MarkdownPaneContent` pane type on `x-markdown` (the `x-` is "experimental"). Go ahead and add that with: ```json { "command": { "action": "splitPane", "type": "x-markdown" } } ``` That's got the ability to load arbitrary MD files and render them. I wouldn't call that experience finished though[^2][^3](and it probably won't be in 1.22 timeframe). However, it is an excellent testbed for validating what we do and do not support. We'll use the markdown parser Soon<sup>TM</sup> for the What's New panes. * Done in pursuit of displaying release notes in the Terminal. * Doesn't quite close out #16495 * Should make #8647 possible * may help with #16484 [^1]: the most notable gap being "block quotes" with `>`. I don't think I can draw a vertical line in a rich text block easily. Footnotes are also missing, as well as tables. [^2]: I say it's not finished because the aforementioned MD gaps. Also the UX there is not polished at all. [^3]: I don't believe we'll have time to polish out the pure markdown pane for 1.22, but what the parser covers now is more than enough for the release notes pane in time for 1.22
1 parent 52262b0 commit 772f546

33 files changed

+1775
-2
lines changed

.github/actions/spelling/allow/allow.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ breadcrumbs
55
ccmp
66
ccon
77
clickable
8+
cmark
89
CMMI
910
colorbrewer
1011
consvc
@@ -22,6 +23,7 @@ Emacspeak
2223
Fitt
2324
FTCS
2425
gantt
26+
gfm
2527
ghe
2628
gje
2729
godbolt

.github/actions/spelling/allow/apis.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ DONTADDTORECENT
4343
DWMSBT
4444
DWMWA
4545
DWORDLONG
46+
EMPH
4647
endfor
4748
ENDSESSION
4849
enumset
@@ -62,6 +63,7 @@ GETDESKWALLPAPER
6263
GETHIGHCONTRAST
6364
GETMOUSEHOVERTIME
6465
GETTEXTLENGTH
66+
HARDBREAKS
6567
Hashtable
6668
HIGHCONTRASTON
6769
HIGHCONTRASTW
@@ -115,6 +117,7 @@ IUri
115117
IVirtual
116118
KEYSELECT
117119
LCID
120+
LINEBREAK
118121
llabs
119122
llu
120123
localtime
@@ -148,6 +151,7 @@ NIF
148151
NIN
149152
NOAGGREGATION
150153
NOASYNC
154+
NOBREAKS
151155
NOCHANGEDIR
152156
NOPROGRESS
153157
NOREDIRECTIONBITMAP
@@ -204,6 +208,7 @@ SINGLEUSE
204208
SIZENS
205209
smoothstep
206210
snprintf
211+
SOFTBREAK
207212
spsc
208213
sregex
209214
SRWLOC

.github/actions/spelling/excludes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
^doc/reference/UTF8-torture-test\.txt$
105105
^doc/reference/windows-terminal-logo\.ans$
106106
^oss/
107+
^NOTICE.md
107108
^samples/PixelShaders/Screenshots/
108109
^src/interactivity/onecore/BgfxEngine\.
109110
^src/renderer/atlas/

NOTICE.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,181 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the
281281
specific language governing permissions and limitations under the License.
282282
```
283283

284+
## cmark
285+
**Source**: [https://github.com/commonmark/cmark](https://github.com/commonmark/cmark)
286+
287+
### License
288+
Copyright (c) 2014, John MacFarlane
289+
290+
All rights reserved.
291+
292+
Redistribution and use in source and binary forms, with or without
293+
modification, are permitted provided that the following conditions are met:
294+
295+
* Redistributions of source code must retain the above copyright
296+
notice, this list of conditions and the following disclaimer.
297+
298+
* Redistributions in binary form must reproduce the above
299+
copyright notice, this list of conditions and the following
300+
disclaimer in the documentation and/or other materials provided
301+
with the distribution.
302+
303+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
304+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
305+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
306+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
307+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
308+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
309+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
310+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
311+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
312+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
313+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
314+
315+
-----
316+
317+
houdini.h, houdini_href_e.c, houdini_html_e.c, houdini_html_u.c
318+
319+
derive from https://github.com/vmg/houdini (with some modifications)
320+
321+
Copyright (C) 2012 Vicent Martí
322+
323+
Permission is hereby granted, free of charge, to any person obtaining a copy of
324+
this software and associated documentation files (the "Software"), to deal in
325+
the Software without restriction, including without limitation the rights to
326+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
327+
of the Software, and to permit persons to whom the Software is furnished to do
328+
so, subject to the following conditions:
329+
330+
The above copyright notice and this permission notice shall be included in all
331+
copies or substantial portions of the Software.
332+
333+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
334+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
335+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
336+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
337+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
338+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
339+
SOFTWARE.
340+
341+
-----
342+
343+
buffer.h, buffer.c, chunk.h
344+
345+
are derived from code (C) 2012 Github, Inc.
346+
347+
Permission is hereby granted, free of charge, to any person obtaining a copy of
348+
this software and associated documentation files (the "Software"), to deal in
349+
the Software without restriction, including without limitation the rights to
350+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
351+
of the Software, and to permit persons to whom the Software is furnished to do
352+
so, subject to the following conditions:
353+
354+
The above copyright notice and this permission notice shall be included in all
355+
copies or substantial portions of the Software.
356+
357+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
358+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
359+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
360+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
361+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
362+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
363+
SOFTWARE.
364+
365+
-----
366+
367+
utf8.c and utf8.c
368+
369+
are derived from utf8proc
370+
(<http://www.public-software-group.org/utf8proc>),
371+
(C) 2009 Public Software Group e. V., Berlin, Germany.
372+
373+
Permission is hereby granted, free of charge, to any person obtaining a
374+
copy of this software and associated documentation files (the "Software"),
375+
to deal in the Software without restriction, including without limitation
376+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
377+
and/or sell copies of the Software, and to permit persons to whom the
378+
Software is furnished to do so, subject to the following conditions:
379+
380+
The above copyright notice and this permission notice shall be included in
381+
all copies or substantial portions of the Software.
382+
383+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
384+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
385+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
386+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
387+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
388+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
389+
DEALINGS IN THE SOFTWARE.
390+
391+
-----
392+
393+
The normalization code in normalize.py was derived from the
394+
markdowntest project, Copyright 2013 Karl Dubost:
395+
396+
The MIT License (MIT)
397+
398+
Copyright (c) 2013 Karl Dubost
399+
400+
Permission is hereby granted, free of charge, to any person obtaining
401+
a copy of this software and associated documentation files (the
402+
"Software"), to deal in the Software without restriction, including
403+
without limitation the rights to use, copy, modify, merge, publish,
404+
distribute, sublicense, and/or sell copies of the Software, and to
405+
permit persons to whom the Software is furnished to do so, subject to
406+
the following conditions:
407+
408+
The above copyright notice and this permission notice shall be
409+
included in all copies or substantial portions of the Software.
410+
411+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
412+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
413+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
414+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
415+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
416+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
417+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
418+
419+
-----
420+
421+
The CommonMark spec (test/spec.txt) is
422+
423+
Copyright (C) 2014-15 John MacFarlane
424+
425+
Released under the Creative Commons CC-BY-SA 4.0 license:
426+
<http://creativecommons.org/licenses/by-sa/4.0/>.
427+
428+
-----
429+
430+
The test software in test/ is
431+
432+
Copyright (c) 2014, John MacFarlane
433+
434+
All rights reserved.
435+
436+
Redistribution and use in source and binary forms, with or without
437+
modification, are permitted provided that the following conditions are met:
438+
439+
* Redistributions of source code must retain the above copyright
440+
notice, this list of conditions and the following disclaimer.
441+
442+
* Redistributions in binary form must reproduce the above
443+
copyright notice, this list of conditions and the following
444+
disclaimer in the documentation and/or other materials provided
445+
with the distribution.
446+
447+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
448+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
449+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
450+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
451+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
452+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
453+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
454+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
455+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
456+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
457+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
458+
284459
# Microsoft Open Source
285460

286461
This product also incorporates source code from other Microsoft open source projects, all licensed under the MIT license.

OpenConsole.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenderingTests", "src\tools
405405
EndProject
406406
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.Terminal.UI", "src\cascadia\UIHelpers\UIHelpers.vcxproj", "{6515F03F-E56D-4DB4-B23D-AC4FB80DB36F}"
407407
EndProject
408+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.Terminal.UI.Markdown", "src\cascadia\UIMarkdown\UIMarkdown.vcxproj", "{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}"
409+
EndProject
408410
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchcat", "src\tools\benchcat\benchcat.vcxproj", "{2C836962-9543-4CE5-B834-D28E1F124B66}"
409411
EndProject
410412
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleMonitor", "src\tools\ConsoleMonitor\ConsoleMonitor.vcxproj", "{328729E9-6723-416E-9C98-951F1473BBE1}"
@@ -2302,6 +2304,28 @@ Global
23022304
{6515F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Release|x64.Build.0 = Release|x64
23032305
{6515F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Release|x86.ActiveCfg = Release|Win32
23042306
{6515F03F-E56D-4DB4-B23D-AC4FB80DB36F}.Release|x86.Build.0 = Release|Win32
2307+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.AuditMode|Any CPU.ActiveCfg = Debug|Win32
2308+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.AuditMode|ARM64.ActiveCfg = Release|ARM64
2309+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.AuditMode|x64.ActiveCfg = Release|x64
2310+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.AuditMode|x86.ActiveCfg = Release|Win32
2311+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Debug|Any CPU.ActiveCfg = Debug|x64
2312+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Debug|ARM64.ActiveCfg = Debug|ARM64
2313+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Debug|ARM64.Build.0 = Debug|ARM64
2314+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Debug|x64.ActiveCfg = Debug|x64
2315+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Debug|x64.Build.0 = Debug|x64
2316+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Debug|x86.ActiveCfg = Debug|Win32
2317+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Debug|x86.Build.0 = Debug|Win32
2318+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Fuzzing|Any CPU.ActiveCfg = Fuzzing|x64
2319+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Fuzzing|ARM64.ActiveCfg = Fuzzing|ARM64
2320+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Fuzzing|x64.ActiveCfg = Fuzzing|x64
2321+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Fuzzing|x86.ActiveCfg = Fuzzing|Win32
2322+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Release|Any CPU.ActiveCfg = Release|x64
2323+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Release|ARM64.ActiveCfg = Release|ARM64
2324+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Release|ARM64.Build.0 = Release|ARM64
2325+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Release|x64.ActiveCfg = Release|x64
2326+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Release|x64.Build.0 = Release|x64
2327+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Release|x86.ActiveCfg = Release|Win32
2328+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F}.Release|x86.Build.0 = Release|Win32
23052329
{2C836962-9543-4CE5-B834-D28E1F124B66}.AuditMode|Any CPU.ActiveCfg = AuditMode|Win32
23062330
{2C836962-9543-4CE5-B834-D28E1F124B66}.AuditMode|ARM64.ActiveCfg = Release|ARM64
23072331
{2C836962-9543-4CE5-B834-D28E1F124B66}.AuditMode|x64.ActiveCfg = Release|x64
@@ -2455,6 +2479,7 @@ Global
24552479
{613CCB57-5FA9-48EF-80D0-6B1E319E20C4} = {A10C4720-DCA4-4640-9749-67F4314F527C}
24562480
{37C995E0-2349-4154-8E77-4A52C0C7F46D} = {A10C4720-DCA4-4640-9749-67F4314F527C}
24572481
{6515F03F-E56D-4DB4-B23D-AC4FB80DB36F} = {61901E80-E97D-4D61-A9BB-E8F2FDA8B40C}
2482+
{7615F03F-E56D-4DB4-B23D-BD4FB80DB36F} = {61901E80-E97D-4D61-A9BB-E8F2FDA8B40C}
24582483
{2C836962-9543-4CE5-B834-D28E1F124B66} = {A10C4720-DCA4-4640-9749-67F4314F527C}
24592484
{328729E9-6723-416E-9C98-951F1473BBE1} = {A10C4720-DCA4-4640-9749-67F4314F527C}
24602485
{BE92101C-04F8-48DA-99F0-E1F4F1D2DC48} = {A10C4720-DCA4-4640-9749-67F4314F527C}

0 commit comments

Comments
 (0)