Markdown formatting plugin for dprint.
This uses the pulldown-cmark parser for markdown.
Markdown code formatting plugin for dprint.
License: MIT License
Markdown formatting plugin for dprint.
This uses the pulldown-cmark parser for markdown.
Given the following text, it should format as is:
````text
# std/io
## readLines
```ts
import * as path from "https://deno.land/std/path/mod.ts";
## Rest of the file
````
Would be good to make this configurable and probably the default.
Version 0.9.5:
Example:
1. Test ![image is](./wrongly/assumed_to_be_link_reference.png)
You can try it here: https://dprint.dev/playground/#code/FDCMDoAIBUFMGcAukCEBtAlgWwIYHNZIN4BdACnAHoB3AJwHsA7PAGwE9Kd54BXLWACYB9RPSEAjWEJYZGAayG1YAM1hLGAY1jgADswCUQA/language/markdown
it yields:
Line 3, column 63: Unexpected token `)` while parsing link reference definition.
e_link_reference.png)
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.
@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.
Example:
Column Title|Test|Asd
--:|--|:---:
Testing|asdff|tesd
This is a test|asd|tes
Output:
| Column Title | Test | Asd |
| -------------: | ----- | :--: |
| Testing | asdff | tesd |
| This is a test | asd | tes |
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
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.
Would be ok if the list was indented correctly:
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
```
<!-- prettier-ignore-start -->
```js
Look at the source for this: `test`
. It's formatted without the spaces which causes it to lose the backticks.
`test`
test
<-- goes toAlso: testing `this` out
## Comparison to Node.js
- Deno does not use `npm`
- It uses modules referenced as URLs or file paths
- Uses "ES Modules" and does not support `require()`. Third party modules are
imported via URLs:
\`\`\`javascript
import * as log from "https://deno.land/std/log/mod.ts";
\`\`\`
testβ`cargo install gvm`
For example, the following:
> Testing this out
> Testing
>
> Testing
> Testing asdf
Should format as-is.
There's multiple ways to represent strong and emphasis text decorations:
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#emphasis
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
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.
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` |
Kind of strange. Look into it.
~~v8~~ _can't implement_
Waiting on dprint/dprint#237
The following should format as-is:
1. test
2. test
3. test
```shell
test
```
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.
- **--allow-net=\<allow-net\>** Allow network access. You can specify an
optional, comma separated list of domains to provide a allow-list of allowed
domains.
From denoland/deno#10185
Why?
## Supported Builtins
- [ ] assert
- [x] node globals _partly_
Formats as:
## Supported Builtins
- [ ]
assert
- [x]
node globals _partly_
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):
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)?
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
.
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.
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.
If you agree and provide some guidance around how to implement this, I'm happy to take a stab at it.
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)
cc @shanloid
So that they prefer to stay on the same line
- `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" ] }
\`\`\`
Might as well π
"textWrapping": "maintain" | "force" | "never"
From #33. I think perhaps the parser is not parsing this as a table for some reason.
For example:
testingΒ testingΒ testingΒ testingΒ testingΒ `code`Β testingΒ testingΒ testingΒ testingΒ `code`Β testing
Example:
* Testing
[test]: asdf
Outputs:
* Testing
The following should format as-is:
- Testing
- Other
* Testing
* Other
This is important because changing the deliminator starts a new list. See https://spec.commonmark.org/0.29/#loose
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
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.
> This is an unstable feature. Learn more about
> [unstable features](./stability.md).
By default the namespace is not available in worker scope.
https://github.com/littletof/prettyBenching/blob/696e3541fc5a52e35776f93c704ddae31a1a3d44/README.md
thread 'test_specs' panicked at 'attempt to subtract with overflow', src\parsing\parse.rs:638:32
Problem line:
let dashes_count = column_width - (if has_left_colon { 1 } else { 0 }) - (if has_right_colon { 1 } else { 0 });
If the tag doesn't match anything, then the user should be able to say to format with the original string instead. This will avoid a needless copy.
Input/Output:
Expected:
A list should not be deleted
As title.
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
---
Input:
foo<space><space>\
bar<space><space>\
baz
Output:
foo
bar
baz
Expected output:
foo<space>\
bar<space>\
baz
Input:
foo<space><space>
bar<space><space>
baz
Output:
foo<space>
bar<space>
baz
Expected output:
foo<space><space>
bar<space><space>
baz
ref: denoland/deno#9727
I thought it would be nice to convert code blocks to be fenced automatically, but in practice it can be annoying since some markdown renders have different indentation requirements.
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...
}
```
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.