IEnumerable <FilePath> Visit(MarkdownCell markdownCell) => markdownCell .ToMarkdownDocumentBlock() .AsEnumerable() .Where(e => e.IsOpening && e.Inline?.TargetUrl != null) .Select(e => GetRelativePath(e.Inline.TargetUrl)) .Where(path => !path.IsNull);
public void Append() { var doc = new WorkbookDocument(); doc.Count.ShouldEqual(0); var a = new MarkdownCell(); doc.AppendCell(a); TestEntryLinkage(doc, a, 1, a, a, null, null); var b = new MarkdownCell(); doc.AppendCell(b); TestEntryLinkage(doc, b, 2, a, b, a, null); var c = new MarkdownCell(); doc.AppendCell(c); TestEntryLinkage(doc, c, 3, a, c, b, null); var d = new MarkdownCell(); doc.AppendCell(d); TestEntryLinkage(doc, d, 4, a, d, c, null); TestEntryLinkage(doc, a, 4, a, d, null, b); TestEntryLinkage(doc, b, 4, a, d, a, c); TestEntryLinkage(doc, c, 4, a, d, b, d); TestEntryLinkage(doc, d, 4, a, d, c, null); }
public void InsertBefore() { var doc = new WorkbookDocument(); // [a] var a = new MarkdownCell(); doc.AppendCell(a); TestEntryLinkage(doc, a, 1, a, a, null, null); // [b, a] var b = new MarkdownCell(); doc.InsertCellBefore(a, b); TestEntryLinkage(doc, b, 2, b, a, null, a); // [b, c, a] var c = new MarkdownCell(); doc.InsertCellBefore(a, c); TestEntryLinkage(doc, c, 3, b, a, b, a); // [b, d, c, a] var d = new MarkdownCell(); doc.InsertCellBefore(c, d); TestEntryLinkage(doc, d, 4, b, a, b, c); // [b, d, c, a] TestEntryLinkage(doc, b, 4, b, a, null, d); TestEntryLinkage(doc, d, 4, b, a, b, c); TestEntryLinkage(doc, c, 4, b, a, d, a); TestEntryLinkage(doc, a, 4, b, a, c, null); }
public void InsertAfter() { var doc = new WorkbookDocument(); // [a] var a = new MarkdownCell(); doc.AppendCell(a); TestEntryLinkage(doc, a, 1, a, a, null, null); // [a, b] var b = new MarkdownCell(); doc.InsertCellAfter(a, b); TestEntryLinkage(doc, b, 2, a, b, a, null); // [a, c, b] var c = new MarkdownCell(); doc.InsertCellAfter(a, c); TestEntryLinkage(doc, c, 3, a, b, a, b); // [a, c, d, b] var d = new MarkdownCell(); doc.InsertCellAfter(c, d); TestEntryLinkage(doc, d, 4, a, b, c, b); // [a, c, d, b] TestEntryLinkage(doc, a, 4, a, b, null, c); TestEntryLinkage(doc, c, 4, a, b, a, d); TestEntryLinkage(doc, d, 4, a, b, c, b); TestEntryLinkage(doc, b, 4, a, b, d, null); }
public static string ToHtml(this BaseCell cell) { return(cell switch { CodeCell codeCell => convertCodeToHtml(codeCell), MarkdownCell mdCell => convertMarkdownToHtml(mdCell), RawCell rwCell => convertRawToHtml(rwCell), _ => throw new NotSupportedException(), });
protected override void BindMarkdownCellToView(MarkdownCell cell) { var view = new MarkdownCellView(cell, webView.Document); if (!string.IsNullOrEmpty(cell.Buffer.Value)) { view.MarkdownContent = cell.Buffer.Value; } cell.View = view; }
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); }
public ProseMirrorEditor(MarkdownCell markdownCell, HtmlElement editorElem) { Cell = markdownCell ?? throw new ArgumentNullException(nameof(markdownCell)); ContentElement = editorElem ?? throw new ArgumentNullException(nameof(editorElem)); UpdateTheme(); var jsContext = editorElem.Context; var jsGlobal = jsContext.GlobalObject; proseMirror = jsGlobal.xiexports.WorkbookEditor(jsContext.CreateObject(o => { o.placeElem = editorElem; o.onFocus = (ScriptAction)HandleFocus; o.onChange = (ScriptAction)HandleChange; o.onCursorUpDown = (ScriptFunc)HandleCursorUpDown; o.onModEnter = (ScriptAction)HandleModEnter; })); proseMirror.setMenuStyle("tooltip"); }
protected override void BindMarkdownCellToView(MarkdownCell cell) => cell.View = new ConsoleCellView(cell, output);
public void Remove() { var doc = new WorkbookDocument(); var a = new MarkdownCell(); doc.AppendCell(a); doc.Count.ShouldEqual(1); doc.RemoveCell(a); doc.Count.ShouldEqual(0); a.NextCell.ShouldBeNull(); a.PreviousCell.ShouldBeNull(); doc.FirstCell.ShouldBeNull(); doc.LastCell.ShouldBeNull(); var b = new MarkdownCell(); doc.AppendCell(a); doc.AppendCell(b); doc.FirstCell.ShouldEqual(a); doc.LastCell.ShouldEqual(b); a.NextCell.ShouldEqual(b); a.PreviousCell.ShouldBeNull(); b.NextCell.ShouldBeNull(); b.PreviousCell.ShouldEqual(a); doc.RemoveCell(b); doc.Count.ShouldEqual(1); doc.FirstCell.ShouldEqual(a); doc.LastCell.ShouldEqual(a); b.NextCell.ShouldBeNull(); b.PreviousCell.ShouldBeNull(); a.NextCell.ShouldBeNull(); a.PreviousCell.ShouldBeNull(); doc.RemoveCell(a); var c = new MarkdownCell(); doc.AppendCell(a); doc.AppendCell(b); doc.AppendCell(c); doc.FirstCell.ShouldEqual(a); doc.LastCell.ShouldEqual(c); a.NextCell.ShouldEqual(b); a.PreviousCell.ShouldBeNull(); b.NextCell.ShouldEqual(c); b.PreviousCell.ShouldEqual(a); c.NextCell.ShouldBeNull(); c.PreviousCell.ShouldEqual(b); doc.RemoveCell(b); doc.FirstCell.ShouldEqual(a); doc.LastCell.ShouldEqual(c); a.NextCell.ShouldEqual(c); a.PreviousCell.ShouldBeNull(); b.NextCell.ShouldBeNull(); b.PreviousCell.ShouldBeNull(); c.NextCell.ShouldBeNull(); c.PreviousCell.ShouldEqual(a); }