mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-10 17:24:32 +02:00
plugins/markdown-preview: switch to mkPlugin
This commit is contained in:
parent
9eea1486bc
commit
20c1ae069e
1 changed files with 207 additions and 105 deletions
|
@ -1,120 +1,222 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
|
helpers,
|
||||||
...
|
...
|
||||||
}:
|
} @ args:
|
||||||
with lib; let
|
with lib;
|
||||||
cfg = config.plugins.markdown-preview;
|
with import ../helpers.nix {inherit lib;};
|
||||||
in {
|
mkPlugin args {
|
||||||
|
name = "markdown-preview";
|
||||||
|
description = "markdown-preview.nvim";
|
||||||
|
package = pkgs.vimPlugins.markdown-preview-nvim;
|
||||||
|
globalPrefix = "mkdp_";
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
plugins.markdown-preview = {
|
autoStart = mkDefaultOpt {
|
||||||
enable = mkEnableOption "markdown-preview";
|
global = "auto_start";
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Open the preview window after entering the markdown buffer.
|
||||||
|
|
||||||
package = helpers.mkPackageOption "markdown-preview" pkgs.vimPlugins.markdown-preview-nvim;
|
Default: `false`
|
||||||
|
|
||||||
autoStart = helpers.defaultNullOpts.mkBool false ''
|
|
||||||
Open the preview window after entering the markdown buffer
|
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
autoClose = helpers.defaultNullOpts.mkBool true ''
|
autoClose = mkDefaultOpt {
|
||||||
Auto close current preview window when change from markdown buffer to another buffer
|
global = "auto_close";
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Auto close current preview window when change from markdown buffer to another buffer.
|
||||||
|
|
||||||
|
Default: `true`
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
refreshSlow = helpers.defaultNullOpts.mkBool false ''
|
refreshSlow = mkDefaultOpt {
|
||||||
Refresh markdown when save the buffer or leave from insert mode, default false is auto refresh markdown as you edit or move the cursor
|
global = "refresh_slow";
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Refresh markdown when save the buffer or leave from insert mode, default false is auto
|
||||||
|
refresh markdown as you edit or move the cursor.
|
||||||
|
|
||||||
|
Default: `false`
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
commandForGlobal = helpers.defaultNullOpts.mkBool false ''
|
commandForGlobal = mkDefaultOpt {
|
||||||
Enable markdown preview for all files (by default, the plugin is only enabled for markdown files)
|
global = "command_for_global";
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Enable markdown preview for all files (by default, the plugin is only enabled for markdown
|
||||||
|
files).
|
||||||
|
|
||||||
|
Default: `false`
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
openToTheWorld = helpers.defaultNullOpts.mkBool false ''
|
openToTheWorld = mkDefaultOpt {
|
||||||
Make the preview server available to others in your network. By default, the server listens on localhost (127.0.0.1).
|
global = "open_to_the_world";
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Make the preview server available to others in your network.
|
||||||
|
By default, the server listens on localhost (127.0.0.1).
|
||||||
|
|
||||||
|
Default: `false`
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
openIp = helpers.defaultNullOpts.mkStr "" ''
|
openIp = mkDefaultOpt {
|
||||||
Custom IP used to open the preview page. This can be useful when you work in remote vim and preview on local browser.
|
global = "open_ip";
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Custom IP used to open the preview page.
|
||||||
|
This can be useful when you work in remote vim and preview on local browser.
|
||||||
For more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9.
|
For more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9.
|
||||||
'';
|
|
||||||
|
|
||||||
browser = helpers.defaultNullOpts.mkStr "" ''
|
Default: ""
|
||||||
The browser to open the preview page
|
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
echoPreviewUrl = helpers.defaultNullOpts.mkBool false ''
|
browser = mkDefaultOpt {
|
||||||
Echo preview page url in command line when opening the preview page
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
The browser to open the preview page.
|
||||||
|
|
||||||
|
Default: ""
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
browserFunc = helpers.defaultNullOpts.mkStr "" ''
|
echoPreviewUrl = mkDefaultOpt {
|
||||||
A custom vim function name to open preview page. This function will receive url as param.
|
global = "echo_preview_url";
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Echo preview page url in command line when opening the preview page.
|
||||||
|
|
||||||
|
Default: `false`
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
previewOptions = {
|
browserFunc = mkDefaultOpt {
|
||||||
mkit = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "markdown-it options for render";
|
global = "browser_func";
|
||||||
katex = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "katex options for math";
|
type = types.str;
|
||||||
uml = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "markdown-it-plantuml options";
|
description = ''
|
||||||
maid = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "mermaid options";
|
A custom vim function name to open preview page.
|
||||||
disable_sync_scroll = helpers.defaultNullOpts.mkBool false "Disable sync scroll";
|
This function will receive url as param.
|
||||||
sync_scroll_type = helpers.defaultNullOpts.mkNullable (types.enum ["middle" "top" "relative"]) "middle" ''
|
|
||||||
|
Default: ""
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
previewOptions = mkDefaultOpt {
|
||||||
|
global = "preview_options";
|
||||||
|
default = {};
|
||||||
|
description = "Preview options";
|
||||||
|
type = types.submodule {
|
||||||
|
freeformType = types.attrs;
|
||||||
|
options = let
|
||||||
|
mkEmptyListOfStr = helpers.defaultNullOpts.mkNullable (with types; listOf str) "[]";
|
||||||
|
in {
|
||||||
|
mkit = mkEmptyListOfStr "markdown-it options for render";
|
||||||
|
|
||||||
|
katex = mkEmptyListOfStr "katex options for math";
|
||||||
|
|
||||||
|
uml = mkEmptyListOfStr "markdown-it-plantuml options";
|
||||||
|
|
||||||
|
maid = mkEmptyListOfStr "mermaid options";
|
||||||
|
|
||||||
|
disable_sync_scroll = helpers.defaultNullOpts.mkBool false "Disable sync scroll.";
|
||||||
|
|
||||||
|
sync_scroll_type =
|
||||||
|
helpers.defaultNullOpts.mkEnumFirstDefault
|
||||||
|
["middle" "top" "relative"]
|
||||||
|
''
|
||||||
Scroll type:
|
Scroll type:
|
||||||
- "middle": The cursor position is always shown at the middle of the preview page.
|
- "middle": The cursor position is always shown at the middle of the preview page.
|
||||||
- "top": The vim top viewport is always shown at the top of the preview page.
|
- "top": The vim top viewport is always shown at the top of the preview page.
|
||||||
- "relative": The cursor position is always shown at the relative positon of the preview page.
|
- "relative": The cursor position is always shown at the relative positon of the preview page.
|
||||||
|
|
||||||
|
Default: "middle"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
hide_yaml_meta = helpers.defaultNullOpts.mkBool true "Hide yaml metadata.";
|
hide_yaml_meta = helpers.defaultNullOpts.mkBool true "Hide yaml metadata.";
|
||||||
sequence_diagrams = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "js-sequence-diagrams options";
|
|
||||||
flowchart_diagrams = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "flowcharts diagrams options";
|
sequence_diagrams = mkEmptyListOfStr "js-sequence-diagrams options";
|
||||||
content_editable = helpers.defaultNullOpts.mkBool false "Content editable from the preview page";
|
|
||||||
disable_filename = helpers.defaultNullOpts.mkBool false "Disable filename header for the preview page";
|
flowchart_diagrams = mkEmptyListOfStr "flowcharts diagrams options";
|
||||||
toc = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" "Toc options";
|
|
||||||
|
content_editable = helpers.defaultNullOpts.mkBool false ''
|
||||||
|
Content editable from the preview page.
|
||||||
|
'';
|
||||||
|
|
||||||
|
disable_filename = helpers.defaultNullOpts.mkBool false ''
|
||||||
|
Disable filename header for the preview page.
|
||||||
|
'';
|
||||||
|
|
||||||
|
toc = mkEmptyListOfStr "Toc options";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
markdownCss = helpers.defaultNullOpts.mkStr "" ''
|
markdownCss = mkDefaultOpt {
|
||||||
Custom markdown style. Must be an absolute path like '/Users/username/markdown.css' or expand('~/markdown.css').
|
global = "markdown_css";
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Custom markdown style.
|
||||||
|
Must be an absolute path like "/Users/username/markdown.css" or
|
||||||
|
`expand('~/markdown.css')`.
|
||||||
|
|
||||||
|
Default: ""
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
highlightCss = helpers.defaultNullOpts.mkStr "" ''
|
highlightCss = mkDefaultOpt {
|
||||||
Custom highlight style. Must be an absolute path like '/Users/username/highlight.css' or expand('~/highlight.css').
|
global = "highlight_css";
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Custom highlight style.
|
||||||
|
Must be an absolute path like "/Users/username/highlight.css" or
|
||||||
|
`expand('~/highlight.css')`.
|
||||||
|
|
||||||
|
Default: ""
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
port = helpers.defaultNullOpts.mkStr "" "Custom port to start server or empty for random";
|
port = mkDefaultOpt {
|
||||||
|
type = types.ints.positive;
|
||||||
pageTitle = helpers.defaultNullOpts.mkStr "「\${name}」" ''
|
apply = v: helpers.ifNonNull' v (toString v);
|
||||||
preview page title. $${name} will be replaced with the file name.
|
description = ''
|
||||||
|
Custom port to start server or empty for random.
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
fileTypes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "['markdown']" ''
|
pageTitle = mkDefaultOpt {
|
||||||
|
global = "page_title";
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Preview page title.
|
||||||
|
`$${name}` will be replaced with the file name.
|
||||||
|
|
||||||
|
Default: "「\$\{name}」"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
fileTypes = mkDefaultOpt {
|
||||||
|
global = "file_types";
|
||||||
|
type = with types; listOf str;
|
||||||
|
description = ''
|
||||||
Recognized filetypes. These filetypes will have MarkdownPreview... commands.
|
Recognized filetypes. These filetypes will have MarkdownPreview... commands.
|
||||||
'';
|
|
||||||
|
|
||||||
theme = helpers.defaultNullOpts.mkNullable (types.enum ["dark" "light"]) "dark" ''
|
Default: `["markdown"]`
|
||||||
Default theme (dark or light). By default the theme is define according to the preferences of the system.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
theme = mkDefaultOpt {
|
||||||
extraPlugins = [cfg.package];
|
type = types.enum ["dark" "light"];
|
||||||
|
description = ''
|
||||||
globals = {
|
Default theme (dark or light).
|
||||||
mkdp_auto_start = mkIf (cfg.autoStart != null) cfg.autoStart;
|
By default the theme is define according to the preferences of the system.
|
||||||
mkdp_auto_close = mkIf (cfg.autoClose != null) cfg.autoClose;
|
'';
|
||||||
mkdp_refresh_slow = mkIf (cfg.refreshSlow != null) cfg.refreshSlow;
|
|
||||||
mkdp_command_for_global = mkIf (cfg.commandForGlobal != null) cfg.commandForGlobal;
|
|
||||||
mkdp_open_to_the_world = mkIf (cfg.openToTheWorld != null) cfg.openToTheWorld;
|
|
||||||
mkdp_open_ip = mkIf (cfg.openIp != null) cfg.openIp;
|
|
||||||
mkdp_browser = mkIf (cfg.browser != null) cfg.browser;
|
|
||||||
mkdp_echo_preview_url = mkIf (cfg.echoPreviewUrl != null) cfg.echoPreviewUrl;
|
|
||||||
mkdp_browserfunc = mkIf (cfg.browserFunc != null) cfg.browserFunc;
|
|
||||||
mkdp_preview_options = cfg.previewOptions;
|
|
||||||
mkdp_markdown_css = mkIf (cfg.markdownCss != null) cfg.markdownCss;
|
|
||||||
mkdp_highlight_css = mkIf (cfg.highlightCss != null) cfg.highlightCss;
|
|
||||||
mkdp_port = mkIf (cfg.port != null) cfg.port;
|
|
||||||
mkdp_page_title = mkIf (cfg.pageTitle != null) cfg.pageTitle;
|
|
||||||
mkdp_filetypes = mkIf (cfg.fileTypes != null) cfg.fileTypes;
|
|
||||||
mkdp_theme = mkIf (cfg.theme != null) cfg.theme;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue