Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove newlines before input-prompt text #6

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions render/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (r *Renderer) renderCode(w io.Writer, cell schema.Cell) error {
return nil
}

div.Open(w, attributes{"class": {"cm-editor", "cm-s-jupyter"}})
div.Open(w, attributes{"class": {"highlight", "hl-ipython3"}})
div.Open(w, attributes{"class": {"cm-editor", "cm-s-jupyter"}}, true)
div.Open(w, attributes{"class": {"highlight", "hl-ipython3"}}, true)

io.WriteString(w, "<pre><code class=\"language-") // TODO: not sure if that's useful here
io.WriteString(w, code.Language())
Expand Down
30 changes: 15 additions & 15 deletions render/html/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (wr *Wrapper) Wrap(w io.Writer, cell schema.Cell, render render.RenderCellF
ct = "jp-RawCell"
}

div.Open(w, attributes{"class": {"jp-Cell", ct, "jp-Notebook-cell"}})
div.Open(w, attributes{"class": {"jp-Cell", ct, "jp-Notebook-cell"}}, true)
render(w, cell)
div.Close(w)
return nil
Expand All @@ -50,19 +50,19 @@ func (wr *Wrapper) Wrap(w io.Writer, cell schema.Cell, render render.RenderCellF
func (wr *Wrapper) WrapInput(w io.Writer, cell schema.Cell, render render.RenderCellFunc) error {
div.Open(w, attributes{
"class": {"jp-Cell-inputWrapper"},
"tabindex": {0}})
"tabindex": {0}}, true)

div.Open(w, attributes{"class": {"jp-Collapser", "jp-InputCollapser", "jp-Cell-inputCollapser"}})
div.Open(w, attributes{"class": {"jp-Collapser", "jp-InputCollapser", "jp-Cell-inputCollapser"}}, true)
io.WriteString(w, " ")
div.Close(w)

// TODO: add collapser-child <div class="jp-Collapser-child"></div> and collapsing functionality
// Pure CSS Collapsible: https://www.digitalocean.com/community/tutorials/css-collapsible

div.Open(w, attributes{"class": {"jp-InputArea", "jp-Cell-inputArea"}})
div.Open(w, attributes{"class": {"jp-InputArea", "jp-Cell-inputArea"}}, true)

// Prompt In:[1]
div.Open(w, attributes{"class": {"jp-InputPrompt", "jp-InputArea-prompt"}})
div.Open(w, attributes{"class": {"jp-InputPrompt", "jp-InputArea-prompt"}}, false)
if ex, ok := cell.(interface{ ExecutionCount() int }); ok {
fmt.Fprintf(w, "In\u00a0[%d]:", ex.ExecutionCount())
}
Expand All @@ -78,7 +78,7 @@ func (wr *Wrapper) WrapInput(w io.Writer, cell schema.Cell, render render.Render
"jp-InputArea-editor",
},
"data-type": {"inline"},
})
}, true)
} else if isMd {
div.Open(w, attributes{
"class": {
Expand All @@ -87,7 +87,7 @@ func (wr *Wrapper) WrapInput(w io.Writer, cell schema.Cell, render render.Render
"jp-RenderedHTMLCommon",
},
"data-mime-type": {common.MarkdownText},
})
}, true)
}

// Cell itself
Expand All @@ -103,9 +103,9 @@ func (wr *Wrapper) WrapInput(w io.Writer, cell schema.Cell, render render.Render
}

func (wr *Wrapper) WrapOutput(w io.Writer, cell schema.Outputter, render render.RenderCellFunc) error {
div.Open(w, attributes{"class": {"jp-Cell-outputWrapper"}})
div.Open(w, attributes{"class": {"jp-Cell-outputWrapper"}}, true)
div.OpenClose(w, attributes{"class": {"jp-Collapser", "jp-OutputCollapser", "jp-Cell-outputCollapser"}})
div.Open(w, attributes{"class": {"jp-OutputArea jp-Cell-outputArea"}})
div.Open(w, attributes{"class": {"jp-OutputArea jp-Cell-outputArea"}}, true)

// TODO: see how application/json would be handled
// TODO: jp-RenderedJavaScript is a thing and so is jp-RenderedLatex (but I don't think we need to do anything about the latter)
Expand Down Expand Up @@ -147,10 +147,10 @@ func (wr *Wrapper) WrapOutput(w io.Writer, cell schema.Outputter, render render.

// Looks like this will always wrap the whole output area!
if child {
div.Open(w, attributes{"class": {childClass}})
div.Open(w, attributes{"class": {childClass}}, true)
}

div.Open(w, attributes{"class": {"jp-OutputPrompt", "jp-OutputArea-prompt"}})
div.Open(w, attributes{"class": {"jp-OutputPrompt", "jp-OutputArea-prompt"}}, false)
for _, out := range cell.Outputs() {
if ex, ok := out.(interface{ ExecutionCount() int }); ok {
fmt.Fprintf(w, "Out\u00a0[%d]:", ex.ExecutionCount())
Expand All @@ -162,7 +162,7 @@ func (wr *Wrapper) WrapOutput(w io.Writer, cell schema.Outputter, render render.
div.Open(w, attributes{
"class": {renderedClass, "jp-OutputArea-output", outputtypeclass},
"data-mime-type": {datamimetype},
})
}, true)
for _, out := range cell.Outputs() {
_ = render(w, out)
}
Expand All @@ -184,8 +184,8 @@ const (
type tag string

// Open the tag with the attributes, e.g. <div class="container" checked>.
func (t tag) Open(w io.Writer, attrs attributes) {
t._open(w, attrs, true)
func (t tag) Open(w io.Writer, attrs attributes, newline bool) {
t._open(w, attrs, newline)
}

func (t tag) _open(w io.Writer, attrs attributes, newline bool) {
Expand Down Expand Up @@ -221,7 +221,7 @@ type tagger struct {

// Open opens the tag with the attributes.
func (t *tagger) Open(tag tag, w io.Writer, attr attributes) {
tag.Open(w, attr)
tag.Open(w, attr, true) // TODO: redo
t.opened = append(t.opened, tag)
}

Expand Down
60 changes: 20 additions & 40 deletions testdata/notebook.golden

Large diffs are not rendered by default.

Loading