Skip to content

Commit bf878a6

Browse files
committed
Improve mermaid diagram styling and README documentation
- Update README with enhanced feature list and mermaid diagram showing how the tool works - Add comprehensive mermaid CSS styling for dark and light modes - Improve text visibility with font-weight and font-size adjustments - Enhance stroke widths for better line visibility in diagrams - Simplify mermaid initialization with proper theme detection - Add flowchart-specific configuration for better diagram rendering
1 parent cbd660a commit bf878a6

5 files changed

Lines changed: 297 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,162 @@
1+
1.7.0 / 2025-12-20
2+
==================
3+
4+
* Convert relative image links to base64 data URIs (markdown and HTML) (#47)
5+
6+
1.6.4 / 2024-12-31
7+
==================
8+
9+
* Merge pull request #39 from mapitman/bug/handle-file-not-found
10+
* Handle file not found error
11+
* Revert "Update snap build to set version"
12+
13+
1.6.3 / 2024-11-30
14+
==================
15+
16+
* Merge pull request #33 from mapitman/handle-permission-denied
17+
* Add vscode settings
18+
* Update snap build to set version
19+
* Handle permission denied error a little better
20+
* 1 version update (readme) (#31)
21+
22+
1.6.2 / 2024-03-23
23+
==================
24+
25+
* Merge pull request #28 from mapitman/dependabot/go_modules/golang.org/x/text-0.3.8
26+
* Bump golang.org/x/text from 0.3.2 to 0.3.8
27+
* Update README.md
28+
29+
1.6.1 / 2024-02-19
30+
==================
31+
32+
* Merge pull request #27 from mapitman/handle-inline-html
33+
* Fix build
34+
* Handle in-line HTML
35+
36+
1.6.0 / 2024-02-19
37+
==================
38+
39+
* Merge pull request #25 from mapitman/update-readme
40+
* Update README
41+
* Merge pull request #24 from mapitman/dependabot/go_modules/golang.org/x/text-0.3.8
42+
* Bump golang.org/x/text from 0.3.2 to 0.3.8
43+
* Merge pull request #23 from mapitman/update-actions
44+
* Update to latest versions of some github actions
45+
* Merge pull request #22 from mapitman/dark-mode
46+
* Update to support light/dark themes via OS setting
47+
* Merge pull request #21 from mapitman/update-readme
48+
* Update docs and Snap build process
49+
* Add build status badge
50+
* Auto-created releases will be drafts
51+
52+
1.5.0 / 2023-09-17
53+
==================
54+
55+
* Prepare for next release
56+
* Merge pull request #15 from mapitman/suppress-browser-messages
57+
* Suppress stderr and stdout messages from browser
58+
* Merge pull request #13 from mapitman/support-env-var-for-output
59+
* Support reading an environment variable for the directory to write to
60+
* Merge pull request #11 from mapitman/add-actions
61+
* Add automated build and release actions
62+
63+
1.4.1 / 2021-12-28
64+
==================
65+
66+
* Fix build with go 1.17
67+
* Add info about AUR to README
68+
69+
1.4.0 / 2020-11-08
70+
==================
71+
72+
* Add manpage to Linux tarballs
73+
* Add files and config to build Debian package
74+
* Write temp files into $HOME/mdview-temp when installed via snap
75+
* add snap store image and link
76+
77+
1.3.0 / 2018-11-16
78+
==================
79+
80+
* Update readme and history
81+
* Add ability to render markdown file with no style applied
82+
* Update Makefile to use version variable
83+
* Update link to releases
84+
* Update README with links to install snapd and golang
85+
* trim history file
86+
* Add changelog
87+
* Add vscode-specific files
88+
* Bump version for next release
89+
* Extract HTML title from markdown
90+
91+
1.2.0 / 2018-11-02
92+
==================
93+
94+
* Bump app version
95+
* Bump snap version
96+
* Merge pull request #5 from eaglersdeveloper/opening-from-file-manager
97+
* Add more information to desktop file
98+
* Bump snap version
99+
* update gitignore
100+
101+
1.1.0 / 2018-10-30
102+
==================
103+
104+
* Update version to 1.1
105+
* Merge pull request #4 from eaglersdeveloper/opening-from-file-manager
106+
* Add the ability to open from file manager
107+
* Merge pull request #3 from evandandrea/fix-snap
108+
* Fix snapcraft.yaml (use go1.8)
109+
* update README with link to snap store
110+
* Fix desktop file
111+
* Add desktop file to get rid of warning when snap is built
112+
* Add parts/ to gitignore
113+
* Add unity7 plug so xdg-open works in snap
114+
* candidate is not the correct value, should be stable
115+
* switch snap to candidate
116+
* Add snap badge
117+
* Update so that classic confinement is not required for snap
118+
* Fix make install
119+
* Add gopath to go build line
120+
* Fix gopath setting in makefile
121+
* Add gopath
122+
* Change confinement to classic
123+
* update makefile to have a snap task
124+
* Add go get to makefile
125+
* Add golang as build dependency
126+
* Update snap yaml to build the right thing
127+
* Update snapcraft.yaml
128+
* Create binary archive files as part of build
129+
* Update README
130+
* Initial commit
131+
132+
1.0.0 / 2018-08-25
133+
==================
134+
135+
* Initial commit
136+
137+
n.n.n / 2026-01-18
138+
==================
139+
140+
* Fix script escaping to include closing bracket and improve comments
141+
* Fix CDN script loading - use NoScript option and embed mermaid.js properly
142+
* Simplify embedMermaidScript and make regex more flexible
143+
* Move CDN regex to package level and make it more flexible
144+
* Add mermaid.min.js to repository for offline self-contained rendering
145+
* Address code review feedback: improve regex check, remove dead code, fix title extraction
146+
* Replace golang-commonmark with Goldmark and add Mermaid support
147+
* Initial plan
148+
149+
n.n.n / 2026-01-18
150+
==================
151+
152+
* Fix script escaping to include closing bracket and improve comments
153+
* Fix CDN script loading - use NoScript option and embed mermaid.js properly
154+
* Simplify embedMermaidScript and make regex more flexible
155+
* Move CDN regex to package level and make it more flexible
156+
* Add mermaid.min.js to repository for offline self-contained rendering
157+
* Address code review feedback: improve regex check, remove dead code, fix title extraction
158+
* Replace golang-commonmark with Goldmark and add Mermaid support
159+
* Initial plan
1160

2161
1.5.0 / 2023-09-17
3162
==================

README.md

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
# Markdown View
2+
![Markdown View application icon showing the letter M with a downward arrow on a white background](markdown-256.webp)
23

34
[![Build](https://github.com/mapitman/mdview/actions/workflows/build.yml/badge.svg)](https://github.com/mapitman/mdview/actions/workflows/build.yml)
45

5-
Formats markdown and launches it in a browser.
6+
A lightweight command-line tool that converts markdown files to styled HTML and opens them in your default browser. Supports GitHub Flavored Markdown, Mermaid diagrams, embedded images, and automatic theme detection.
67

7-
## Usage
8+
## Features
89

9-
By default, `mdview` tries to use your operating system's temporary
10-
directory to write HTML files to. If that doesn't work for you, you can
11-
set an environment variable that it will use instead. For example, on
12-
Ubuntu Linux, Firefox is packaged as a Snap and is unable to read from
13-
`/tmp`. I get around this by setting `MDVIEW_DIR` like so:
10+
- **GitHub Flavored Markdown** - Full support for tables, task lists, strikethrough, and more
11+
- **Mermaid Diagrams** - Create flowcharts, sequence diagrams, state diagrams, and other visualizations directly in markdown
12+
- **Embedded Images** - Automatically converts relative image paths to data URIs for offline viewing
13+
- **Theme Detection** - HTML output conforms to your system's light or dark theme setting
14+
- **Typographic Enhancements** - Smart quotes, dashes, and other typographic improvements
15+
- **Bare HTML Option** - Generate unstyled HTML when needed
16+
- **Flexible Output** - Write to a temporary file or specify a custom output location
1417

15-
```sh
16-
export MDVIEW_DIR=$HOME/mdview-temp
17-
```
1818

1919

20+
## Usage
21+
22+
By default, `mdview` writes the generated HTML to a temporary directory.
23+
It tries these in order:
24+
- A path defined in the `MDVIEW_DIR` environment variable
25+
- Your operating system's temporary directory
26+
27+
If you are on Linux and set the `TMPDIR` environment variable, that is
28+
what the OS will report as the temp directory. If you set it to a
29+
directory under your home directory, then browsers installed via Snap
30+
(like Firefox on Ubuntu) will be able to read the generated file.
31+
Applications installed via Snap are unable to read from `/tmp`.
32+
2033
```text
2134
Usage:
2235
mdview [options] <filename>
@@ -50,7 +63,7 @@ Thanks to [sindresorhus](https://github.com/sindresorhus/github-markdown-css) fo
5063

5164
### Arch Linux (and derivatives)
5265

53-
Markdown View is now available in the [AUR](https://aur.archlinux.org/packages/mdview/)
66+
Markdown View is available in the [AUR](https://aur.archlinux.org/packages/mdview/)
5467
If you have an AUR helper like `yay`, installing is as easy as:
5568
```
5669
yay -S mdview
@@ -119,4 +132,20 @@ go get github.com/mapitman/mdview
119132

120133
Don't have Golang? [Get it now](https://golang.org/doc/install).
121134

135+
## How It Works
136+
137+
```mermaid
138+
graph TD
139+
A["📄 Markdown File"] -->|Read| B["Process Images"]
140+
B -->|Convert<br/>Relative Paths<br/>to Data URIs| C["Image Processing"]
141+
C --> D["Parse Markdown"]
142+
D -->|GFM + Mermaid<br/>+ Typography| E["Goldmark Parser"]
143+
E -->|Generate| F["HTML AST"]
144+
F -->|Extract Title| G["Extract H1"]
145+
F -->|Render| H["HTML Content"]
146+
H -->|Embed<br/>Scripts| I["Add Mermaid.js"]
147+
I -->|Apply Styles| J["Apply CSS Theme"]
148+
J -->|Generate| K["HTML File"]
149+
K -->|Launch| L["🌐 Browser"]
150+
```
122151

github-markdown.css

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,3 +1193,85 @@
11931193
.markdown-body .markdown-alert.markdown-alert-caution .markdown-alert-title {
11941194
color: var(--color-danger-fg);
11951195
}
1196+
1197+
/* Mermaid diagram styling for better visibility */
1198+
.mermaid text,
1199+
.mermaid tspan {
1200+
font-weight: 500 !important;
1201+
font-size: 13px !important;
1202+
}
1203+
1204+
.mermaid .label text {
1205+
font-weight: 600 !important;
1206+
font-size: 13px !important;
1207+
}
1208+
1209+
.mermaid .edgeLabel text {
1210+
font-weight: 500 !important;
1211+
}
1212+
1213+
@media (prefers-color-scheme: dark) {
1214+
.mermaid {
1215+
background-color: transparent;
1216+
}
1217+
1218+
.mermaid text,
1219+
.mermaid tspan,
1220+
.mermaid .label text,
1221+
.mermaid .edgeLabel text {
1222+
fill: #e6edf3 !important;
1223+
}
1224+
1225+
.mermaid .node rect,
1226+
.mermaid .node circle,
1227+
.mermaid .node ellipse,
1228+
.mermaid .node polygon,
1229+
.mermaid .node path {
1230+
stroke: #58a6ff !important;
1231+
stroke-width: 2px !important;
1232+
fill: #0d1117 !important;
1233+
}
1234+
1235+
.mermaid .edgeLabel {
1236+
background-color: #0d1117;
1237+
}
1238+
1239+
.mermaid line,
1240+
.mermaid path {
1241+
stroke: #58a6ff !important;
1242+
stroke-width: 2px !important;
1243+
}
1244+
}
1245+
1246+
@media (prefers-color-scheme: light) {
1247+
.mermaid {
1248+
background-color: transparent;
1249+
}
1250+
1251+
.mermaid text,
1252+
.mermaid tspan,
1253+
.mermaid .label text,
1254+
.mermaid .edgeLabel text {
1255+
fill: #1F2328 !important;
1256+
}
1257+
1258+
.mermaid .node rect,
1259+
.mermaid .node circle,
1260+
.mermaid .node ellipse,
1261+
.mermaid .node polygon,
1262+
.mermaid .node path {
1263+
stroke: #0550ae !important;
1264+
stroke-width: 2px !important;
1265+
fill: #ffffff !important;
1266+
}
1267+
1268+
.mermaid .edgeLabel {
1269+
background-color: #ffffff;
1270+
}
1271+
1272+
.mermaid line,
1273+
.mermaid path {
1274+
stroke: #0550ae !important;
1275+
stroke-width: 2px !important;
1276+
}
1277+
}

main.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package main
33
import (
44
"bytes"
55
"crypto/rand"
6-
"encoding/base64"
76
_ "embed"
7+
"encoding/base64"
88
"encoding/hex"
99
"errors"
1010
"flag"
@@ -411,7 +411,21 @@ func embedMermaidScript(htmlContent string) string {
411411
escapedMermaidJS := strings.ReplaceAll(mermaidJS, "</script>", "<\\/script>")
412412

413413
// Add the embedded Mermaid.js and initialization at the end of the content
414-
inlineScript := fmt.Sprintf("<script>%s</script><script>mermaid.initialize({startOnLoad: true});</script>", escapedMermaidJS)
414+
// Initialize mermaid with theme detection
415+
initScript := `
416+
var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
417+
mermaid.initialize({
418+
startOnLoad: true,
419+
theme: isDarkMode ? 'dark' : 'default',
420+
flowchart: {
421+
useMaxWidth: true,
422+
htmlLabels: true,
423+
curve: 'linear'
424+
},
425+
securityLevel: 'loose'
426+
});
427+
`
428+
inlineScript := fmt.Sprintf("<script>%s</script><script>%s</script>", escapedMermaidJS, initScript)
415429

416430
return htmlContent + inlineScript
417431
}

markdown-256.webp

694 Bytes
Loading

0 commit comments

Comments
 (0)