Skip to content

Commit

Permalink
fix: remove \n before input- and output- prompt text (#6)
Browse files Browse the repository at this point in the history
Input- and output- prompts are the "In [3]:" and "Out [3]:" bits
next to code cells and code cell outputs.

In general: added a way to control if a newline should be added
after a tag or not. This is a dirty solution, but that's its only
real drawback at the moment.

v0.3.0 will ship with a decent rewrite of the HTML/CSS logic,
so I am going to postpone implementing a better solution until then.
  • Loading branch information
bevzzz authored Jan 26, 2024
1 parent d7249bd commit b138fc5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 57 deletions.
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.

0 comments on commit b138fc5

Please sign in to comment.