mirror of
https://github.com/go-gitea/gitea.git
synced 2026-06-15 20:25:18 +02:00
chore: center info message for unsupported jupyter notebook versions (#38114)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ package jupyter
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -150,10 +151,8 @@ func (renderer) Render(ctx *markup.RenderContext, input io.Reader, outputWriter
|
|||||||
|
|
||||||
// Check nbformat version
|
// Check nbformat version
|
||||||
if notebook.Nbformat < 4 {
|
if notebook.Nbformat < 4 {
|
||||||
htmlWriter.WriteFormat(
|
msg := htmlutil.HTMLFormat("This notebook uses an older format (nbformat %d). Only nbformat 4+ is supported for rendering. Please upgrade the notebook in Jupyter or view the raw JSON.", notebook.Nbformat)
|
||||||
`<div class="ui info message">This notebook uses an older format (nbformat %d). Only nbformat 4+ is supported for rendering. Please upgrade the notebook in Jupyter or view the raw JSON.</div>`,
|
htmlWriter.WriteFormat(`<div class="file-not-rendered-prompt">%s</div>`, msg)
|
||||||
notebook.Nbformat,
|
|
||||||
)
|
|
||||||
return htmlWriter.Err()
|
return htmlWriter.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,9 +189,7 @@ func (renderer) Render(ctx *markup.RenderContext, input io.Reader, outputWriter
|
|||||||
}
|
}
|
||||||
|
|
||||||
if truncated {
|
if truncated {
|
||||||
htmlWriter.WriteHTML(`<div class="ui warning message">`)
|
renderCellPrompt(htmlWriter, "Warning:", "Output truncated. This notebook contains too many cells to display efficiently.")
|
||||||
htmlWriter.WriteHTML(`<strong>Output truncated.</strong> This notebook contains too many cells to display efficiently.`)
|
|
||||||
htmlWriter.WriteHTML(`</div>`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
htmlWriter.WriteHTML(`</div>`)
|
htmlWriter.WriteHTML(`</div>`)
|
||||||
@@ -254,6 +251,16 @@ func renderCellCode(output htmlutil.HTMLWriter, cell Cell, language string) erro
|
|||||||
return output.Err()
|
return output.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renderCellPrompt(output htmlutil.HTMLWriter, left, right template.HTML) {
|
||||||
|
output.WriteFormat(`
|
||||||
|
<div class="notebook-cell">
|
||||||
|
<div class="cell-line">
|
||||||
|
<div class="cell-left cell-prompt">%s</div>
|
||||||
|
<div class="cell-right cell-prompt">%s</div>
|
||||||
|
</div>
|
||||||
|
</div>`, left, right)
|
||||||
|
}
|
||||||
|
|
||||||
func renderCell(ctx *markup.RenderContext, output htmlutil.HTMLWriter, cell Cell, language string) error {
|
func renderCell(ctx *markup.RenderContext, output htmlutil.HTMLWriter, cell Cell, language string) error {
|
||||||
switch cell.CellType {
|
switch cell.CellType {
|
||||||
case "markdown":
|
case "markdown":
|
||||||
@@ -265,7 +272,10 @@ func renderCell(ctx *markup.RenderContext, output htmlutil.HTMLWriter, cell Cell
|
|||||||
if err := renderCellMarkdown(ctx, output, joinSource(cell.Source)); err != nil {
|
if err := renderCellMarkdown(ctx, output, joinSource(cell.Source)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
output.WriteHTML(`</div></div></div>`)
|
output.WriteHTML(`
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`)
|
||||||
case "code":
|
case "code":
|
||||||
output.WriteHTML(`<div class="notebook-cell cell-type-code">`)
|
output.WriteHTML(`<div class="notebook-cell cell-type-code">`)
|
||||||
if err := renderCellCode(output, cell, language); err != nil {
|
if err := renderCellCode(output, cell, language); err != nil {
|
||||||
@@ -273,13 +283,7 @@ func renderCell(ctx *markup.RenderContext, output htmlutil.HTMLWriter, cell Cell
|
|||||||
}
|
}
|
||||||
output.WriteHTML(`</div>`)
|
output.WriteHTML(`</div>`)
|
||||||
default:
|
default:
|
||||||
output.WriteFormat(`
|
renderCellPrompt(output, "Cell:", htmlutil.HTMLFormat("[Cell type %s - unsupported, skipped]", cell.CellType))
|
||||||
<div class="notebook-cell">
|
|
||||||
<div class="cell-line">
|
|
||||||
<div class="cell-left cell-prompt">Cell:</div>
|
|
||||||
<div class="cell-right cell-prompt">[Cell type %s - unsupported, skipped]</div>
|
|
||||||
</div>
|
|
||||||
</div>`, cell.CellType)
|
|
||||||
}
|
}
|
||||||
return output.Err()
|
return output.Err()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ func TestRender(t *testing.T) {
|
|||||||
err := r.Render(ctx, strings.NewReader(input), &output)
|
err := r.Render(ctx, strings.NewReader(input), &output)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Regexp(t, `<div class="ui info message">This notebook uses an older format.*</div>`, output.String())
|
assert.Regexp(t, `<div class="file-not-rendered-prompt">This notebook uses an older format.*</div>`, output.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</h4>
|
</h4>
|
||||||
<div class="ui bottom attached table unstackable segment">
|
<div class="ui bottom attached segment file-view-container">
|
||||||
<div class="file-view code-view unicode-escaped">
|
<div class="file-view code-view unicode-escaped">
|
||||||
{{if .IsFileTooLarge}}
|
{{if .IsFileTooLarge}}
|
||||||
{{template "shared/filetoolarge" dict "RawFileLink" .RawFileLink}}
|
{{template "shared/filetoolarge" dict "RawFileLink" .RawFileLink}}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<a class="ui primary tiny button" href="{{.LFSFilesLink}}/find?oid={{.LFSFile.Oid}}&size={{.LFSFile.Size}}">{{ctx.Locale.Tr "repo.settings.lfs_findcommits"}}</a>
|
<a class="ui primary tiny button" href="{{.LFSFilesLink}}/find?oid={{.LFSFile.Oid}}&size={{.LFSFile.Size}}">{{ctx.Locale.Tr "repo.settings.lfs_findcommits"}}</a>
|
||||||
</div>
|
</div>
|
||||||
</h4>
|
</h4>
|
||||||
<div class="ui bottom attached table unstackable segment">
|
<div class="ui bottom attached segment file-view-container">
|
||||||
{{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus "root" $}}
|
{{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus "root" $}}
|
||||||
<div class="file-view {{if .IsPlainText}}plain-text{{else if .IsTextFile}}code-view{{end}}">
|
<div class="file-view {{if .IsPlainText}}plain-text{{else if .IsTextFile}}code-view{{end}}">
|
||||||
{{if .IsFileTooLarge}}
|
{{if .IsFileTooLarge}}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<div class="ui bottom attached table unstackable segment">
|
<div class="ui bottom attached segment file-view-container">
|
||||||
{{if not .RenderAsMarkup}}
|
{{if not .RenderAsMarkup}}
|
||||||
{{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus}}
|
{{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
.file-view-container {
|
||||||
|
padding: 0 !important; /* the file-view itself provides padding */
|
||||||
|
width: 100% !important; /* override fomantic's "100% + 2px" */
|
||||||
|
max-width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
.file-view tr.active .lines-num,
|
.file-view tr.active .lines-num,
|
||||||
.file-view tr.active .lines-escape,
|
.file-view tr.active .lines-escape,
|
||||||
.file-view tr.active .lines-code {
|
.file-view tr.active .lines-code {
|
||||||
|
|||||||
Reference in New Issue
Block a user