Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Nov 16, 2023
1 parent 0987d75 commit dff0f14
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 153 deletions.
316 changes: 199 additions & 117 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "md-to-pdf"
version = "1.0.0"
version = "1.1.0"
authors = ["spawnia <[email protected]>"]
edition = "2018"

Expand Down
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ COPY . .

RUN cargo install --path .

FROM debian:bookworm-slim
FROM debian:12-slim

RUN apt-get update \
&& apt-get install -y \
&& apt-get install --yes \
pandoc \
wkhtmltopdf \
texlive \
build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info \
&& pip3 install weasyprint \
# https://stackoverflow.com/questions/75608323/how-do-i-solve-error-externally-managed-environment-every-time-i-use-pip-3
&& pip3 install --break-system-packages weasyprint \
&& pandoc --version

COPY --from=builder /usr/local/cargo/bin/md-to-pdf /usr/bin/md-to-pdf
COPY --from=builder /usr/local/cargo/bin/md-to-pdf /usr/local/bin/md-to-pdf

EXPOSE 8000
CMD ["md-to-pdf"]

RUN useradd -m rocket
RUN useradd --create-home rocket
USER rocket
WORKDIR /home/rocket

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dcrust=$$( [ -f /.dockerenv ] && echo "" || echo "docker-compose exec rust")
dcpandoc=$$( [ -f /.dockerenv ] && echo "" || echo "docker-compose exec pandoc")

.PHONY: it
it: fmt target/debug test ## Perform common targets
it: fmt target/debug ## Perform common targets

.PHONY: help
help: ## Displays this list of targets with descriptions
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Send data from files like this:
A prebuilt container image is available at [Docker Hub](https://hub.docker.com/r/spawnia/md-to-pdf).
You can run it yourself like this:

docker run -p 8000:8000 spawnia/md-to-pdf
docker run --publish=8000:8000 spawnia/md-to-pdf

## Built with

Expand Down
3 changes: 2 additions & 1 deletion Rocket.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[development]
address = "0.0.0.0"

# https://rocket.rs/v0.4/guide/configuration/#data-limits
[global.limits]
forms = 131072
forms = 131072 # 128KiB
7 changes: 4 additions & 3 deletions pandoc.dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM debian:bookworm-slim
FROM debian:12-slim

RUN apt-get update \
&& apt-get install -y \
&& apt-get install --yes \
pandoc \
wkhtmltopdf \
texlive \
build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info \
&& pip3 install weasyprint \
# https://stackoverflow.com/questions/75608323/how-do-i-solve-error-externally-managed-environment-every-time-i-use-pip-3
&& pip3 install --break-system-packages weasyprint \
&& pandoc --version

EXPOSE 8000
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ fn convert(form: Form<ConvertForm>) -> Result<NamedFile, ConvertError> {

let mut pandoc_process = pandoc_builder.spawn().map_err(ConvertError::IO)?;

{
let pandoc_stdin = pandoc_process.stdin.as_mut().unwrap();
pandoc_stdin
.write_all(form.markdown.as_bytes())
.map_err(ConvertError::IO)?;
}
pandoc_process
.stdin
.as_mut()
.unwrap()
.write_all(form.markdown.as_bytes())
.map_err(ConvertError::IO)?;

let output = pandoc_process
.wait_with_output()
Expand Down
44 changes: 26 additions & 18 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<style>
body {
background: #243247;
color: #b3b1ad;
font-family: monospace;
margin: 0;
}
Expand Down Expand Up @@ -61,6 +62,9 @@
<main>
<h1 hidden="hidden">md-to-pdf</h1>

<label for="markdown">Markdown</label>
<br>
<br>
<textarea id="markdown" class="markdown">
# md-to-pdf

Expand All @@ -77,11 +81,11 @@ <h1 hidden="hidden">md-to-pdf</h1>

curl --data-urlencode 'markdown=# Heading 1' --output md-to-pdf.pdf https://md-to-pdf.fly.dev

| Parameter | Required | Description |
| --- | --- | --- |
| `markdown` | Required | The markdown content to convert |
| `css` | Optional | CSS styles to apply |
| `engine` | Optional |The PDF conversion engine, can be `wkhtmltopdf`, `weasyprint` or `pdflatex`, defaults to `weasyprint` |
| Parameter | Required | Description |
|------------|----------|-------------------------------------------------------------------------------------------------------|
| `markdown` | Required | The markdown content to convert |
| `css` | Optional | CSS styles to apply |
| `engine` | Optional | The PDF conversion engine, can be `weasyprint`, `wkhtmltopdf` or `pdflatex`, defaults to `weasyprint` |

Send data from files like this:

Expand All @@ -92,7 +96,7 @@ <h1 hidden="hidden">md-to-pdf</h1>
A prebuilt container image is available at [Docker Hub](https://hub.docker.com/r/spawnia/md-to-pdf).
You can run it yourself like this:

docker run -p 8000:8000 spawnia/md-to-pdf
docker run --publish=8000:8000 spawnia/md-to-pdf

## Built with

Expand All @@ -101,8 +105,11 @@ <h1 hidden="hidden">md-to-pdf</h1>
- [Codemirror - a text editor for the browser](https://codemirror.net)
</textarea>

<br/>
<br>

<label for="css">CSS</label>
<br>
<br>
<textarea id="css" class="css">
/* You can add some CSS styles too, if you want. */

Expand All @@ -124,20 +131,21 @@ <h1 hidden="hidden">md-to-pdf</h1>
}
</textarea>

<br/>
<br>

<div style="padding: 1em; color: #b3b1ad;">
<label for="engine">Conversion Engine (just try which works better for you)</label>
<select id="engine">
<option>weasyprint</option>
<option>wkhtmltopdf</option>
<option label="pdflatex (CSS will have no effect)">pdflatex</option>
</select>
</div>
<label for="engine">Conversion Engine (just try which works better for you)</label>
<br />
<br />
<select id="engine">
<option>weasyprint</option>
<option>wkhtmltopdf</option>
<option label="pdflatex (CSS will have no effect)">pdflatex</option>
</select>

<br/>
<br>
<br>

<button onclick="mdToPdf()" style="margin-left: 1em">Convert and download PDF</button>
<button onclick="mdToPdf()">Convert and download PDF</button>

<script>
const markdown = CodeMirror.fromTextArea(
Expand Down

0 comments on commit dff0f14

Please sign in to comment.