private async Task <AutoEnableOptions> GetAutoEnableOptions(MarkdownFile file)
        {
            bool useWasmRunner;

            if (_startupOptions.Package != null)
            {
                var package = await _packageRegistry.Get <Package2>(_startupOptions.Package);

                useWasmRunner = package.CanSupportWasm;
            }
            else
            {
                var blocks = await file.GetAnnotatedCodeBlocks();

                var packageUsesWasm = await Task.WhenAll(blocks
                                                         .Select(b => b.PackageName())
                                                         .Select(async name => (await _packageRegistry.Get <ICanSupportWasm>(name))?.CanSupportWasm ?? false));

                useWasmRunner = packageUsesWasm.Any(p => p);
            }

            var requestUri = Request.GetUri();

            var hostUrl = $"{requestUri.Scheme}://{requestUri.Authority}";

            return(new AutoEnableOptions(hostUrl, useWasmRunner));
        }
예제 #2
0
        public static async Task <IHtmlContent> SessionControlsHtml(MarkdownFile markdownFile, bool enablePreviewFeatures = false)
        {
            var sessions = (await markdownFile
                            .GetAnnotatedCodeBlocks())
                           .GroupBy(b => b.Annotations.Session);

            var sb = new StringBuilder();

            foreach (var session in sessions)
            {
                sb.AppendLine($@"<button class=""run"" data-trydotnet-mode=""run"" data-trydotnet-session-id=""{session.Key}"" data-trydotnet-run-args=""{session.First().Annotations.RunArgs.HtmlAttributeEncode()}"">{session.Key}{SvgResources.RunButtonSvg}</button>");

                sb.AppendLine(enablePreviewFeatures
                    ? $@"<div class=""output-panel"" data-trydotnet-mode=""runResult"" data-trydotnet-output-type=""terminal"" data-trydotnet-session-id=""{session.Key}""></div>"
                    : $@"<div class=""output-panel"" data-trydotnet-mode=""runResult"" data-trydotnet-session-id=""{session.Key}""></div>");
            }

            return(new HtmlString(sb.ToString()));
        }