Coder Social home page Coder Social logo

dprint-plugin-markdown's Introduction

dprint-plugin-markdown

CI

Markdown formatting plugin for dprint.

This uses the pulldown-cmark parser for markdown.

dprint-plugin-markdown's People

Contributors

bartlomieju avatar basaran avatar disrupted avatar dsherret avatar ifiokjr avatar joscha avatar kevgo avatar rivy avatar satyarohith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dprint-plugin-markdown's Issues

additional fenced code block formatting

Hello,

Apologies if this is the wrong place to ask this question. Is there anyway to extend the code formatting? I noticed dprint can format fenced js and css. I'm more specifically trying to format fenced svelte, vue and react.

πŸ› Parsing bug for combination of blockquote containing a bullet-list and following text

@dsherret , Hello! πŸ‘‹πŸ»

I just ran into what appears to be a parsing bug and wanted to let you know about it.

Describe the bug

C:>dprint --version
dprint 0.18.2

C:>cat .dprint.json
{
	"$schema": "https://dprint.dev/schemas/v0.json",
	"projectType": "openSource",
	"incremental": true,
	"indentWidth": 2,
	"lineWidth": 100,
	"useTabs": true,
	"typescript": {
		// ref: <https://dprint.dev/plugins/typescript/config>
		"deno": true,
		// * customize preferences (overrides of some Deno formatting choices)
		// ref: <https://github.com/dprint/dprint-plugin-typescript/blob/44b6cf562e511a308f4a7183dc98fb19cdf21d07/src/configuration/builder.rs#L51>
		// ref: <https://github.com/denoland/deno/blob/f46e39c5c5/cli/tools/fmt.rs#L311>
		"lineWidth": 100,
		"preferSingleLine": true,
		"quoteStyle": "preferSingle",
		//
		"ignoreNodeCommentText": "dprint-ignore", // from Deno's "deno-fmt-ignore"
		"ignoreFileCommentText": "dprint-ignore-file", // from Deno's "deno-fmt-ignore-file"
		"memberExpression.linePerExpression": true,
		"memberExpression.preferSingleLine": true,
		"module.sortImportDeclarations": "caseInsensitive",
		"module.sortExportDeclarations": "caseInsensitive"
	},
	"json": { "preferSingleLine": true },
	"markdown": { "textWrap": "always", "lineWidth": 99999 },
	"prettier": { "printWidth": 100, "singleQuote": true, "tabWidth": 2 },
	"rustfmt": {},
	"includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,mkd,rs,yaml,yml}"],
	"excludes": [
		".history",
		".changelog/*.tpl.*",
		"CHANGELOG{,.}*",
		"**/node_modules",
		"**/*-lock.json",
		"**/target",
		"**/vendor"
	],
	"plugins": [
		// ref: <https://plugins.dprint.dev>
		// "https://plugins.dprint.dev/typescript-0.51.0.wasm",
		// "https://plugins.dprint.dev/json-0.12.3.wasm",
		// "https://plugins.dprint.dev/markdown-0.9.5.wasm",
		// "https://plugins.dprint.dev/toml-0.4.1.wasm",
		// // ref: <https://github.com/dprint/dprint-plugin-rustfmt/releases>
		// "https://plugins.dprint.dev/rustfmt-0.4.0.exe-plugin@c6bb223ef6e5e87580177f6461a0ab0554ac9ea6b54f78ea7ae8bf63b14f5bc2",
		// // ref: <https://github.com/dprint/dprint-plugin-prettier/releases>
		// "https://plugins.dprint.dev/prettier-0.2.2.exe-plugin@63b06beba3acd51e6d23379c47db342a1a24f3d88f3c52a775e2db3426124582"
		"https://plugins.dprint.dev/typescript-0.59.0.wasm",
		"https://plugins.dprint.dev/json-0.13.1.wasm",
		"https://plugins.dprint.dev/markdown-0.11.1.wasm",
		"https://plugins.dprint.dev/toml-0.5.2.wasm",
		// ref: <https://github.com/dprint/dprint-plugin-rustfmt/releases>
		"https://plugins.dprint.dev/rustfmt-0.4.0.exe-plugin@c6bb223ef6e5e87580177f6461a0ab0554ac9ea6b54f78ea7ae8bf63b14f5bc2",
		// ref: <https://github.com/dprint/dprint-plugin-prettier/releases>
		"https://plugins.dprint.dev/prettier-0.3.0.exe-plugin@c6c227493e655717b5f3d9c811ba576c82f2b060317bb233c6ec014958fbee19"
	]
}

Input Code

> - Officia exercitation voluptate ea esse do culpa consequat amet consectetur mollit dolor tempor.
>
> ...

Actual Output

An error occurs during reformatting...

[ERROR] Error formatting text. Line 4, column 1: Unexpected token `>` while parsing link reference definition.

  >
  ~

Let me know if I can be of help tracking down the source of the issue.

Maintain blank line for list inside list

1. Get [VS Community 2019](https://www.visualstudio.com/downloads/) with
   "Desktop development with C++" toolkit and make sure to select the following
   required tools listed below along with all C++ tools.

   - Visual C++ tools for CMake
   - Windows 10 SDK (10.0.17763.0)
   - Testing tools core features - Build Tools
   - Visual C++ ATL for x86 and x64
   - Visual C++ MFC for x86 and x64
   - C++/CLI support
   - VC++ 2015.3 v14.00 (v140) toolset for desktop

Add configuration options that allow (partial) enforcement of the semantic line breaks specification

I've recently come across https://sembr.org/ and I am a big fan so far.

In our markdown documents, we are already trying to follow the "one sentence per line" rule.
This makes our Git diffs more readable because natural language tends to be edited on a sentence basis (i.e. rewrite a single sentence, split it in two, merge two into one, etc).

This behaviour is captured in requirement 4 of sembr.

I haven't looked into the parser and formatter yet but it would be amazing if dprint would make it easy to have markdown documents follow sembr.

Handle incorrectly indented list with sub code blocks more gracefully

https://dprint.dev/playground/#code/MTAEGUFMGMBcEsD2A7AsAKA6UBaUAZeAZ1lHlkgFtQBGDLbUABQEMAnFgcw4AcALUNBQVkpFqSItKkMsgAmkUeKTJQLIqAA2xUuSq166RqAAGZhtiELQAI02JoAazUSpM+PMWxlKNRu0kZBTUdEaMZiaGxnjgAK52OkH6AIJRxszsXLwCQqJeLqCS0rIKSgi+6oXxAbrBoKmYYcYRFoxWMnYOzuKFbiVePqqVRNWJetQN6abmjcYAsohsMjyZ3Cz8gsL5PUXunmUqflpjdaGtLU2b1p1OBbv9BxX+J-qhzTMMeISB46AATGlsKwOGsNrkRGJXMUPKVvOUhs8fnUAbNwjNjO1bPZbjs+jCBvCjjUktQUe8TEA/language/markdown

Would be ok if the list was indented correctly:

https://dprint.dev/playground/#code/MTAEGUFMGMBcEsD2A7AsAKAwWlAGXgM6yjyyQC2oAjBhqKAAoCGATkwOZsAOAFqNCjLJiTYgSblIJZABNIw0UmSgmBUABtCxUhWq109AAbG6-RHNAAjdYmgBrFWIlT4s+bEUoVazURJlKGgNQY0N9ehxwAFdrLX9dAEFw+kZWDm4+AWF3R1BxSWk5BQQvVTyY320A0CTMYKMTerMLa1sHUTznQvdPZTKCCridSlqUkMbTAFlEFikuNM4mXjNs4Vz8lzdipW8NIeqg01DTARabe3Wu1yKPEr6ffd0ghrC6nHw-YdAAJmTmNkWyyyQhETgK1x6d12lXilF+dReJ3MUlaFw6G2621KD0+1XhLyAA/language/markdown

Input Code

## Section

  - List item 1

    Paragraph content at same indentation as list item 1

    ```
    code block at same indentation as list item 1
    ```

    - Sublist item A

      Paragraph content at same indentation as sublist item A

      ```
      code block at same indentation as sublist item A
      ```

    More paragraph content at same indentation as list item 1

    ```
    code block at same indentation as list item 1
    ```

  - List item 2

    Paragraph content at same indentation as list item 2

    ```
    code block at same indentation as list item 2
    ```

Output code

## Section

- List item 1

  Paragraph content at same indentation as list item 1

      ```
      code block at same indentation as list item 1
      ```

  - Sublist item A

    Paragraph content at same indentation as sublist item A

        ```
        code block at same indentation as sublist item A
        ```

  More paragraph content at same indentation as list item 1

      ```
      code block at same indentation as list item 1
      ```

- List item 2

  Paragraph content at same indentation as list item 2

      ```
      code block at same indentation as list item 2
      ```

Desired Output

## Section

- List item 1

  Paragraph content at same indentation as list item 1

  ```
  code block at same indentation as list item 1
  ```

  - Sublist item A

    Paragraph content at same indentation as sublist item A

    ```
    code block at same indentation as sublist item A
    ```

  More paragraph content at same indentation as list item 1

  ```
  code block at same indentation as list item 1
  ```

- List item 2

  Paragraph content at same indentation as list item 2

  ```
  code block at same indentation as list item 2
  ```

Need newline after table

Try this:

## Verbs

The following verbs are supported:

| Verb  | Meaning                                                        |
| ----- | -------------------------------------------------------------- |
| `%`   | print a literal percent                                        |
| `t`   | evaluate arg as boolean, print `true` or `false`               |
| `b`   | eval as number, print binary                                   |
| `c`   | eval as number, print character corresponding to the codePoint |
| `o`   | eval as number, print octal                                    |
| `x X` | print as hex (ff FF), treat string as list of bytes            |
| `e E` | print number in scientific/exponent format 1.123123e+01        |
| `f F` | print number as float with decimal point and no exponent       |
| `g G` | use %e %E or %f %F depending on size of argument               |
| `s`   | interpolate string                                             |
| `T`   | type of arg, as returned by `typeof`                           |
| `v`   | value of argument in 'default' format (see below)              |
| `j`   | argument as formatted by `JSON.stringify`                      |

## Width and Precision

Configuration for changing ignore comment text

Right now ignore comments have the text "dprint-ignore", "dprint-ignore-start" and "dprint-ignore-end", but this should be configurable.

It is being really lazy now and using regex, but that should be removed and replaced with character comparisons.

Excess cells in a table row disappear in output

Input

| name                                 |                   description                              |
| ------------------------ | ------------------------------ |
| `get(key: name): string | null` | Get the value of the string.             |

Expected output

| name                            | description                  |
| ------------------------------- | ---------------------------- |
| `get(key: name): string | null` | Get the value of the string. |

Actual output

| name                    | description |
| ----------------------- | ----------- |
| `get(key: name): string | null`       |

additional indentation for task lists

Thanks for dprint! It reduces the time to format my knowledge base consisting of ~1600 Markdown files from 87 seconds (Prettier) to 0.2 seconds! πŸ’₯

I noticed different indentation behavior for task lists when always wrapping text. Prettier formats them with 6 spaces of indentation. This separates the check boxes visually from the text (playground example):

- [x] an issue with a very very long title that flows into subsequent lines in
      order to demonstrate how Prettier uses six spaces of indentation for task
      lists
- [ ] another issue

Dprint indents task lists with only two spaces. This somewhat hides the checkboxes in the text (playground example):

- [x] an issue with a very very long title that flows into subsequent lines in
  order to demonstrate how dprint uses only two spaces of indentation for task
  lists
- [ ] another issue

Both styles work but I think the Prettier version looks nicer and is a bit more ergonomic. How do you feel about matching Prettier's formatting of task lists in dprint? If you agree and provide some guidance, I'm happy to take a stab at implementing this.

Support numbered markdown lists with repeated numbers

1. Item
1. Item
1. Item

Is currently reformatted as:

1. Item
2. Item
3. Item

However, both render the same (see the source of this):

  1. Item
  2. Item
  3. Item

The form that repeats the same number can be more preferable, as it's easier to see what changed in diffs and add/remove items without modifying every other list item after it.

Could a new setting be added to prefer this form, or maintain the numbering (if it's consistent)?

`proseWrap: always` should not wrap link title

Thanks for dprint! I love it and hope it takes over the formatting world and we never have to wait for Prettier again! I would like to propose to never wrap links even if textWrap is set to always.

Details

Prettier never wraps links even if their title is longer than 80 characters. In this example in the Prettier playground the link is only on line 2. Dprint currently wraps links: in the equivalent example in the dprint playground the link ends up on lines 2-3 in the formatted output.

Rationale

Keeping links on a single line makes processing markdown text line by line so much easier, for example grepping with regexes, showing only matching lines in search results, or when syntax highlighting. I'd also argue that keeping the link on one line improves readability of the formatted output since links could be considered a logical unit in the content. It is easier to read Markdown when links stay "together". This change wouldn't affect HTML rendered from the Markdown.

Implementation

If you agree and provide some guidance around how to implement this, I'm happy to take a stab at it.

quadruple backtick sections in markdown are outdented

Even though marked ignored, this markdown fails to stay in format:

* some list
<!-- dprint-ignore-start -->

         ````md
         :rocket:[censored]
         ```ini
         DEBUG=true
         ```
         ````
<!-- dprint-ignore-end -->

it seems to receive a diff on fmt:

Canva__auto_format__8

text code blocks are reformatted

Markdown 0.10.0

expected:

```text
                                          β”‚
                                        HTTP                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   component   β”œβ”€β”
β”‚                                         β”‚                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                         β–Ό                                       β”‚
β”‚                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                             β”‚
β”‚                               β”‚                   β”‚                             β”‚
β”‚                               β”‚    Blablabla      β”‚                             β”‚
β”‚                               β”‚                   β”‚                             β”‚
β”‚                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                             β”‚
β”‚                                         β”‚                                       β”‚
β”‚                                         β”‚                                       β”‚
β”‚                                    helloWorld()                                 β”‚
β”‚                                         β”‚                                       β”‚
β”‚                                         β–Ό                                       β”‚
β”‚                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                             β”‚
β”‚                               β”‚                   β”‚                             β”‚
β”‚                               β”‚       Bla         β”‚                             β”‚
β”‚                               β”‚                   β”‚                             β”‚
β”‚                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                             β”‚
β”‚                                         β”‚                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                          β–Ό
```

to stay as-is. Instead the first pipe is shifted (spaces collapsed):

```text
β”‚
                                        HTTP                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   component   β”œβ”€β”
β”‚                                         β”‚                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                         β–Ό                                       β”‚
β”‚                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                             β”‚
β”‚                               β”‚                   β”‚                             β”‚
β”‚                               β”‚    Blablabla      β”‚                             β”‚
β”‚                               β”‚                   β”‚                             β”‚
β”‚                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                             β”‚
β”‚                                         β”‚                                       β”‚
β”‚                                         β”‚                                       β”‚
β”‚                                    helloWorld()                                 β”‚
β”‚                                         β”‚                                       β”‚
β”‚                                         β–Ό                                       β”‚
β”‚                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                             β”‚
β”‚                               β”‚                   β”‚                             β”‚
β”‚                               β”‚       Bla         β”‚                             β”‚
β”‚                               β”‚                   β”‚                             β”‚
β”‚                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                             β”‚
β”‚                                         β”‚                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                          β–Ό
```

(first line)

see https://dprint.dev/playground/#code/AYguFMA9QKAAgYpyWrSwQKT3T36ASAKoQAp5qAwpIACkNtd9gCKQIzX1vsef2A8pF34CSkiAMYB7ALYAHEQDtw00IkA4pFQYwM5DRvWbkgFFI+dQBikcLNp3mUgHtILNhKdu5WBxg7T3Xbm2Y+J3P5N4AQgA2AIYARmGRoZj+SH5xdl6JdmopiPrO9MYpCeme+W5phejeJb7F5XAAFuDBwSIA6iIATsEAJgAUAJTleVVJAxVlQ9ZDqSP+Tlk0TLmVucnzkz6TITEFif3+K7i7tts+mTM0OVsL4-vpWMcndzz3j6fY44iWMCDAQA/language/markdown

cc @shanloid

Need newline before codeblock after text in list

- `options['--']` - when true, populate `parsedArgs._` with everything before
  the `--` and `parsedArgs['--']` with everything after the `--`. Here's an
  example:
  \`\`\`ts
  // $ deno run example.ts -- a arg1
  import { parse } from "https://deno.land/std/flags/mod.ts";
  console.dir(parse(Deno.args, { "--": false }));
  // output: { _: [ "a", "arg1" ] }
  console.dir(parse(Deno.args, { "--": true }));
  // output: { _: [], --: [ "a", "arg1" ] }
  \`\`\`

Handle non-breaking spaces

For example:

testingΒ testingΒ testingΒ testingΒ testingΒ `code`Β testingΒ testingΒ testingΒ testingΒ `code`Β testing

Incorrectly trims whitespace

Source:

`` Edit post `slug-here` ``

Expected:

`` Edit post `slug-here` ``

Which gets rendered as:

<p><code>Edit post `slug-here`</code></p>

Actual:

``Edit post `slug-here` ``

Which gets rendered as:

<p><code>Edit post `slug-here` </code></p>

Which contains a trailing whitespace in a code block, which then looks incorrect when displayed.

Ref: denoland/deno#10313

Ignore file directive works in the whole file

When working on a blog post @lucacasonato discovered that ignore directive for the file (in our case deno-fmt-ignore-file) makes dprint to ignore file if it's placed anywhere in the file.

Ideally this directive should only have effect if it's placed on the first line.

Need newline after block quotes

> This is an unstable feature. Learn more about
> [unstable features](./stability.md).

By default the namespace is not available in worker scope.

meta information not retained in shape without new line

Input

---
title: File System APIs
category: Runtime
weight: 2
--- 

^-- no new line at the end.

Output

---

## title: File System APIs category: Runtime weight: 2

Expected Behaviour

---
title: File System APIs
category: Runtime
weight: 2
---

Extra blank line added after dprint-ignore comment when file is CRLF

Weird:

Testing:
<!-- dprint-ignore -->
```json
{
  "extends": "https://dprint.dev/path/to/config/file.v1.json",
  // ...omitted...
}
```

Formats as:

Testing:

<!-- dprint-ignore -->


```json
{
  "extends": "https://dprint.dev/path/to/config/file.v1.json",
  // ...omitted...
}
```

Reference links after a table are swallowed

Input

# Test

| Company                    |
| -------------------------- |
| [GitHub][github]           |
| [Amazon Web Services][aws] |

[github]: https://github.com
[aws]: https://aws.amazon.com

A paragraph.

Expected Output

# Test

| Company                    |
| -------------------------- |
| [GitHub][github]           |
| [Amazon Web Services][aws] |

[github]: https://github.com
[aws]: https://aws.amazon.com

A paragraph.

Actual Output

# Test

| Company                    |
| -------------------------- |
| [GitHub][github]           |
| [Amazon Web Services][aws] |

A paragraph.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.