markup: able to display image from IPython notebook (#4366)

pull/4551/head
Unknwon 2017-06-06 15:41:27 -04:00
parent e9a2b72ddb
commit a851b77ac9
No known key found for this signature in database
GPG Key ID: 7A02C406FAC875A2
6 changed files with 19 additions and 7 deletions

View File

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/setting"
) )
const APP_VER = "0.11.16.0605" const APP_VER = "0.11.17.0606"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

View File

@ -1,6 +1,6 @@
{ {
"CodeKitInfo": "This is a CodeKit 2.x project configuration file. It is designed to sync project settings across multiple machines. MODIFYING THE CONTENTS OF THIS FILE IS A POOR LIFE DECISION. If you do so, you will likely cause CodeKit to crash. This file is not useful unless accompanied by the project that created it in CodeKit 2. This file is not backwards-compatible with CodeKit 1.x. For more information, see: http:\/\/incident57.com\/codekit", "CodeKitInfo": "This is a CodeKit 2.x project configuration file. It is designed to sync project settings across multiple machines. MODIFYING THE CONTENTS OF THIS FILE IS A POOR LIFE DECISION. If you do so, you will likely cause CodeKit to crash. This file is not useful unless accompanied by the project that created it in CodeKit 2. This file is not backwards-compatible with CodeKit 1.x. For more information, see: http:\/\/incident57.com\/codekit",
"creatorBuild": "19127", "creatorBuild": "19115",
"files": { "files": {
"\/css\/github.min.css": { "\/css\/github.min.css": {
"fileType": 16, "fileType": 16,
@ -66,7 +66,7 @@
"fileType": 32768, "fileType": 32768,
"ignore": 0, "ignore": 0,
"ignoreWasSetByUser": 0, "ignoreWasSetByUser": 0,
"initialSize": 514087, "initialSize": 4048,
"inputAbbreviatedPath": "\/img\/avatar_default.png", "inputAbbreviatedPath": "\/img\/avatar_default.png",
"outputAbbreviatedPath": "\/img\/avatar_default.png", "outputAbbreviatedPath": "\/img\/avatar_default.png",
"outputPathIsOutsideProject": 0, "outputPathIsOutsideProject": 0,

View File

@ -1402,6 +1402,9 @@ footer .ui.language .menu {
.repository.file.list #file-content #ipython-notebook .nb-cell.nb-heading-cell { .repository.file.list #file-content #ipython-notebook .nb-cell.nb-heading-cell {
margin-top: 0.5em; margin-top: 0.5em;
} }
.repository.file.list #file-content #ipython-notebook .nb-cell img {
max-width: 100%;
}
.repository.file.list #file-content #ipython-notebook .nb-raw-cell { .repository.file.list #file-content #ipython-notebook .nb-raw-cell {
white-space: pre-wrap; white-space: pre-wrap;
background-color: #f5f2f0; background-color: #f5f2f0;

View File

@ -324,6 +324,10 @@
&.nb-heading-cell { &.nb-heading-cell {
margin-top: 0.5em; margin-top: 0.5em;
} }
img {
max-width: 100%;
}
} }
.nb-raw-cell { .nb-raw-cell {
@ -370,7 +374,7 @@
font-size: 14px; font-size: 14px;
} }
img { img {
max-width: 100%; max-width: 100%;
} }
table { table {
border: 1px solid #000; border: 1px solid #000;

View File

@ -1 +1 @@
0.11.16.0605 0.11.17.0606

View File

@ -42,7 +42,6 @@
{{else if .IsIPythonNotebook}} {{else if .IsIPythonNotebook}}
<script> <script>
var rendered = null; var rendered = null;
console.log("fuck")
$.getJSON("{{.RawFileLink}}", null, function(notebook_json) { $.getJSON("{{.RawFileLink}}", null, function(notebook_json) {
var notebook = nb.parse(notebook_json); var notebook = nb.parse(notebook_json);
rendered = notebook.render(); rendered = notebook.render();
@ -52,8 +51,14 @@
hljs.highlightBlock(block); hljs.highlightBlock(block);
}); });
// Overwrite image method to append proper prefix to the source URL
var renderer = new marked.Renderer();
var context = '{{.TreeLink}}'.replace('/src/', '/raw/');
renderer.image = function (href, title, text) {
return `<img src="${context}/${href}"`
}
$("#ipython-notebook .nb-markdown-cell").each(function(i, markdown) { $("#ipython-notebook .nb-markdown-cell").each(function(i, markdown) {
$(markdown).html(marked($(markdown).html())); $(markdown).html(marked($(markdown).html(), {renderer: renderer}));
}); });
}); });
</script> </script>