-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
166 lines (147 loc) · 4.2 KB
/
Copy pathindex.html
File metadata and controls
166 lines (147 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<title>draftr</title>
<script src="./jquery-1.9.1.js"></script>
<script src="./yaml.js"></script>
<script src="./draftr.js"></script>
<script>
var state = {
mkd: null,
xml: null,
txt: null,
name: null
}
$(document).ready(function() {
var IN = $("#in")[0], OUT = $("#out")[0];
// Populate a minimal mkd file in the input
$.ajax({
url: "./min.mkd",
type: "get",
dataType: "text",
success: function(response) {
IN.value = response;
}
})
// Attach the compile action to the button
$("#go").click(function() {
window.ast = fromMD(IN.value);
OUT.value = toTXT(window.ast);
/*
OUT.value = "Loading...";
$.ajax({
url: "./compile.py",
type: "post",
data: IN.value,
contentType: "text/plain",
dataType: "text",
success: function(response) {
// Split out and cache MKD, XML, TXT
var divider = "-----DRAFTR-----\n";
parts = response.split(divider);
if (parts.length != 3) { return; }
window.state.mkd = parts[0];
window.state.xml = parts[1];
window.state.txt = parts[2];
OUT.value = window.state.txt;
},
error: function() {
OUT.value = "Error in compiling. Is your Markdown correct?";
OUT.value += "\n(Sorry this isn't very helpful. TODO: better error messages";
}
});
*/
})
$("a.download").click(function() {
// Update the content
window.state.mkd = IN.value
window.state.name = IN.value.match(/draft-[a-zA-Z0-9-]*/);
// Populate the form
var id = $(this)[0].id;
var content = $("#downloadContent")[0];
var format = $("#downloadFormat")[0];
var name = $("#downloadName")[0];
if (id.indexOf("mkd") == 0) {
content.value = window.state.mkd;
format.value = "mkd";
name.value = window.state.name + ".mkd";
} else if (id.indexOf("xml") == 0) {
content.value = window.state.xml;
format.value = "xml";
name.value = window.state.name + ".xml";
} else if (id.indexOf("txt") == 0) {
content.value = window.state.txt;
format.value = "txt";
name.value = window.state.name + ".txt";
} else {
return; // wat
}
// Submit the form
$("#dlForm").submit();
})
});
</script>
<style>
html { height: 95%; }
body {
background: #ECF0F1;
font-family: Menlo, Courier, monospace;
font-size: 12px;
width: 170ex;
height: 95%;
margin: 1em auto;
text-align: center;
}
textarea {
width: 80ex;
height: 95%;
background: #ECF0F1;
border: 1px solid #BDC3C7;
font-family: Menlo, Courier, monospace;
font-size: 12px;
}
button {
width: 80ex;
color: white;
background: #8E44AD;
border: none;
padding: 1ex;
font-family: Menlo, Courier, monospace;
font-size: 12px;
font-weight: bold;
}
a {
width: 80ex;
color: white;
background: #2980B9;
border: none;
padding: 2ex;
font-family: Menlo, Courier, monospace;
font-size: 12px;
font-weight: bold;
text-decoration: none;
}
form {
display: none;
}
</style>
</head>
<body>
<!-- Main markup section -->
<button id="go">markdown --> rfc</button><br/>
<textarea id="in"></textarea>
<textarea id="out"></textarea>
<!-- file downloads -->
<p>
<a href="#" class="download" id="mkdDownload" title="Download Markdown">↓M</a>
<a href="#" class="download" id="xmlDownload" title="Download XML">↓X</a>
<a href="#" class="download" id="txtDownload" title="Download text/RFC">↓T</a>
<a href="https://github.com/cabo/kramdown-rfc2629" target="_blank" title="Help">H?</a>
</p>
<form id="dlForm" action="download.py" method="post" target="blank">
<input type="hidden" id="downloadContent" name="content"/>
<input type="hidden" id="downloadFormat" name="format"/>
<input type="hidden" id="downloadName" name="name"/>
</form>
</body>
</html>