Skip to content

Commit 4539039

Browse files
committed
Fixed behavior of the note view
1 parent 005a7c7 commit 4539039

File tree

11 files changed

+156
-127
lines changed

11 files changed

+156
-127
lines changed

.rizin-notebook.png

-52.7 KB
Loading

assets.go

Lines changed: 90 additions & 90 deletions
Large diffs are not rendered by default.

assets/templates/markdown-edit.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
autofocus: true,
3535
hideIcons: ["side-by-side", "fullscreen", "guide"],
3636
autosave: { enabled: false },
37+
spellChecker: false,
3738
forceSync: true,
3839
indentWithTabs: false,
3940
promptURLs: true,

assets/templates/markdown-view.tmpl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,31 @@
99
<style type="text/css">
1010
html, body { width: 100%; height: 100%; margin: 0 }
1111
.button-edit { float: right; width: 60px ! important; margin-top: 5px; }
12-
.markdown-container { margin-top: 9px; white-space: pre; line-height: 0px; }
12+
.markdown-container { margin-top: 9px; }
1313
</style>
1414
</head>
15-
<body>
15+
<body onload="view()">
1616
<a class="btn btn-action spacing-left button-edit" href="{{ .root }}markdown/edit{{ .path }}">
1717
<i class="icon icon-edit">Code</i> Edit
1818
</a>
19-
<div class="markdown-container">
20-
{{ .html | raw}}
19+
<div class="markdown-container" id="markdown-container" >
20+
<textarea style="display: none;" name="md-container" id="md-container" cols="30" rows="10">{{ .html }}</textarea>
2121
</div>
22+
<script src="{{ .root }}static/simplemde.min.js"></script>
23+
<script>
24+
function view() {
25+
var smde = new SimpleMDE({
26+
element: document.getElementById('md-container'),
27+
autoDownloadFontAwesome: false,
28+
spellChecker: false,
29+
status: false,
30+
indentWithTabs: false,
31+
promptURLs: true,
32+
tabSize: 4,
33+
});
34+
var md = smde.value();
35+
document.getElementById('markdown-container').innerHTML = smde.markdown(md);
36+
};
37+
</script>
2238
</body>
2339
</html>

assets/templates/page-view.tmpl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
if (obj.contentWindow.location.href.indexOf("/deleted") > 0) {
2929
obj.parentNode.parentNode.removeChild(obj.parentNode);
3030
}
31+
window.scrollTo(0, document.body.scrollHeight);
3132
}
3233
function output(obj) {
3334
obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + 'px';
@@ -36,6 +37,7 @@
3637
} else if (obj.contentWindow.location.href.indexOf("/loaded") > 0) {
3738
location.reload()
3839
}
40+
window.scrollTo(0, document.body.scrollHeight);
3941
}
4042
function newmd() {
4143
var body = document.getElementById("page-body");
@@ -78,13 +80,10 @@
7880
event.preventDefault();
7981
}
8082
}
81-
function syntax(elem, id) {
82-
console.log(elem, id);
83-
}
8483
</script>
8584
</head>
8685
<body>
87-
<section class="container mt-10">
86+
<section class="container grid-960 mt-10">
8887
<header class="navbar navbar-fixed-height">
8988
<section class="navbar-section">
9089
<img src="{{ $root }}static/logo.png" width="30" height="30" />&nbsp;
@@ -102,16 +101,24 @@
102101
</header>
103102
<section class="container">
104103
<div class="columns">
105-
<div class="column" id="page-body">
104+
<div class="column">
106105
<div class="input-group spacing-top">
107106
<code class="input-group-addon spacing-right">File: {{ $page.filename }}</code>
108107
</div>
109-
{{ range $i, $line := $page.lines }}
110-
{{ if eq $line.type "markdown" }}
108+
</div>
109+
</div>
110+
</section>
111+
</section>
112+
<section class="container mt-10">
113+
<section class="container">
114+
<div class="columns">
115+
<div class="column" style="padding-top: 0px" id="page-body">
116+
{{ range $i, $line := $page.lines }}
117+
{{ if eq $line.type "markdown" }}
111118
<div class="panel spacing-top resizer">
112119
<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>
113120
</div>
114-
{{ else }}
121+
{{ else }}
115122
<div class="input-group spacing-top">
116123
<code class="input-group-addon spacing-right spacing-left">{{ $line.command }}</code>
117124
<a class="btn float-right" href="{{ $root }}output/delete/{{ $page.unique }}/{{ $line.unique }}" onclick="confirm_delete(event)">
@@ -121,14 +128,14 @@
121128
<div class="input-group spacing-top">
122129
<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>
123130
</div>
124-
{{ end }}
125-
{{ end }}
131+
{{ end }}
132+
{{ end }}
126133
<div class="input-group spacing-top" style="margin-top: 10px;">
127134
<a class="btn" href="#" onclick="newmd()"><i class="icon icon-message">Markdown</i> Markdown</a>
128-
{{ if $pipe }}
135+
{{ if $pipe }}
129136
&nbsp;
130137
<a class="btn" href="#" onclick="newcm()"><i class="icon icon-resize-horiz">Command Line</i> Command Line</a>
131-
{{ end }}
138+
{{ end }}
132139
</div>
133140
</div>
134141
</div>

assets/templates/reload.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
border-top-color:transparent;
2222
}
2323
</style>
24-
<meta http-equiv="refresh" content="5"/>
24+
<meta http-equiv="refresh" content="2"/>
2525
</head>
2626
<body>
2727
<div class="center">

pipe_html.go renamed to output.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ var col256 = regexp.MustCompile(`^\[([34]8);5;(\d+)m`)
291291
var colrgb = regexp.MustCompile(`^\[([34]8);2;(\d+);(\d+);(\d+)m`)
292292
var escape = regexp.MustCompile(`^\[(\d+;)?(\d+;)?(\d+;)?(\d+;)?(\d+)([A-Za-z])`)
293293

294-
func _toHtml(raw string) string {
295-
var output = strings.TrimSuffix(raw, "\x00")
294+
func toHtml(raw []byte) []byte {
295+
var output = strings.TrimSuffix(string(raw), "\x00")
296296
output = strings.ReplaceAll(output, "\r", "")
297297
output = strings.Trim(output, "\n")
298298
if output == "" {
299-
return output
299+
return []byte{}
300300
}
301301
output = strings.ReplaceAll(output, "&", "&amp;")
302302
output = strings.ReplaceAll(output, "<", "&lt;")
@@ -449,5 +449,5 @@ func _toHtml(raw string) string {
449449
}
450450
}
451451
html = strings.ReplaceAll(html, "\n", "<br>\n")
452-
return html
452+
return []byte(html)
453453
}

pipe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (r *Rizin) exec(cmd string) (string, error) {
7878
fmt.Println("pipe error:", err)
7979
return "", err
8080
}
81-
return _toHtml(buf), nil
81+
return buf, nil
8282
}
8383

8484
func (r *Rizin) close() {

server_assets.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"github.com/gin-gonic/gin"
67
"html/template"
@@ -14,6 +15,13 @@ var functionMap = template.FuncMap{
1415
"raw": func(b []byte) template.HTML {
1516
return template.HTML(b)
1617
},
18+
"stringify": func(input interface{}) string {
19+
buffer, err := json.Marshal(input)
20+
if err != nil {
21+
return `""`
22+
}
23+
return string(buffer)
24+
},
1725
"keycombo": func(input string) string {
1826
if len(input) > 0 {
1927
return strings.Replace(input, ",", " + ", -1)

server_markdown.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"github.com/gin-gonic/gin"
5-
"gopkg.in/russross/blackfriday.v2"
65
"strings"
76
)
87

@@ -20,10 +19,9 @@ func serverAddMarkdown(markdown *gin.RouterGroup) {
2019
if err != nil {
2120
c.String(404, "file not found")
2221
} else {
23-
html := blackfriday.Run(bytes)
2422
c.HTML(200, "markdown-view.tmpl", gin.H{
2523
"root": webroot,
26-
"html": html,
24+
"html": string(bytes),
2725
"path": "/" + tokens[0] + "/" + tokens[1],
2826
})
2927
}

0 commit comments

Comments
 (0)