Skip to content

Commit b52b3bb

Browse files
authored
Add an optional input text field for specifying the filename to download
1 parent cfa24ed commit b52b3bb

File tree

3 files changed

+90
-63
lines changed

3 files changed

+90
-63
lines changed

.github/workflows/docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
jobs:
1212
push_to_registry:
13-
name: Push Docker image to Docker Hub
13+
name: Build Docker image and push to Docker Hub on master
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout

Cargo.lock

Lines changed: 54 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/index.html

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,23 @@
2828
padding: 1em;
2929
}
3030

31+
/* Class is automatically added to textarea elements, see https://codemirror.net/5/doc/manual.html#styling. */
3132
.CodeMirror {
3233
border-radius: 1em;
3334
padding: 1em;
3435
height: auto;
3536
}
3637

37-
select {
38+
select, input {
3839
padding: 0.5em;
3940
border-radius: 0.2em;
4041
}
4142

43+
code {
44+
background: #4f5a6b;
45+
padding: 0.125em 0.25em;
46+
}
47+
4248
button {
4349
background: #c2d94c;
4450
color: #0a0e14;
@@ -65,7 +71,7 @@ <h1 hidden="hidden">md-to-pdf</h1>
6571
<label for="markdown">Markdown</label>
6672
<br>
6773
<br>
68-
<textarea id="markdown" class="markdown">
74+
<textarea id="markdown">
6975
# md-to-pdf
7076

7177
A web service for converting markdown to PDF
@@ -110,7 +116,7 @@ <h1 hidden="hidden">md-to-pdf</h1>
110116
<label for="css">CSS</label>
111117
<br>
112118
<br>
113-
<textarea id="css" class="css">
119+
<textarea id="css">
114120
/* You can add some CSS styles too, if you want. */
115121

116122
h1, h2 {
@@ -133,14 +139,25 @@ <h1 hidden="hidden">md-to-pdf</h1>
133139

134140
<br>
135141

136-
<label for="engine">Conversion Engine (just try which works better for you)</label>
137-
<br />
138-
<br />
139-
<select id="engine">
140-
<option>weasyprint</option>
141-
<option>wkhtmltopdf</option>
142-
<option label="pdflatex (CSS will have no effect)">pdflatex</option>
143-
</select>
142+
<div style="display: flex; flex-direction: row; gap: 5em;">
143+
<div>
144+
<label for="engine">Conversion Engine (just try which works better for you)</label>
145+
<br />
146+
<br />
147+
<select id="engine">
148+
<option>weasyprint</option>
149+
<option>wkhtmltopdf</option>
150+
<option label="pdflatex (CSS will have no effect)">pdflatex</option>
151+
</select>
152+
</div>
153+
154+
<div>
155+
<label for="filename">Filename (defaults to <code>md-to-pdf</code>, extension <code>.pdf</code> is always added)</label>
156+
<br />
157+
<br />
158+
<input type="text" id="filename">
159+
</div>
160+
</div>
144161

145162
<br>
146163
<br>
@@ -150,11 +167,11 @@ <h1 hidden="hidden">md-to-pdf</h1>
150167
<script>
151168
const markdown = CodeMirror.fromTextArea(
152169
document.querySelector('#markdown'),
153-
{mode: 'markdown', theme: 'ayu-dark'}
170+
{ mode: 'markdown', theme: 'ayu-dark' },
154171
);
155172
const css = CodeMirror.fromTextArea(
156173
document.querySelector('#css'),
157-
{mode: 'css', theme: 'ayu-dark'}
174+
{ mode: 'css', theme: 'ayu-dark' },
158175
);
159176

160177
async function mdToPdf() {
@@ -179,9 +196,10 @@ <h1 hidden="hidden">md-to-pdf</h1>
179196
function downloadBlob(blob) {
180197
const url = URL.createObjectURL(blob);
181198
const a = document.createElement('a');
199+
const filename = document.querySelector('#filename').value || 'md-to-pdf'
182200

183201
a.href = url;
184-
a.download = 'md-to-pdf.pdf';
202+
a.download = `${filename}.pdf`;
185203

186204
const clickHandler = () => {
187205
setTimeout(() => {
@@ -197,7 +215,9 @@ <h1 hidden="hidden">md-to-pdf</h1>
197215

198216
<footer>
199217
<a href="https://github.com/spawnia/md-to-pdf" title="md-to-pdf GitHub repository">
200-
<svg height="30" width="30" viewBox="0 0 16 16"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>
218+
<svg height="30" width="30" viewBox="0 0 16 16">
219+
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/>
220+
</svg>
201221
</a>
202222
</footer>
203223
</body>

0 commit comments

Comments
 (0)