Skip to content

fix(Lists): enable tight lists by default to eliminate unnecessary spacing #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions src/extensions/markdown/Lists/Lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const {doc, p, li, ul, ol} = builders<'doc' | 'p' | 'li' | 'ul' | 'ol'>(schema,
const {same} = createMarkupChecker({parser, serializer});

describe('Lists extension', () => {
it('should parse bullet list', () => {
it('should parse bullet list (tight)', () => {
same(
'* one\n\n* two',
'* one\n* two',
doc(
ul(
{[ListsAttr.Markup]: '*'},
Expand All @@ -38,21 +38,47 @@ describe('Lists extension', () => {
);
});

it('should parse ordered list with dots', () => {
it('should parse bullet list (non tight)', () => {
same(
'* one\n\n* two',
doc(
ul(
{[ListsAttr.Markup]: '*', [ListsAttr.Tight]: false},
li({[ListsAttr.Markup]: '*'}, p('one')),
li({[ListsAttr.Markup]: '*'}, p('two')),
),
),
);
});

it('should parse ordered list with dots (tight)', () => {
same(
'1. one\n2. two',
doc(
ol(
li({[ListsAttr.Markup]: '.'}, p('one')),
li({[ListsAttr.Markup]: '.'}, p('two')),
),
),
);
});

it('should parse ordered list with dots (non tight)', () => {
same(
'1. one\n\n2. two',
doc(
ol(
{[ListsAttr.Tight]: false},
li({[ListsAttr.Markup]: '.'}, p('one')),
li({[ListsAttr.Markup]: '.'}, p('two')),
),
),
);
});

it('should parse ordered list with parenthesis', () => {
it('should parse ordered list with parenthesis (tight)', () => {
same(
'1) one\n\n2) two',
'1) one\n2) two',
doc(
ol(
{[ListsAttr.Markup]: ')'},
Expand All @@ -63,6 +89,19 @@ describe('Lists extension', () => {
);
});

it('should parse ordered list with parenthesis (non tight)', () => {
same(
'1) one\n\n2) two',
doc(
ol(
{[ListsAttr.Markup]: ')', [ListsAttr.Tight]: false},
li({[ListsAttr.Markup]: ')'}, p('one')),
li({[ListsAttr.Markup]: ')'}, p('two')),
),
),
);
});

it('should parse nested lists', () => {
const markup = `
- one
Expand All @@ -80,11 +119,12 @@ describe('Lists extension', () => {
markup,
doc(
ul(
{[ListsAttr.Markup]: '-'},
{[ListsAttr.Markup]: '-', [ListsAttr.Tight]: false},
li(
{[ListsAttr.Markup]: '-'},
p('one'),
ol(
{[ListsAttr.Tight]: false},
li(
{[ListsAttr.Markup]: '.'},
p('two'),
Expand All @@ -110,15 +150,15 @@ describe('Lists extension', () => {
'- + * 2. item',
doc(
ul(
{[ListsAttr.Markup]: '-'},
{[ListsAttr.Markup]: '-', [ListsAttr.Tight]: false},
li(
{[ListsAttr.Markup]: '-'},
ul(
{[ListsAttr.Markup]: '+'},
{[ListsAttr.Markup]: '+', [ListsAttr.Tight]: false},
li(
{[ListsAttr.Markup]: '+'},
ul(
{[ListsAttr.Markup]: '*'},
{[ListsAttr.Markup]: '*', [ListsAttr.Tight]: false},
li(
{[ListsAttr.Markup]: '*'},
ol(
Expand Down
5 changes: 2 additions & 3 deletions src/extensions/markdown/Lists/ListsSpecs/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {ListNode, ListsAttr, Markup} from './const';
export const schemaSpecs: Record<ListNode, NodeSpec> = {
[ListNode.ListItem]: {
attrs: {
[ListsAttr.Tight]: {default: false},
[ListsAttr.Markup]: {default: null},
},
content: '(paragraph|block)+',
Expand All @@ -24,7 +23,7 @@ export const schemaSpecs: Record<ListNode, NodeSpec> = {
content: `${ListNode.ListItem}+`,
group: 'block',
attrs: {
[ListsAttr.Tight]: {default: false},
[ListsAttr.Tight]: {default: true},
[ListsAttr.Markup]: {default: Markup.bullet.default},
},
parseDOM: [
Expand All @@ -46,7 +45,7 @@ export const schemaSpecs: Record<ListNode, NodeSpec> = {
[ListNode.OrderedList]: {
attrs: {
[ListsAttr.Order]: {default: 1},
[ListsAttr.Tight]: {default: false},
[ListsAttr.Tight]: {default: true},
[ListsAttr.Markup]: {default: Markup.ordered.default},
},
content: `${ListNode.ListItem}+`,
Expand Down
Loading