@@ -5,6 +5,7 @@ import 'package:markdown/markdown.dart' as md;
55final markdownInput = querySelector ('#markdown' ) as TextAreaElement ;
66final htmlDiv = querySelector ('#html' ) as DivElement ;
77final versionSpan = querySelector ('.version' ) as SpanElement ;
8+
89final nullSanitizer = new NullTreeSanitizer ();
910const typing = const Duration (milliseconds: 150 );
1011final introText = r'''Markdown is the **best**!
@@ -13,6 +14,18 @@ final introText = r'''Markdown is the **best**!
1314* It has [links](http://dartlang.org).
1415* It has _so much more_...''' ;
1516
17+ // Flavor support.
18+ final basicRadio = querySelector ('#basic-radio' ) as HtmlElement ;
19+ final commonmarkRadio = querySelector ('#commonmark-radio' ) as HtmlElement ;
20+ final gfmRadio = querySelector ('#gfm-radio' ) as HtmlElement ;
21+ md.ExtensionSet extensionSet;
22+
23+ final extensionSets = {
24+ 'basic-radio' : md.ExtensionSet .none,
25+ 'commonmark-radio' : md.ExtensionSet .commonMark,
26+ 'gfm-radio' : md.ExtensionSet .gitHub,
27+ };
28+
1629void main () {
1730 versionSpan.text = 'v${md .version }' ;
1831 markdownInput.onKeyUp.listen (_renderMarkdown);
@@ -28,11 +41,21 @@ void main() {
2841 } else {
2942 _typeItOut (introText, 82 );
3043 }
44+
45+ // GitHub is the default extension set.
46+ gfmRadio.attributes['checked' ] = '' ;
47+ gfmRadio.querySelector ('.glyph' ).text = 'radio_button_checked' ;
48+ extensionSet = extensionSets[gfmRadio.id];
49+ _renderMarkdown ();
50+
51+ basicRadio.onClick.listen (_switchFlavor);
52+ commonmarkRadio.onClick.listen (_switchFlavor);
53+ gfmRadio.onClick.listen (_switchFlavor);
3154}
3255
3356void _renderMarkdown ([Event event]) {
3457 var markdown = markdownInput.value;
35- htmlDiv.setInnerHtml (md.markdownToHtml (markdown),
58+ htmlDiv.setInnerHtml (md.markdownToHtml (markdown, extensionSet : extensionSet ),
3659 treeSanitizer: nullSanitizer);
3760 if (event != null ) {
3861 // Not simulated typing. Store it.
@@ -59,6 +82,29 @@ void _typeItOut(String msg, int pos) {
5982 timer = new Timer (typing, addCharacter);
6083}
6184
85+ void _switchFlavor (Event e) {
86+ var target = e.currentTarget;
87+ if (! target.attributes.containsKey ('checked' )) {
88+ if (basicRadio != target) {
89+ basicRadio.attributes.remove ('checked' );
90+ basicRadio.querySelector ('.glyph' ).text = 'radio_button_unchecked' ;
91+ }
92+ if (commonmarkRadio != target) {
93+ commonmarkRadio.attributes.remove ('checked' );
94+ commonmarkRadio.querySelector ('.glyph' ).text = 'radio_button_unchecked' ;
95+ }
96+ if (gfmRadio != target) {
97+ gfmRadio.attributes.remove ('checked' );
98+ gfmRadio.querySelector ('.glyph' ).text = 'radio_button_unchecked' ;
99+ }
100+
101+ target.attributes['checked' ] = '' ;
102+ target.querySelector ('.glyph' ).text = 'radio_button_checked' ;
103+ extensionSet = extensionSets[target.id];
104+ _renderMarkdown ();
105+ }
106+ }
107+
62108class NullTreeSanitizer implements NodeTreeSanitizer {
63109 void sanitizeTree (Node node) {}
64110}
0 commit comments