Skip to content

Commit 89d0f5b

Browse files
committed
Remove bulletOrderedOther, always use other bullets
Previously, two adjacent lists, which can only be created with markdown by using different bullets, were serialized with the primary bullet, but an empty comment was injected between them. Now, different bullets are always used. Closes GH-56.
1 parent 7f91d06 commit 89d0f5b

File tree

6 files changed

+73
-227
lines changed

6 files changed

+73
-227
lines changed

lib/handle/list.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import {checkBullet} from '../util/check-bullet.js'
99
import {checkBulletOther} from '../util/check-bullet-other.js'
1010
import {checkBulletOrdered} from '../util/check-bullet-ordered.js'
11-
import {checkBulletOrderedOther} from '../util/check-bullet-ordered-other.js'
1211
import {checkRule} from '../util/check-rule.js'
1312

1413
/**
@@ -25,22 +24,12 @@ export function list(node, parent, state, info) {
2524
let bullet = node.ordered ? checkBulletOrdered(state) : checkBullet(state)
2625
/** @type {string} */
2726
const bulletOther = node.ordered
28-
? checkBulletOrderedOther(state)
27+
? bullet === '.'
28+
? ')'
29+
: '.'
2930
: checkBulletOther(state)
30-
const bulletLastUsed = state.bulletLastUsed
31-
let useDifferentMarker = false
32-
33-
if (
34-
parent &&
35-
// Explicit `other` set.
36-
(node.ordered
37-
? state.options.bulletOrderedOther
38-
: state.options.bulletOther) &&
39-
bulletLastUsed &&
40-
bullet === bulletLastUsed
41-
) {
42-
useDifferentMarker = true
43-
}
31+
let useDifferentMarker =
32+
parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false
4433

4534
if (!node.ordered) {
4635
const firstListItem = node.children ? node.children[0] : undefined

lib/join.js

-12
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ function joinDefaults(left, right, parent, state) {
2020
return false
2121
}
2222

23-
// Two lists with the same marker.
24-
if (
25-
left.type === 'list' &&
26-
left.type === right.type &&
27-
Boolean(left.ordered) === Boolean(right.ordered) &&
28-
!(left.ordered
29-
? state.options.bulletOrderedOther
30-
: state.options.bulletOther)
31-
) {
32-
return false
33-
}
34-
3523
// Join children of a list or an item.
3624
// In which case, `parent` has a `spread` field.
3725
if ('spread' in parent && typeof parent.spread === 'boolean') {

lib/types.js

+23-33
Original file line numberDiff line numberDiff line change
@@ -299,44 +299,34 @@
299299
* Configuration (optional).
300300
* @property {'*' | '+' | '-' | null | undefined} [bullet='*']
301301
* Marker to use for bullets of items in unordered lists (default: `'*'`).
302-
* @property {'*' | '+' | '-' | null | undefined} [bulletOther]
303-
* Marker to use in certain cases where the primary bullet doesn’t work
304-
* (default: depends).
305302
*
306303
* There are three cases where the primary bullet cannot be used:
307304
*
308-
* * When three list items are on their own, the last one is empty, and
309-
* `bullet` is also a valid `rule`: `* - +`.
310-
* This would turn into a thematic break if serialized with three primary
311-
* bullets.
312-
* As this is an edge case unlikely to appear in normal markdown, the
313-
* last list item will be given a different bullet.
314-
* * When a thematic break is the first child of one of the list items, and
315-
* `bullet` is the same character as `rule`: `- ***`.
316-
* This would turn into a single thematic break if serialized with
317-
* primary bullets.
318-
* As this is an edge case unlikely to appear in normal markdown this
319-
* markup is always fixed, even if `bulletOther` is not passed
320-
* * When two unordered lists appear next to each other: `* a\n- b`.
321-
* CommonMark sees different bullets as different lists, but several
322-
* markdown parsers parse it as one list.
323-
* To solve for both, we instead inject an empty comment between the two
324-
* lists: `* a\n<!---->\n* b`, but if `bulletOther` is given explicitly,
325-
* it will be used instead
305+
* * when three or more list items are on their own, the last one is empty,
306+
* and `bullet` is also a valid `rule`: `* - +`; this would turn into a
307+
* thematic break if serialized with three primary bullets; `bulletOther`
308+
* is used for the last item
309+
* * when a thematic break is the first child of a list item and `bullet` is
310+
* the same character as `rule`: `- ***`; this would turn into a single
311+
* thematic break if serialized with primary bullets; `bulletOther` is used
312+
* for the item
313+
* * when two unordered lists appear next to each other: `* a\n- b`;
314+
* `bulletOther` is used for such lists
315+
* @property {'*' | '+' | '-' | null | undefined} [bulletOther]
316+
* Marker to use in certain cases where the primary bullet doesn’t work
317+
* (default: `'-'` when `bullet` is `'*'`, `'*'` otherwise).
318+
*
319+
* Cannot be equal to `bullet`.
326320
* @property {'.' | ')' | null | undefined} [bulletOrdered='.']
327321
* Marker to use for bullets of items in ordered lists (default: `'.'`).
328-
* @property {'.' | ')' | null | undefined} [bulletOrderedOther]
329-
* Marker to use in certain cases where the primary bullet for ordered items
330-
* doesn’t work (default: none).
331-
*
332-
* There is one case where the primary bullet for ordered items cannot be used:
333-
*
334-
* * When two ordered lists appear next to each other: `1. a\n2) b`.
335-
* CommonMark added support for `)` as a marker, but other markdown
336-
* parsers do not support it.
337-
* To solve for both, we instead inject an empty comment between the two
338-
* lists: `1. a\n<!---->\n1. b`, but if `bulletOrderedOther` is given
339-
* explicitly, it will be used instead
322+
*
323+
* There is one case where the primary bullet for ordered items cannot be
324+
* used:
325+
*
326+
* * when two ordered lists appear next to each other: `1. a\n2) b`; to
327+
* solve
328+
* that, `'.'` will be used when `bulletOrdered` is `')'`, and `'.'`
329+
* otherwise
340330
* @property {boolean | null | undefined} [closeAtx=false]
341331
* Whether to add the same number of number signs (`#`) at the end of an ATX
342332
* heading as the opening sequence (default: `false`).

lib/util/check-bullet-ordered-other.js

-39
This file was deleted.

readme.md

+17-32
Original file line numberDiff line numberDiff line change
@@ -314,50 +314,35 @@ The following fields influence how markdown is serialized.
314314
Marker to use for bullets of items in unordered lists (`'*'`, `'+'`, or `'-'`,
315315
default: `'*'`).
316316

317+
There are three cases where the primary bullet cannot be used:
318+
319+
* when three or more list items are on their own, the last one is empty, and
320+
`bullet` is also a valid `rule`: `* - +`; this would turn into a thematic
321+
break if serialized with three primary bullets; `bulletOther` is used for
322+
the last item
323+
* when a thematic break is the first child of a list item and `bullet` is the
324+
same character as `rule`: `- ***`; this would turn into a single thematic
325+
break if serialized with primary bullets; `bulletOther` is used for the
326+
item
327+
* when two unordered lists appear next to each other: `* a\n- b`;
328+
`bulletOther` is used for such lists
329+
317330
###### `options.bulletOther`
318331

319332
Marker to use in certain cases where the primary bullet doesn’t work (`'*'`,
320-
`'+'`, or `'-'`, default: depends).
333+
`'+'`, or `'-'`, default: `'-'` when `bullet` is `'*'`, `'*'` otherwise).
321334

322-
There are three cases where the primary bullet cannot be used:
323-
324-
* When three list items are on their own, the last one is empty, and `bullet`
325-
is also a valid `rule`: `* - +`.
326-
This would turn into a thematic break if serialized with three primary
327-
bullets.
328-
As this is an edge case unlikely to appear in normal markdown, the last list
329-
item will be given a different bullet.
330-
* When a thematic break is the first child of one of the list items, and
331-
`bullet` is the same character as `rule`: `- ***`.
332-
This would turn into a single thematic break if serialized with primary
333-
bullets.
334-
As this is an edge case unlikely to appear in normal markdown this markup is
335-
always fixed, even if `bulletOther` is not passed
336-
* When two unordered lists appear next to each other: `* a\n- b`.
337-
CommonMark sees different bullets as different lists, but several markdown
338-
parsers parse it as one list.
339-
To solve for both, we instead inject an empty comment between the two lists:
340-
`* a\n<!---->\n* b`, but if `bulletOther` is given explicitly, it will be
341-
used instead
335+
Cannot be equal to `bullet`.
342336

343337
###### `options.bulletOrdered`
344338

345339
Marker to use for bullets of items in ordered lists (`'.'` or `')'`, default:
346340
`'.'`).
347341

348-
###### `options.bulletOrderedOther`
349-
350-
Marker to use in certain cases where the primary bullet for ordered items
351-
doesn’t work (`'.'` or `')'`, default: none).
352-
353342
There is one case where the primary bullet for ordered items cannot be used:
354343

355-
* When two ordered lists appear next to each other: `1. a\n2) b`.
356-
CommonMark added support for `)` as a marker, but other markdown parsers
357-
do not support it.
358-
To solve for both, we instead inject an empty comment between the two lists:
359-
`1. a\n<!---->\n1. b`, but if `bulletOrderedOther` is given explicitly, it
360-
will be used instead
344+
* when two ordered lists appear next to each other: `1. a\n2) b`; to solve
345+
that, `'.'` will be used when `bulletOrdered` is `')'`, and `'.'` otherwise
361346

362347
###### `options.closeAtx`
363348

0 commit comments

Comments
 (0)