Exemplo n.º 1
0
        public CodeCellView(
            Models.CodeCellState codeCellState,
            CodeCell codeCell,
            HtmlDocument document,
            RendererContext rendererContext) : base(
                document,
                "submission " + codeCell.LanguageName)
        {
            this.codeCell = codeCell
                            ?? throw new ArgumentNullException(nameof(codeCell));

            this.rendererContext = rendererContext
                                   ?? throw new ArgumentNullException(nameof(rendererContext));

            ContentElement.AppendChild(editorElem = CreateContentContainer("editor"));

            editor = new CodeCellEditorView(codeCellState, codeCell, editorElem);

            PreferenceStore.Default.Subscribe(change => {
                if (change.Key == Prefs.Submissions.ShowExecutionTimings.Key)
                {
                    UpdateEvaluationDurationHidden();
                }
            });
        }
Exemplo n.º 2
0
        public void RenderCapturedOutputSegment(CapturedOutputSegment segment)
        {
            if (capturedOutputElem == null)
            {
                ContentElement.AppendChild(
                    capturedOutputElem = CreateContentContainer("captured-output"));
            }

            var span = Document.CreateElement("span",
                                              @class: segment.FileDescriptor == CapturedOutputWriter.StandardErrorFd
                ? "stderr"
                : "stdout");

            var builder = new StringBuilder();

            for (var i = 0; i < segment.Value.Length; i++)
            {
                string escaped;
                var    c = segment.Value [i];
                if (c.TryHtmlEscape(out escaped, true))
                {
                    builder.Append(escaped);
                }
                else
                {
                    builder.Append(c);
                }
            }

            span.InnerHTML = builder.ToString();

            capturedOutputElem.AppendChild(span);
        }
Exemplo n.º 3
0
        public MarkdownCellView(MarkdownCell markdownCell, HtmlDocument document)
            : base(document, "text")
        {
            var editorContainerElem = CreateContentContainer(null);

            ContentElement.AppendChild(editorContainerElem);

            editorElem = Document.CreateElement("div");
            editorContainerElem.AppendChild(editorElem);

            editor = new ProseMirrorEditor(markdownCell, editorElem);
        }
Exemplo n.º 4
0
        public void RenderDiagnostic(InteractiveDiagnostic diagnostic)
        {
            if (diagnosticsElem == null)
            {
                diagnosticsElem = CreateContentContainer("diagnostics");
                if (HasErrorDiagnostics)
                {
                    diagnosticsElem.AddCssClass("error");
                }
                ContentElement.AppendChild(diagnosticsElem);
            }

            var displayMessage = new StringBuilder();
            var position       = diagnostic.Span.StartLinePosition;
            var severity       = diagnostic.Severity.ToString().ToLowerInvariant();

            var listElem = diagnosticsElem.FirstElementChild;

            if (listElem == null)
            {
                diagnosticsElem.AppendChild(listElem = Document.CreateElement("ul"));
            }

            var itemElement = Document.CreateElement("li", @class: severity);

            if (diagnostic.Span.IsValid)
            {
                displayMessage.Append($"({position.Line + 1},{position.Character + 1}): ");
                itemElement.AddEventListener("click", evnt => {
                    if (!WindowHasSelection)
                    {
                        editor.Focus();
                        editor.CursorPosition = position;
                    }
                });
            }

            displayMessage.Append(severity);

            if (!String.IsNullOrEmpty(diagnostic.Id))
            {
                displayMessage.Append(' ').Append(diagnostic.Id);
            }

            displayMessage.Append(": ").Append(diagnostic.Message);

            itemElement.AppendChild(Document.CreateTextNode(displayMessage.ToString()));
            listElem.AppendChild(itemElement);
        }
Exemplo n.º 5
0
        public void RenderResult(
            CultureInfo cultureInfo,
            object result,
            EvaluationResultHandling resultHandling)
        {
            if (resultElem == null)
            {
                ContentElement.AppendChild(resultElem = CreateContentContainer("result"));
            }
            else if (resultHandling == EvaluationResultHandling.Replace)
            {
                resultElem.RemoveChildren();
            }

            rendererContext.Render(
                RenderState.Create(result, cultureInfo),
                resultElem);
        }