mdrefine 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/rules.md CHANGED
@@ -4,7 +4,8 @@ A rule is either a **style** rule or a **problem** rule. A style rule checks how
4
4
  something is written and proposes an edit, which `format` applies and `lint`
5
5
  reports. A problem rule reports a defect that has no single correct repair, and
6
6
  never edits. `format` applies an edit only when the document still means the
7
- same afterwards; see [how it works](design.md#safety-model).
7
+ same afterwards, and never in text that the parser reads where renderers read a
8
+ list; see [how it works](design.md#safety-model).
8
9
 
9
10
  Enable and configure rules under `rules` in the
10
11
  [configuration](configuration.md#rules-and-severity). `npx mdtools rules` lists
@@ -165,7 +166,9 @@ Writes the type of a GitHub alert in capitals. The renderers accept any case for
165
166
  the five types `NOTE`, `TIP`, `IMPORTANT`, `WARNING`, and `CAUTION`, and their
166
167
  documentation spells them in capitals. Other types are not alerts there and are
167
168
  left as written, and so is a marker written with an escape or a character
168
- reference, such as `\[!note]`.
169
+ reference, such as `\[!note]`. So is a marker that GitHub shows as text: one in
170
+ a block quote inside another quote or a list, one followed by text on its line,
171
+ and one with nothing below it in the quote.
169
172
 
170
173
  Before:
171
174
 
@@ -242,7 +245,9 @@ label shows its target as text, and a note embed is not the same thing as a
242
245
  Markdown image. A new wikilink decodes percent escapes, because Obsidian takes
243
246
  its text as the note's name: `[x](My%20Note.md)` becomes `[[My Note.md|x]]`. A
244
247
  destination that does not decode, or whose name would hold `|`, `[`, `]`, `#`,
245
- or `^`, stays as written.
248
+ or `^`, stays as written. In a table cell, a `|` that the rule writes, between a
249
+ new wikilink's target and label or in a new Markdown label, is escaped as `\|`,
250
+ because one that is not escaped ends the cell.
246
251
 
247
252
  With `"style": "markdown"`, before:
248
253
 
@@ -290,11 +295,14 @@ only when the new destination leads to the same file and fragment.
290
295
  A relative path also gets `./` when it would otherwise name a different file at
291
296
  the vault's root. A destination that already has the configured spelling keeps
292
297
  its percent-encoding; a new path encodes `%` and `#`, so that it names the same
293
- file. Absolute filesystem paths are never written. These are left as written: a
294
- wikilink without a label, whose target is also its visible text; reference
295
- definitions, which are checked but not rewritten; autolinks; and links whose
296
- target is uncertain because a directory could not be read or the workspace root
297
- is only part of a vault (see [Obsidian
298
+ file, and in a table cell writes a `|` in a name as `\|`, because one that is
299
+ not escaped ends the cell. In a wikilink only the destination changes: the `|`
300
+ or `\|` after it, the label, and an embed's size stay as written. Absolute
301
+ filesystem paths are never written. These are left as written: a wikilink
302
+ without a label, whose target is also its visible text; reference definitions,
303
+ which are checked but not rewritten; autolinks; and links whose target is
304
+ uncertain because a directory could not be read or the workspace root is only
305
+ part of a vault (see [Obsidian
298
306
  vaults](obsidian.md#a-workspace-root-inside-a-vault)).
299
307
 
300
308
  With `{ "style": "relative", "leadingDot": true }` in `README.md`, before:
@@ -674,7 +682,9 @@ or what a comment applies to:
674
682
  blocks of a list item makes the list loose, which changes how it renders.
675
683
  - Front matter and the block below it.
676
684
  - A list that ends inside an HTML comment or another HTML block without its end
677
- marker, which would take the blank line in.
685
+ marker, which would take the blank line in. The same goes for a list whose
686
+ last item ends in a fenced code block without its closing fence: renderers put
687
+ the blank line into the code, although the parser does not.
678
688
  - A heading or list directly below an HTML comment or below a
679
689
  `mdtools-disable-next-line` directive, which apply to the line below them.
680
690
  - The line that opens a callout or alert, such as `> [!NOTE]`, and the block
@@ -682,10 +692,15 @@ or what a comment applies to:
682
692
  - In the Obsidian dialect, a block identifier on a line of its own (`^id`)
683
693
  directly below a heading or list, which Obsidian may attach to the block
684
694
  above.
685
- - Directly below text or a link reference definition: a list or quote whose
686
- first line continues with another list marker, as in `- 2. Step` or `- -`, and
687
- a heading underlined with `===` or `---`. The parser can read such a line
688
- differently there than below a blank line.
695
+ - Directly below text or a link reference definition: a heading underlined with
696
+ `===` or `---`, which the parser can read differently there than below a blank
697
+ line.
698
+ - Text that the parser reads where renderers read a list, such as `- 2. Step`
699
+ directly below text: the list or quote that starts with it, the blocks
700
+ indented below it, and a list after them, which renderers read as part of that
701
+ list, and text on the line directly below the list item or quote that it ends,
702
+ which renderers read as more of it (see [how it
703
+ works](design.md#safety-model)).
689
704
  - Directly below a table that ends in a list item or block quote: text whose
690
705
  second line is a table delimiter row. The parser reads a table there as text,
691
706
  where GitHub reads a table, and a blank line would make it a table for the
@@ -821,9 +836,11 @@ After:
821
836
 
822
837
  A trailing run of `#` in the text of an underlined heading is escaped, so that
823
838
  it is not taken for a closing sequence. Underlined headings of more than one
824
- line, and those inside lists or block quotes, are left as written. On Forgejo
825
- and Gitea, a closing sequence after an attribute block such as `{#id}` stays,
826
- because Gitea before 1.26 reads the block only when the sequence follows it.
839
+ line, those inside lists or block quotes, and one directly below TOML front
840
+ matter, whose lines renderers without TOML front matter read as part of the
841
+ heading, are left as written. On Forgejo and Gitea, a closing sequence after an
842
+ attribute block such as `{#id}` stays, because Gitea before 1.26 reads the block
843
+ only when the sequence follows it.
827
844
 
828
845
  With `setext`, a `#` heading is underlined only where its text can stand on a
829
846
  line of its own as the same heading: at the start of a line of the document, not
@@ -859,6 +876,9 @@ joined line would read differently:
859
876
  marker, which holds an Obsidian callout's title.
860
877
  - Where the joined span needs a different number of backticks than it has, and
861
878
  an earlier run of that many in the same paragraph would pair with them.
879
+ - Where a line inside the span ends with a backslash: where its backticks do not
880
+ pair, as on GitHub after an unpaired longer run, that backslash is a hard line
881
+ break. `style/wrap` keeps such a paragraph as written too.
862
882
 
863
883
  Before:
864
884
 
@@ -941,6 +961,17 @@ These are left as written:
941
961
  another block once inside the item.
942
962
  - A list with a tab in an item's indentation, such as one that Obsidian indented
943
963
  with tabs.
964
+ - A list directly below TOML front matter that cannot interrupt a paragraph: a
965
+ numbered list that does not start at 1, or one whose first item starts with a
966
+ blank line, and the lists that directly follow it. Renderers without TOML
967
+ front matter read the front matter's lines as a paragraph, which such a list
968
+ continues as text. `style/list-marker` and `style/ordered-list` leave these
969
+ lists as written too.
970
+ - A list among the blocks indented below text that the parser reads where
971
+ renderers read a list, such as `2. Two` after an indented code block, or the
972
+ list right after them, and the lists next to it (see [how it
973
+ works](design.md#safety-model)). `style/list-marker` and `style/ordered-list`
974
+ keep their markers too.
944
975
 
945
976
  ## `style/list-marker`
946
977
 
@@ -963,7 +994,9 @@ A bullet list that directly follows another one is a separate list only because
963
994
  its marker differs, so it gets the next marker in the order `-`, `*`, `+`, and
964
995
  the list after that the first one again. A list whose new marker would make a
965
996
  line read as a thematic break, as `+ - -` would with `-`, keeps its markers, and
966
- so do the lists next to it.
997
+ so do the lists next to it. So does a list directly below TOML front matter
998
+ whose first item starts with a blank line, as for
999
+ [`style/list-indent`](#stylelist-indent).
967
1000
 
968
1001
  Before:
969
1002
 
@@ -1010,7 +1043,9 @@ number gets wider or narrower, as from `9.` to `10.`, the item's other lines
1010
1043
  move with its text. A list keeps its numbers where that would move a line into
1011
1044
  or out of an item, as for [`style/list-indent`](#stylelist-indent), and where
1012
1045
  the numbers are written with leading zeros, as in `01.`, or would need more than
1013
- nine digits.
1046
+ nine digits. A list directly below TOML front matter that does not start at 1,
1047
+ or whose first item starts with a blank line, keeps its delimiter and numbers,
1048
+ as for `style/list-indent`.
1014
1049
 
1015
1050
  Before:
1016
1051
 
@@ -1105,8 +1140,9 @@ Text.
1105
1140
  A break is left as written where the new marker would change what the document
1106
1141
  means:
1107
1142
 
1108
- - With `---`, directly below a paragraph or a link reference definition, which
1109
- `---` would underline as a heading.
1143
+ - With `---`, directly below a paragraph, a link reference definition, or
1144
+ display math, which `---` would underline as a heading; GitHub builds display
1145
+ math from a paragraph.
1110
1146
  - On the line of a list item whose marker is the new marker's character, as in
1111
1147
  `- ***` with `---`: `- ---` is one thematic break, not a list item.
1112
1148
  - At the start of a document, with `---`, which would open front matter if a
@@ -1114,6 +1150,10 @@ means:
1114
1150
  start of front matter.
1115
1151
  - With `---`, at the start of a line below a first line of `---` that no line
1116
1152
  closes, which `---` would close as front matter.
1153
+ - Directly below TOML front matter, a break that is or would become `---`,
1154
+ because renderers without TOML front matter read the front matter's lines as a
1155
+ paragraph that `---` underlines as a heading; see the [safety
1156
+ model](design.md#safety-model).
1117
1157
 
1118
1158
  ## `style/trailing-space`
1119
1159
 
@@ -1161,10 +1201,12 @@ span, an image, math, a link's destination, a template tag on one line such as
1161
1201
  `{% data x %}` or `{{ title }}`, and a word longer than the line stay whole and
1162
1202
  can overflow; a code span or an image description written across lines is joined
1163
1203
  onto one, without the spaces and tabs that start its next line, as renderers
1164
- read it. In Obsidian, the text of a link stays whole and is joined onto one line
1165
- too, because Live Preview shows a link whose text spans lines as its Markdown
1166
- source. List markers, block quote markers, and indentation count toward the
1167
- width, a tab up to the next multiple of four columns.
1204
+ read it. On a lazy continuation line, which keeps them, such a code span stays
1205
+ as written, and so does its paragraph. In Obsidian, the text of a link stays
1206
+ whole and is joined onto one line too, because Live Preview shows a link whose
1207
+ text spans lines as its Markdown source. List markers, block quote markers, and
1208
+ indentation count toward the width, a tab up to the next multiple of four
1209
+ columns.
1168
1210
 
1169
1211
  A word that would start a block at the start of a line, such as a list marker,
1170
1212
  `#`, `>`, a run of `-` or `=`, or a table delimiter row such as `|---|`, stays
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdrefine",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Configurable Markdown linting and formatting for CommonMark, GitHub, Forgejo, Gitea, and Obsidian",
5
5
  "keywords": [
6
6
  "markdown",
@@ -120,10 +120,13 @@
120
120
  },
121
121
  "devDependencies": {
122
122
  "@eslint/js": "10.0.1",
123
+ "@types/commonmark": "0.27.10",
123
124
  "@types/node": "22.20.5",
124
125
  "@types/unist": "3.0.3",
126
+ "commonmark": "0.31.2",
125
127
  "eslint": "10.13.0",
126
128
  "fast-check": "4.10.2",
129
+ "markdown-it": "15.0.3",
127
130
  "npm-run-all2": "9.0.3",
128
131
  "prettier": "3.9.10",
129
132
  "typescript": "6.0.3",