Skip to content

Commit

Permalink
Fixed behavior of the note view
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Oct 21, 2021
1 parent 005a7c7 commit 4539039
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 127 deletions.
Binary file modified .rizin-notebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 90 additions & 90 deletions assets.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/templates/markdown-edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
autofocus: true,
hideIcons: ["side-by-side", "fullscreen", "guide"],
autosave: { enabled: false },
spellChecker: false,
forceSync: true,
indentWithTabs: false,
promptURLs: true,
Expand Down
24 changes: 20 additions & 4 deletions assets/templates/markdown-view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,31 @@
<style type="text/css">
html, body { width: 100%; height: 100%; margin: 0 }
.button-edit { float: right; width: 60px ! important; margin-top: 5px; }
.markdown-container { margin-top: 9px; white-space: pre; line-height: 0px; }
.markdown-container { margin-top: 9px; }
</style>
</head>
<body>
<body onload="view()">
<a class="btn btn-action spacing-left button-edit" href="{{ .root }}markdown/edit{{ .path }}">
<i class="icon icon-edit">Code</i> Edit
</a>
<div class="markdown-container">
{{ .html | raw}}
<div class="markdown-container" id="markdown-container" >
<textarea style="display: none;" name="md-container" id="md-container" cols="30" rows="10">{{ .html }}</textarea>
</div>
<script src="{{ .root }}static/simplemde.min.js"></script>
<script>
function view() {
var smde = new SimpleMDE({
element: document.getElementById('md-container'),
autoDownloadFontAwesome: false,
spellChecker: false,
status: false,
indentWithTabs: false,
promptURLs: true,
tabSize: 4,
});
var md = smde.value();
document.getElementById('markdown-container').innerHTML = smde.markdown(md);
};
</script>
</body>
</html>
31 changes: 19 additions & 12 deletions assets/templates/page-view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
if (obj.contentWindow.location.href.indexOf("/deleted") > 0) {
obj.parentNode.parentNode.removeChild(obj.parentNode);
}
window.scrollTo(0, document.body.scrollHeight);
}
function output(obj) {
obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + 'px';
Expand All @@ -36,6 +37,7 @@
} else if (obj.contentWindow.location.href.indexOf("/loaded") > 0) {
location.reload()
}
window.scrollTo(0, document.body.scrollHeight);
}
function newmd() {
var body = document.getElementById("page-body");
Expand Down Expand Up @@ -78,13 +80,10 @@
event.preventDefault();
}
}
function syntax(elem, id) {
console.log(elem, id);
}
</script>
</head>
<body>
<section class="container mt-10">
<section class="container grid-960 mt-10">
<header class="navbar navbar-fixed-height">
<section class="navbar-section">
<img src="{{ $root }}static/logo.png" width="30" height="30" />&nbsp;
Expand All @@ -102,16 +101,24 @@
</header>
<section class="container">
<div class="columns">
<div class="column" id="page-body">
<div class="column">
<div class="input-group spacing-top">
<code class="input-group-addon spacing-right">File: {{ $page.filename }}</code>
</div>
{{ range $i, $line := $page.lines }}
{{ if eq $line.type "markdown" }}
</div>
</div>
</section>
</section>
<section class="container mt-10">
<section class="container">
<div class="columns">
<div class="column" style="padding-top: 0px" id="page-body">
{{ range $i, $line := $page.lines }}
{{ if eq $line.type "markdown" }}
<div class="panel spacing-top resizer">
<iframe frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="no" onload="handle(this)" onunload="handle(this)" class="panel-body no-borders md-heigh" src="{{ $root }}markdown/view/{{ $page.unique }}/{{ $line.unique }}"></iframe>
</div>
{{ else }}
{{ else }}
<div class="input-group spacing-top">
<code class="input-group-addon spacing-right spacing-left">{{ $line.command }}</code>
<a class="btn float-right" href="{{ $root }}output/delete/{{ $page.unique }}/{{ $line.unique }}" onclick="confirm_delete(event)">
Expand All @@ -121,14 +128,14 @@
<div class="input-group spacing-top">
<iframe id="output-{{ $i }}" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="no" onload="handle(this)" class="input-group-addon spacing-left md-heigh" src="{{ $root }}output/view/{{ $page.unique }}/{{ $line.unique }}"></iframe>
</div>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
<div class="input-group spacing-top" style="margin-top: 10px;">
<a class="btn" href="#" onclick="newmd()"><i class="icon icon-message">Markdown</i> Markdown</a>
{{ if $pipe }}
{{ if $pipe }}
&nbsp;
<a class="btn" href="#" onclick="newcm()"><i class="icon icon-resize-horiz">Command Line</i> Command Line</a>
{{ end }}
{{ end }}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion assets/templates/reload.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
border-top-color:transparent;
}
</style>
<meta http-equiv="refresh" content="5"/>
<meta http-equiv="refresh" content="2"/>
</head>
<body>
<div class="center">
Expand Down
8 changes: 4 additions & 4 deletions pipe_html.go → output.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ var col256 = regexp.MustCompile(`^\[([34]8);5;(\d+)m`)
var colrgb = regexp.MustCompile(`^\[([34]8);2;(\d+);(\d+);(\d+)m`)
var escape = regexp.MustCompile(`^\[(\d+;)?(\d+;)?(\d+;)?(\d+;)?(\d+)([A-Za-z])`)

func _toHtml(raw string) string {
var output = strings.TrimSuffix(raw, "\x00")
func toHtml(raw []byte) []byte {
var output = strings.TrimSuffix(string(raw), "\x00")
output = strings.ReplaceAll(output, "\r", "")
output = strings.Trim(output, "\n")
if output == "" {
return output
return []byte{}
}
output = strings.ReplaceAll(output, "&", "&amp;")
output = strings.ReplaceAll(output, "<", "&lt;")
Expand Down Expand Up @@ -449,5 +449,5 @@ func _toHtml(raw string) string {
}
}
html = strings.ReplaceAll(html, "\n", "<br>\n")
return html
return []byte(html)
}
2 changes: 1 addition & 1 deletion pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *Rizin) exec(cmd string) (string, error) {
fmt.Println("pipe error:", err)
return "", err
}
return _toHtml(buf), nil
return buf, nil
}

func (r *Rizin) close() {
Expand Down
8 changes: 8 additions & 0 deletions server_assets.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"html/template"
Expand All @@ -14,6 +15,13 @@ var functionMap = template.FuncMap{
"raw": func(b []byte) template.HTML {
return template.HTML(b)
},
"stringify": func(input interface{}) string {
buffer, err := json.Marshal(input)
if err != nil {
return `""`
}
return string(buffer)
},
"keycombo": func(input string) string {
if len(input) > 0 {
return strings.Replace(input, ",", " + ", -1)
Expand Down
4 changes: 1 addition & 3 deletions server_markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"github.com/gin-gonic/gin"
"gopkg.in/russross/blackfriday.v2"
"strings"
)

Expand All @@ -20,10 +19,9 @@ func serverAddMarkdown(markdown *gin.RouterGroup) {
if err != nil {
c.String(404, "file not found")
} else {
html := blackfriday.Run(bytes)
c.HTML(200, "markdown-view.tmpl", gin.H{
"root": webroot,
"html": html,
"html": string(bytes),
"path": "/" + tokens[0] + "/" + tokens[1],
})
}
Expand Down
23 changes: 11 additions & 12 deletions server_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,24 @@ func serverAddOutput(output *gin.RouterGroup) {
return
}

eunique := notebook.newcmd(unique, command)
if len(eunique) < 1 {
section := notebook.newcmd(unique, command)
if len(section) < 1 {
c.HTML(400, "console-error.tmpl", gin.H{
"error": "cannot create eunique for output.",
"error": "cannot create section for output.",
"root": webroot,
})
return
}

go func(unique, eunique, command string, rizin *Rizin) {
go func(unique, name, command string, rizin *Rizin) {
output, err := rizin.exec(command)
if len(strings.TrimSpace(output)) < 1 && err == nil {
output = "no output from rizin."
} else if err != nil {
if err != nil {
output = fmt.Sprintf("pipe error: %v", err)
}
notebook.save([]byte(output), unique, eunique+".out")
}(unique, eunique, command, rizin)
notebook.save([]byte(output), unique, name+".out")
}(unique, section, command, rizin)

c.Redirect(302, webroot+"output/check/"+unique+"/"+eunique)
c.Redirect(302, webroot+"output/check/"+unique+"/"+section)
})
output.GET("/check/*path", func(c *gin.Context) {
tokens := strings.Split(c.Param("path")[1:], "/")
Expand Down Expand Up @@ -98,12 +96,13 @@ func serverAddOutput(output *gin.RouterGroup) {
if err != nil {
c.HTML(404, "output.tmpl", gin.H{
"root": webroot,
"output": []byte("file not found"),
"output": []byte("missing output file"),
})
} else {
output := toHtml(bytes)
c.HTML(200, "output.tmpl", gin.H{
"root": webroot,
"output": bytes,
"output": output,
})
}
}
Expand Down

0 comments on commit 4539039

Please sign in to comment.