Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Mar 18, 2020
1 parent 3179d82 commit 4135ac0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions cmd/nbtohtml/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type convertCmd struct {
Path string `arg name:"path" help:"Jupyter Notebook file to convert." type:"existingfile"`
Path string `kong:"arg,name='path',help='Jupyter Notebook file to convert.',type='existingfile'"`
}

var (
Expand All @@ -20,8 +20,8 @@ var (
nbtohtml is a library for converting Jupyter Notebook files to HTML.
`
cli struct {
Convert convertCmd `cmd help:"Convert Jupyter Notebook file to HTML."`
Version kong.VersionFlag `help:"Show version."`
Convert convertCmd `kong:"cmd,help='Convert Jupyter Notebook file to HTML.'"`
Version kong.VersionFlag `kong:"cmd,help='Show version.'"`
}
)

Expand Down
22 changes: 11 additions & 11 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,33 @@ func renderMarkdown(markdownLines []string) string {

// convertDataOutput converts data output (e.g. a base64-encoded plot image) to HTML.
func convertDataOutput(output Output) template.HTML {
var htmlString string
htmlString := ""

if output.Data.TextHTML != nil {
switch {
case output.Data.TextHTML != nil:
htmlString = strings.Join(output.Data.TextHTML, "")
} else if output.Data.ApplicationPDF != nil {
case output.Data.ApplicationPDF != nil:
// TODO: Implement PDF conversion
fmt.Printf("missing conversion logic for `application/pdf` data type\n")
htmlString = "<pre>PDF output</pre>"
} else if output.Data.TextLaTeX != nil {
case output.Data.TextLaTeX != nil:
// TODO: Implement LaTeX conversion
fmt.Printf("missing conversion logic for `text/latex` data type\n")
htmlString = "<pre>LaTeX output</pre>"
} else if output.Data.ImageSVGXML != nil {
case output.Data.ImageSVGXML != nil:
htmlString = strings.Join(output.Data.ImageSVGXML, "")
} else if output.Data.ImagePNG != nil {
case output.Data.ImagePNG != nil:
htmlString = fmt.Sprintf(`<img src="data:image/png;base64,%s">`, *output.Data.ImagePNG)
} else if output.Data.ImageJPEG != nil {
case output.Data.ImageJPEG != nil:
htmlString = fmt.Sprintf(`<img src="data:image/jpeg;base64,%s">`, *output.Data.ImageJPEG)
} else if output.Data.TextMarkdown != nil {
case output.Data.TextMarkdown != nil:
htmlString = renderMarkdown(output.Data.TextMarkdown)
} else if output.Data.TextPlain != nil {
case output.Data.TextPlain != nil:
htmlString = fmt.Sprintf(
`<pre>%s</pre>`,
html.EscapeString(strings.Join(output.Data.TextPlain, "")),
)
} else {
htmlString = ""
default:
fmt.Printf("missing `execute_result` data type in output of type `%s`\n", output.OutputType)
}

Expand Down
6 changes: 4 additions & 2 deletions convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ func TestConvertDataLaTeXOutput(t *testing.T) {
}

func TestConvertDataSVGOutput(t *testing.T) {
expected := template.HTML(`<svg id="star" xmlns="https://www.w3.org/2000/svg" width="255" height="240" viewBox="0 0 51 48">
expected := template.HTML(
`<svg id="star" xmlns="https://www.w3.org/2000/svg" width="255" height="240" viewBox="0 0 51 48">
<path d="M25 1l6 17h18L35 29l5 17-15-10-15 10 5-17L1 18h18z"/>
</svg>`)
</svg>`,
)
actual := convertDataOutput(testDisplayDataSVGOutput)
assert.Equal(t, expected, actual)
}
Expand Down

0 comments on commit 4135ac0

Please sign in to comment.