Skip to content

use ordered list start index when rendering #30

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

Merged
merged 2 commits into from
Dec 8, 2021
Merged
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
6 changes: 5 additions & 1 deletion src/components/ContentNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ function renderNode(createElement, references) {
node.text
));
case BlockType.orderedList:
return createElement('ol', {}, (
return createElement('ol', {
attrs: {
start: node.start,
},
}, (
renderListItems(node.items)
));
case BlockType.paragraph:
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/components/ContentNode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,51 @@ describe('ContentNode', () => {

const list = wrapper.find('.content ol');
expect(list.exists()).toBe(true);
expect(list.attributes('start')).toBeUndefined();

const items = list.findAll('li');
expect(items.length).toBe(2);
expect(items.at(0).find('p').text()).toBe('foo');
expect(items.at(1).find('p').text()).toBe('bar');
});

it('renders an <ol> with <li> items and a custom start index', () => {
const wrapper = mountWithItem({
type: 'orderedList',
start: 2,
items: [
{
content: [
{
type: 'paragraph',
inlineContent: [
{
type: 'text',
text: 'foo',
},
],
},
],
},
{
content: [
{
type: 'paragraph',
inlineContent: [
{
type: 'text',
text: 'bar',
},
],
},
],
},
],
});

const list = wrapper.find('.content ol');
expect(list.exists()).toBe(true);
expect(list.attributes('start')).toBe('2');

const items = list.findAll('li');
expect(items.length).toBe(2);
Expand Down