Skip to content

Commit

Permalink
Clean up templates and CSS handling 🧽
Browse files Browse the repository at this point in the history
1. Create new, minimal `default-template.html`
    - when using for plain conversion (rather than preview),
      we don't need all that bulk (CSS)
    - this keeps the default output short and focused
2. Rename the previous default template to `preview-template.html`
    - this one is used for previews by the Vim plugin
    - it now includes the CSS directly
3. CSS insertion is removed from the command-line tool
  • Loading branch information
pmeinhardt committed Apr 19, 2024
1 parent d44a23a commit d11cb68
Show file tree
Hide file tree
Showing 13 changed files with 1,274 additions and 1,245 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Update CSS
run: script/update-css
- name: Update preview template
run: script/update-preview-template
- name: Create or update pull-request
id: create-pull-request
uses: peter-evans/create-pull-request@v4
with:
title: Update CSS 💅
title: Update preview template 💅
body: https://github.com/sindresorhus/github-markdown-css
commit-message: Update CSS 💅
commit-message: Update preview template 💅
delete-branch: true
labels: automated pull-request
- name: Print pull-request details
Expand Down
9 changes: 4 additions & 5 deletions examples/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ $ maxdown input.md
<!DOCTYPE html>
<html>
<head>
...
<meta charset="utf-8">
<title>Preview</title>
<base href="">
...
</head>
<body class="markdown-body">
<body>
<p>Hello <strong>Markdown</strong>!</p>
</body>
</html>
Expand All @@ -33,7 +32,7 @@ $ maxdown --title "Pizzazz" input.md
<title>Pizzazz</title>
...
</head>
<body class="markdown-body">
<body>
<p>Hello <strong>Markdown</strong>!</p>
</body>
</html>
Expand All @@ -53,7 +52,7 @@ $ maxdown --base "https://github.com/pmeinhardt/maxdown" input.md
<base href="https://github.com/pmeinhardt/maxdown">
...
</head>
<body class="markdown-body">
<body>
<p>Hello <strong>Markdown</strong>!</p>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion examples/read-stdin.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
...
</head>
<body class="markdown-body">
<body>
<p>Hello I/O!</p>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion examples/write-file.out/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
...
</head>
<body class="markdown-body">
<body>
<p>Just here for the input.</p>
</body>
</html>
2 changes: 1 addition & 1 deletion plugin/maxdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function! s:convert() abort

let args = [
\ '--dangerous',
\ '--template', shellescape(s:path . '/src/minimal-template.html'),
\ '--title', shellescape(expand('%:t')),
\ '-',
\ ]
Expand All @@ -44,6 +43,7 @@ function! s:invoke(dest, source, bnum) abort
\ '--dangerous',
\ '--base', shellescape(a:source),
\ '--output', shellescape(a:dest),
\ '--template', shellescape(s:path . '/src/preview-template.html'),
\ '-'
\ ]

Expand Down
10 changes: 4 additions & 6 deletions script/update-css → script/get-github-markdown-css
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ BASE="https://raw.githubusercontent.com/sindresorhus/github-markdown-css/main"
CSS="$BASE/github-markdown.css"
LICENSE="$BASE/license"

{
printf '/*\n'
curl --silent --show-error "$LICENSE"
printf '*/\n\n'
curl --silent --show-error "$CSS"
} > src/github.css
printf '/*\n'
curl --silent --show-error "$LICENSE"
printf '*/\n\n'
curl --silent --show-error "$CSS"
16 changes: 16 additions & 0 deletions script/update-preview-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

cd "$(dirname "$0")/.."

TEMPLATE="src/preview-template-template.html"
OUTPUT="src/preview-template.html"

CSS="$(script/get-github-markdown-css | sed '2,$s/^/ /' | sed 's/ *$//')"
export CSS

# shellcheck disable=SC2016
envsubst '${CSS}' < "$TEMPLATE" > "$OUTPUT"
9 changes: 1 addition & 8 deletions src/default-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
<meta charset="utf-8">
<title>{{ title }}</title>
<base href="{{ base }}">
<style>
.markdown-body {
padding: 2rem;
}

{{ default-css }}
</style>
</head>
<body class="markdown-body">
<body>
{{ content }}
</body>
</html>
Loading

0 comments on commit d11cb68

Please sign in to comment.