Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ home-manager.users.<user>.home.packages = [
- `extra_plugins.nix`: Configures additional plugins.
- `mini.nix`: Configures the Mini plugin.
- `obsidian.nix`: Confiugres the Obsidian plugin, for note-taking purposes.
- `markdown-preview.nix`: Configures the Markdown Preview plugin.
- `md-render.nix`: Provides in-terminal Markdown previews, synchronized splits, and native Mermaid rendering.
- `toggleterm.nix`: Provides a floating scratch terminal; cmux owns persistent panes and sessions.

Please refer to the individual `.nix` files for more detailed configuration information.
Expand Down
2 changes: 1 addition & 1 deletion config/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ _: {
./plugins/utils/whichkey.nix
./plugins/utils/extra_plugins.nix
./plugins/utils/mini.nix
./plugins/utils/markdown-preview.nix
./plugins/utils/md-render.nix
./plugins/utils/obsidian.nix
./plugins/utils/toggleterm.nix
./plugins/utils/web-devicons.nix
Expand Down
29 changes: 0 additions & 29 deletions config/plugins/utils/markdown-preview.nix

This file was deleted.

114 changes: 114 additions & 0 deletions config/plugins/utils/md-render.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
lib,
mdRender,
mmdr,
pkgs,
...
}:
let
mdRenderPlugin = pkgs.vimUtils.buildVimPlugin {
pname = "md-render.nvim";
version = "3.4.0";
src = mdRender;
};

mmdc = pkgs.writeShellApplication {
name = "mmdc";
text = ''
input=""
output=""
theme=""
background=""

while (( $# > 0 )); do
if (( $# < 2 )); then
echo "mmdc: missing value for $1" >&2
exit 2
fi

case "$1" in
-i|--input)
input="$2"
;;
-o|--output)
output="$2"
;;
-t|--theme)
theme="$2"
;;
-b|--backgroundColor)
background="$2"
;;
-s|--scale)
;;
*)
echo "mmdc: unsupported argument: $1" >&2
exit 2
;;
esac

shift 2
done

if [[ -z "$input" || -z "$output" ]]; then
echo "mmdc: input and output are required" >&2
exit 2
fi

args=(-i "$input" -o "$output" -e png)
if [[ -n "$theme" ]]; then
args+=(-t "$theme")
fi

if [[ -n "$background" ]]; then
config="$(mktemp "''${TMPDIR:-/tmp}/md-render-mmdr.XXXXXX")"
trap 'rm -f -- "$config"' EXIT
printf '{"themeVariables":{"background":"%s"}}\n' "$background" > "$config"
args+=(-c "$config")
fi

${lib.getExe mmdr} "''${args[@]}"
'';
};
in
{
extraPlugins = [ mdRenderPlugin ];
extraPackages = [ mmdc ];

keymaps = [
{
mode = "n";
key = "<leader>mp";
action = lib.nixvim.mkRaw ''
function()
local columns = vim.o.columns
local width = math.min(160, math.floor(columns * 0.8), math.max(80, math.floor(columns * 0.6)))

require("md-render").preview.show({ max_width = width - 2 })

local win = vim.api.nvim_get_current_win()
local config = vim.api.nvim_win_get_config(win)
if config.relative ~= "" then
vim.api.nvim_win_set_config(win, {
relative = config.relative,
width = width,
row = config.row,
col = math.floor((columns - width) / 2),
})
end
end
'';
options = {
desc = "Toggle Markdown preview";
};
}
{
mode = "n";
key = "<leader>ms";
action = "<cmd>vertical MdRender split<cr>";
options = {
desc = "Open synchronized Markdown split";
};
}
];
}
76 changes: 75 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
};
md-render = {
url = "github:delphinus/md-render.nvim/v3.4.0";
flake = false;
};
mmdr = {
url = "github:1jehuang/mermaid-rs-renderer/v0.3.1";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
Expand Down Expand Up @@ -44,7 +52,8 @@
module = import ./config; # import the module directly
# You can use `extraSpecialArgs` to pass additional arguments to your module files
extraSpecialArgs = {
# inherit (inputs) foo;
mdRender = inputs.md-render;
mmdr = inputs.mmdr.packages.${system}.default;
};
};
nvim = nixvim'.makeNixvimWithModule nixvimModule;
Expand Down