Skip to content

Commit

Permalink
Make markdown viewer configurable with $NB_MARKDOWN_TOOL.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwmx committed Sep 22, 2023
1 parent 9043a84 commit b9aea4f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 12 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ Also supported for various enhancements:
[`eza`](https://github.com/eza-community/eza),
[`ffplay`](https://ffmpeg.org/ffplay.html),
[ImageMagick](https://imagemagick.org/),
[`glow`](https://github.com/charmbracelet/glow),
[GnuPG](https://en.wikipedia.org/wiki/GNU_Privacy_Guard),
[`highlight`](http://www.andre-simon.de/doku/highlight/en/highlight.php),
[`imgcat`](https://www.iterm2.com/documentation-images.html),
Expand All @@ -219,6 +220,8 @@ Also supported for various enhancements:
[`lsd`](https://github.com/lsd-rs/lsd),
[Links](https://en.wikipedia.org/wiki/Links_(web_browser)),
[Lynx](https://en.wikipedia.org/wiki/Lynx_(web_browser)),
[`mdcat`](https://github.com/swsnr/mdcat),
[`mdless`](https://github.com/ttscoff/mdless),
[Midnight Commander (`mc`)](https://en.wikipedia.org/wiki/Midnight_Commander),
[`mpg123`](https://en.wikipedia.org/wiki/Mpg123),
[MPlayer](https://en.wikipedia.org/wiki/MPlayer),
Expand Down Expand Up @@ -1430,6 +1433,11 @@ which can be opened in your editor with [`nb settings edit`](#settings).

Supported file types and tools include:

- Markdown files ([`$NB_MARKDOWN_TOOL`](#nb_markdown_tool)):
- [`bat`](https://github.com/sharkdp/bat)
- [`glow`](https://github.com/charmbracelet/glow)
- [`mdcat`](https://github.com/swsnr/mdcat)
- [`mdless`](https://github.com/ttscoff/mdless)
- PDF files:
- [`termpdf.py`](https://github.com/dsanson/termpdf.py)
with [kitty](https://sw.kovidgoyal.net/kitty/)
Expand Down Expand Up @@ -8997,6 +9005,7 @@ Shortcut Alias:
<a href="#nb_indicator_video"><code>$NB_INDICATOR_VIDEO</code></a>&nbsp;·
<a href="#nb_limit"><code>$NB_LIMIT</code></a>&nbsp;·
<a href="#nb_mathjax_enabled"><code>$NB_MATHJAX_ENABLED</code></a>&nbsp;·
<a href="#nb_markdown_tool"><code>$NB_MARKDOWN_TOOL</code></a>&nbsp;·
<a href="#nb_pinned_pattern"><code>$NB_PINNED_PATTERN</code></a>&nbsp;·
<a href="#nb_server_host"><code>$NB_SERVER_HOST</code></a>&nbsp;·
<a href="#nb_server_port"><code>$NB_SERVER_PORT</code></a>&nbsp;·
Expand Down Expand Up @@ -9507,6 +9516,20 @@ Example Values: '0', '1'
</sup>
</p>

##### `$NB_MARKDOWN_TOOL`

```text
Default: '' (default pager)

Supported Values: 'bat', 'glow', 'mdcat', 'mdless'
```

<p>
<sup>
<a href="#-variables">↑</a>
</sup>
</p>

##### `$NB_PINNED_PATTERN`

```text
Expand Down
23 changes: 23 additions & 0 deletions docs/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Also supported for various enhancements:
[`eza`](https://github.com/eza-community/eza),
[`ffplay`](https://ffmpeg.org/ffplay.html),
[ImageMagick](https://imagemagick.org/),
[`glow`](https://github.com/charmbracelet/glow),
[GnuPG](https://en.wikipedia.org/wiki/GNU_Privacy_Guard),
[`highlight`](http://www.andre-simon.de/doku/highlight/en/highlight.php),
[`imgcat`](https://www.iterm2.com/documentation-images.html),
Expand All @@ -225,6 +226,8 @@ Also supported for various enhancements:
[`lsd`](https://github.com/lsd-rs/lsd),
[Links](https://en.wikipedia.org/wiki/Links_(web_browser)),
[Lynx](https://en.wikipedia.org/wiki/Lynx_(web_browser)),
[`mdcat`](https://github.com/swsnr/mdcat),
[`mdless`](https://github.com/ttscoff/mdless),
[Midnight Commander (`mc`)](https://en.wikipedia.org/wiki/Midnight_Commander),
[`mpg123`](https://en.wikipedia.org/wiki/Mpg123),
[MPlayer](https://en.wikipedia.org/wiki/MPlayer),
Expand Down Expand Up @@ -1436,6 +1439,11 @@ which can be opened in your editor with [`nb settings edit`](#settings).

Supported file types and tools include:

- Markdown files ([`$NB_MARKDOWN_TOOL`](#nb_markdown_tool)):
- [`bat`](https://github.com/sharkdp/bat)
- [`glow`](https://github.com/charmbracelet/glow)
- [`mdcat`](https://github.com/swsnr/mdcat)
- [`mdless`](https://github.com/ttscoff/mdless)
- PDF files:
- [`termpdf.py`](https://github.com/dsanson/termpdf.py)
with [kitty](https://sw.kovidgoyal.net/kitty/)
Expand Down Expand Up @@ -9003,6 +9011,7 @@ Shortcut Alias:
<a href="#nb_indicator_video"><code>$NB_INDICATOR_VIDEO</code></a>&nbsp;·
<a href="#nb_limit"><code>$NB_LIMIT</code></a>&nbsp;·
<a href="#nb_mathjax_enabled"><code>$NB_MATHJAX_ENABLED</code></a>&nbsp;·
<a href="#nb_markdown_tool"><code>$NB_MARKDOWN_TOOL</code></a>&nbsp;·
<a href="#nb_pinned_pattern"><code>$NB_PINNED_PATTERN</code></a>&nbsp;·
<a href="#nb_server_host"><code>$NB_SERVER_HOST</code></a>&nbsp;·
<a href="#nb_server_port"><code>$NB_SERVER_PORT</code></a>&nbsp;·
Expand Down Expand Up @@ -9513,6 +9522,20 @@ Example Values: '0', '1'
</sup>
</p>

##### `$NB_MARKDOWN_TOOL`

```text
Default: '' (default pager)

Supported Values: 'bat', 'glow', 'mdcat', 'mdless'
```

<p>
<sup>
<a href="#-variables">↑</a>
</sup>
</p>

##### `$NB_PINNED_PATTERN`

```text
Expand Down
44 changes: 32 additions & 12 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -18827,18 +18827,38 @@ Can't show archives. Export archive and expand to edit.\\n"
{
cat "${_target_path}"
} | {
# fold to current width
LC_ALL=C sed -E \
-e "s/^([[:space:]]*-) /\1${_ME}-ph-${_ME}/g" \
-e "s/^([[:space:]]*\*) /\1${_ME}-ph-${_ME}/g" \
| LC_ALL=C fold -s -w "${_COLUMNS}" \
| LC_ALL=C sed -E \
-e "s/^([[:space:]]*-)${_ME}-ph-${_ME}/\1 /g" \
-e "s/^([[:space:]]*\*)${_ME}-ph-${_ME}/\1 /g"
} | {
_highlight_syntax_if_available "${_target_extension:-}"
} | {
_pager
if _contains "${_target_extension:-}" "markdown" "md" &&
_contains "${NB_MARKDOWN_TOOL:-}" "bat" "glow" "mdcat" "mdless"
then
if [[ "${NB_MARKDOWN_TOOL:-}" == "bat" ]]
then
bat --language "${_target_extension:-md}"
elif [[ "${NB_MARKDOWN_TOOL:-}" == "glow" ]]
then
glow --pager
elif [[ "${NB_MARKDOWN_TOOL:-}" == "mdcat" ]]
then
mdcat --paginate
elif [[ "${NB_MARKDOWN_TOOL:-}" == "mdless" ]]
then
mdless
fi
else
{
# fold to current terminal width and preserve list formatting
LC_ALL=C sed -E \
-e "s/^([[:space:]]*-) /\1${_ME}-ph-${_ME}/g" \
-e "s/^([[:space:]]*\*) /\1${_ME}-ph-${_ME}/g" \
| LC_ALL=C fold -s -w "${_COLUMNS}" \
| LC_ALL=C sed -E \
-e "s/^([[:space:]]*-)${_ME}-ph-${_ME}/\1 /g" \
-e "s/^([[:space:]]*\*)${_ME}-ph-${_ME}/\1 /g"
} | {
_highlight_syntax_if_available "${_target_extension:-}"
} | {
_pager
}
fi
}
fi
fi
Expand Down

0 comments on commit b9aea4f

Please sign in to comment.