Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(formatters): support markdownfmt #482

Merged
merged 1 commit into from
Oct 11, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.2.6...HEAD)

- feat(formatters): support ziggy fmt [`#481`](https://github.com/hougesen/mdsf/pull/481)
- feat(formatters): support kulala-fmt [`#480`](https://github.com/hougesen/mdsf/pull/480)
- feat(formatters): support superhtml [`#479`](https://github.com/hougesen/mdsf/pull/479)
- refactor: make language_to_ext return type optional [`#478`](https://github.com/hougesen/mdsf/pull/478)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mdsf init

<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 179 tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 180 tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Formatter | Description |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -283,6 +283,7 @@ mdsf init
| leptosfmt | [https://github.com/bram209/leptosfmt](https://github.com/bram209/leptosfmt) |
| liquidsoap-prettier | [https://github.com/savonet/liquidsoap-prettier](https://github.com/savonet/liquidsoap-prettier) |
| luaformatter | [https://github.com/Koihik/LuaFormatter](https://github.com/Koihik/LuaFormatter) |
| markdownfmt | [https://github.com/shurcooL/markdownfmt](https://github.com/shurcooL/markdownfmt) |
| markdownlint | [https://github.com/davidanson/markdownlint](https://github.com/davidanson/markdownlint) |
| markuplint | [https://markuplint.dev](https://markuplint.dev) |
| mdformat | [https://github.com/executablebooks/mdformat](https://github.com/executablebooks/mdformat) |
Expand Down
45 changes: 45 additions & 0 deletions mdsf/src/formatters/markdownfmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use super::execute_command;
use crate::{error::MdsfError, runners::CommandType};

#[inline]
pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = CommandType::Direct("markdownfmt").build();

cmd.arg("-w").arg(file_path);

execute_command(cmd, file_path)
}

#[cfg(test)]
mod test_markdownfmt {
use crate::{formatters::setup_snippet, fttype::get_file_extension};

#[test_with::executable(markdownfmt)]
fn it_should_format_html() {
let input = "# hello w world

this text has weird spacing

- first
* second";

let expected_output = "hello w world
=============

this text has weird spacing

- first
- second
";

let snippet = setup_snippet(input, &get_file_extension("markdown"))
.expect("it to create a snippet file");

let output = super::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");

assert_eq!(expected_output, output);
}
}
7 changes: 7 additions & 0 deletions mdsf/src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ mod kulala_fmt;
mod leptosfmt;
mod liquidsoap_prettier;
mod luaformatter;
mod markdownfmt;
mod markdownlint;
mod markuplint;
mod mdformat;
Expand Down Expand Up @@ -741,6 +742,10 @@ pub enum Tooling {
#[serde(rename = "luaformatter")]
LuaFormatter,

#[doc = "https://github.com/shurcooL/markdownfmt"]
#[serde(rename = "markdownfmt")]
Markdownfmt,

#[doc = "https://github.com/davidanson/markdownlint"]
#[serde(rename = "markdownlint")]
Markdownlint,
Expand Down Expand Up @@ -1182,6 +1187,7 @@ impl Tooling {
Self::LeptosFmt => leptosfmt::run(snippet_path),
Self::LiquidsoapPrettier => liquidsoap_prettier::run(snippet_path),
Self::LuaFormatter => luaformatter::run(snippet_path),
Self::Markdownfmt => markdownfmt::run(snippet_path),
Self::Markdownlint => markdownlint::run(snippet_path),
Self::Markuplint => markuplint::run(snippet_path),
Self::MdFormat => mdformat::run(snippet_path),
Expand Down Expand Up @@ -1370,6 +1376,7 @@ impl AsRef<str> for Tooling {
Self::LeptosFmt => "leptosfmt",
Self::LiquidsoapPrettier => "liquidsoap-prettier",
Self::LuaFormatter => "luaformatter",
Self::Markdownfmt => "markdownfmt",
Self::Markdownlint => "markdownlint",
Self::Markuplint => "markuplint",
Self::MdFormat => "mdformat",
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.2.7/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@
"type": "string",
"enum": ["luaformatter"]
},
{
"description": "https://github.com/shurcooL/markdownfmt",
"type": "string",
"enum": ["markdownfmt"]
},
{
"description": "https://github.com/davidanson/markdownlint",
"type": "string",
Expand Down
Loading