Skip to content

Commit

Permalink
Remove bulletOrderedOther, always use other bullets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wooorm committed Jul 10, 2023
1 parent 7f91d06 commit 89d0f5b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 227 deletions.
21 changes: 5 additions & 16 deletions lib/handle/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import {checkBullet} from '../util/check-bullet.js'
import {checkBulletOther} from '../util/check-bullet-other.js'
import {checkBulletOrdered} from '../util/check-bullet-ordered.js'
import {checkBulletOrderedOther} from '../util/check-bullet-ordered-other.js'
import {checkRule} from '../util/check-rule.js'

/**
Expand All @@ -25,22 +24,12 @@ export function list(node, parent, state, info) {
let bullet = node.ordered ? checkBulletOrdered(state) : checkBullet(state)
/** @type {string} */
const bulletOther = node.ordered
? checkBulletOrderedOther(state)
? bullet === '.'
? ')'
: '.'
: checkBulletOther(state)
const bulletLastUsed = state.bulletLastUsed
let useDifferentMarker = false

if (
parent &&
// Explicit `other` set.
(node.ordered
? state.options.bulletOrderedOther
: state.options.bulletOther) &&
bulletLastUsed &&
bullet === bulletLastUsed
) {
useDifferentMarker = true
}
let useDifferentMarker =
parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false

if (!node.ordered) {
const firstListItem = node.children ? node.children[0] : undefined
Expand Down
12 changes: 0 additions & 12 deletions lib/join.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ function joinDefaults(left, right, parent, state) {
return false
}

// Two lists with the same marker.
if (
left.type === 'list' &&
left.type === right.type &&
Boolean(left.ordered) === Boolean(right.ordered) &&
!(left.ordered
? state.options.bulletOrderedOther
: state.options.bulletOther)
) {
return false
}

// Join children of a list or an item.
// In which case, `parent` has a `spread` field.
if ('spread' in parent && typeof parent.spread === 'boolean') {
Expand Down
56 changes: 23 additions & 33 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,44 +299,34 @@
* Configuration (optional).
* @property {'*' | '+' | '-' | null | undefined} [bullet='*']
* Marker to use for bullets of items in unordered lists (default: `'*'`).
* @property {'*' | '+' | '-' | null | undefined} [bulletOther]
* Marker to use in certain cases where the primary bullet doesn’t work
* (default: depends).
*
* There are three cases where the primary bullet cannot be used:
*
* * When three list items are on their own, the last one is empty, and
* `bullet` is also a valid `rule`: `* - +`.
* This would turn into a thematic break if serialized with three primary
* bullets.
* As this is an edge case unlikely to appear in normal markdown, the
* last list item will be given a different bullet.
* * When a thematic break is the first child of one of the list items, and
* `bullet` is the same character as `rule`: `- ***`.
* This would turn into a single thematic break if serialized with
* primary bullets.
* As this is an edge case unlikely to appear in normal markdown this
* markup is always fixed, even if `bulletOther` is not passed
* * When two unordered lists appear next to each other: `* a\n- b`.
* CommonMark sees different bullets as different lists, but several
* markdown parsers parse it as one list.
* To solve for both, we instead inject an empty comment between the two
* lists: `* a\n<!---->\n* b`, but if `bulletOther` is given explicitly,
* it will be used instead
* * when three or more list items are on their own, the last one is empty,
* and `bullet` is also a valid `rule`: `* - +`; this would turn into a
* thematic break if serialized with three primary bullets; `bulletOther`
* is used for the last item
* * when a thematic break is the first child of a list item and `bullet` is
* the same character as `rule`: `- ***`; this would turn into a single
* thematic break if serialized with primary bullets; `bulletOther` is used
* for the item
* * when two unordered lists appear next to each other: `* a\n- b`;
* `bulletOther` is used for such lists
* @property {'*' | '+' | '-' | null | undefined} [bulletOther]
* Marker to use in certain cases where the primary bullet doesn’t work
* (default: `'-'` when `bullet` is `'*'`, `'*'` otherwise).
*
* Cannot be equal to `bullet`.
* @property {'.' | ')' | null | undefined} [bulletOrdered='.']
* Marker to use for bullets of items in ordered lists (default: `'.'`).
* @property {'.' | ')' | null | undefined} [bulletOrderedOther]
* Marker to use in certain cases where the primary bullet for ordered items
* doesn’t work (default: none).
*
* There is one case where the primary bullet for ordered items cannot be used:
*
* * When two ordered lists appear next to each other: `1. a\n2) b`.
* CommonMark added support for `)` as a marker, but other markdown
* parsers do not support it.
* To solve for both, we instead inject an empty comment between the two
* lists: `1. a\n<!---->\n1. b`, but if `bulletOrderedOther` is given
* explicitly, it will be used instead
*
* There is one case where the primary bullet for ordered items cannot be
* used:
*
* * when two ordered lists appear next to each other: `1. a\n2) b`; to
* solve
* that, `'.'` will be used when `bulletOrdered` is `')'`, and `'.'`
* otherwise
* @property {boolean | null | undefined} [closeAtx=false]
* Whether to add the same number of number signs (`#`) at the end of an ATX
* heading as the opening sequence (default: `false`).
Expand Down
39 changes: 0 additions & 39 deletions lib/util/check-bullet-ordered-other.js

This file was deleted.

49 changes: 17 additions & 32 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,50 +314,35 @@ The following fields influence how markdown is serialized.
Marker to use for bullets of items in unordered lists (`'*'`, `'+'`, or `'-'`,
default: `'*'`).

There are three cases where the primary bullet cannot be used:

* when three or more list items are on their own, the last one is empty, and
`bullet` is also a valid `rule`: `* - +`; this would turn into a thematic
break if serialized with three primary bullets; `bulletOther` is used for
the last item
* when a thematic break is the first child of a list item and `bullet` is the
same character as `rule`: `- ***`; this would turn into a single thematic
break if serialized with primary bullets; `bulletOther` is used for the
item
* when two unordered lists appear next to each other: `* a\n- b`;
`bulletOther` is used for such lists

###### `options.bulletOther`

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

There are three cases where the primary bullet cannot be used:

* When three list items are on their own, the last one is empty, and `bullet`
is also a valid `rule`: `* - +`.
This would turn into a thematic break if serialized with three primary
bullets.
As this is an edge case unlikely to appear in normal markdown, the last list
item will be given a different bullet.
* When a thematic break is the first child of one of the list items, and
`bullet` is the same character as `rule`: `- ***`.
This would turn into a single thematic break if serialized with primary
bullets.
As this is an edge case unlikely to appear in normal markdown this markup is
always fixed, even if `bulletOther` is not passed
* When two unordered lists appear next to each other: `* a\n- b`.
CommonMark sees different bullets as different lists, but several markdown
parsers parse it as one list.
To solve for both, we instead inject an empty comment between the two lists:
`* a\n<!---->\n* b`, but if `bulletOther` is given explicitly, it will be
used instead
Cannot be equal to `bullet`.

###### `options.bulletOrdered`

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

###### `options.bulletOrderedOther`

Marker to use in certain cases where the primary bullet for ordered items
doesn’t work (`'.'` or `')'`, default: none).

There is one case where the primary bullet for ordered items cannot be used:

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

###### `options.closeAtx`

Expand Down
Loading

0 comments on commit 89d0f5b

Please sign in to comment.