Skip to content

Commit

Permalink
fix(blocks): real nested list on html export
Browse files Browse the repository at this point in the history
  • Loading branch information
fourdim committed Oct 14, 2024
1 parent eaeb1b7 commit 55a9903
Show file tree
Hide file tree
Showing 5 changed files with 395 additions and 96 deletions.
107 changes: 106 additions & 1 deletion packages/blocks/src/__tests__/adapters/html.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,112 @@ describe('snapshot to html', () => {
],
};
const html = template(
`<div class="affine-list-block-container"><ul style=""><li>aaa</li></ul><div class="affine-block-children-container" style="padding-left: 26px;"><div class="affine-list-block-container"><ul style=""><li>bbb</li></ul><div class="affine-block-children-container" style="padding-left: 26px;"><div class="affine-list-block-container"><ul style=""><li>ccc</li></ul><div class="affine-block-children-container" style="padding-left: 26px;"></div></div></div></div><div class="affine-list-block-container"><ul style=""><li>ddd</li></ul><div class="affine-block-children-container" style="padding-left: 26px;"></div></div></div></div><div class="affine-list-block-container"><ul style=""><li>eee</li></ul><div class="affine-block-children-container" style="padding-left: 26px;"></div></div>`
`<ul class="bulleted-list"><li class="affine-list-block-container">aaa<ul class="bulleted-list"><li class="affine-list-block-container">bbb<ul class="bulleted-list"><li class="affine-list-block-container">ccc</li></ul></li><li class="affine-list-block-container">ddd</li></ul></li><li class="affine-list-block-container">eee</li></ul>`
);

const htmlAdapter = new HtmlAdapter(createJob());
const target = await htmlAdapter.fromBlockSnapshot({
snapshot: blockSnapshot,
});
expect(target.file).toBe(html);
});

test('different list', async () => {
const blockSnapshot: BlockSnapshot = {
type: 'block',
id: 'block:vu6SK6WJpW',
flavour: 'affine:page',
props: {
title: {
'$blocksuite:internal:text$': true,
delta: [],
},
},
children: [
{
type: 'block',
id: 'block:Tk4gSPocAt',
flavour: 'affine:surface',
props: {
elements: {},
},
children: [],
},
{
type: 'block',
id: 'block:WfnS5ZDCJT',
flavour: 'affine:note',
props: {
xywh: '[0,0,800,95]',
background: DEFAULT_NOTE_BACKGROUND_COLOR,
index: 'a0',
hidden: false,
displayMode: NoteDisplayMode.DocAndEdgeless,
},
children: [
{
type: 'block',
id: 'block:imiLDMKSkx',
flavour: 'affine:list',
props: {
type: 'bulleted',
text: {
'$blocksuite:internal:text$': true,
delta: [
{
insert: 'aaa',
},
],
},
checked: false,
collapsed: false,
},
children: [],
},
{
type: 'block',
id: 'block:imiLDMKSkx',
flavour: 'affine:list',
props: {
type: 'todo',
text: {
'$blocksuite:internal:text$': true,
delta: [
{
insert: 'bbb',
},
],
},
checked: false,
collapsed: false,
},
children: [],
},
{
type: 'block',
id: 'block:imiLDMKSkx',
flavour: 'affine:list',
props: {
type: 'bulleted',
text: {
'$blocksuite:internal:text$': true,
delta: [
{
insert: 'ccc',
},
],
},
checked: false,
collapsed: false,
},
children: [],
},
],
},
],
};
const html = template(
`<ul class="bulleted-list"><li class="affine-list-block-container">aaa</li></ul><ul style="list-style-type: none; padding-inline-start: 18px;" class="todo-list"><li class="affine-list-block-container"><input type="checkbox"><label style="margin-right: 3px;"></label></input>bbb</li></ul><ul class="bulleted-list"><li class="affine-list-block-container">ccc</li></ul>`
);

const htmlAdapter = new HtmlAdapter(createJob());
Expand Down
164 changes: 164 additions & 0 deletions packages/blocks/src/__tests__/adapters/markdown.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,170 @@ hhh
expect(target.file).toEqual(markdown);
});

test('different list', async () => {
const blockSnapshot: BlockSnapshot = {
type: 'block',
id: 'block:m5hvdXHXS2',
flavour: 'affine:page',
version: 2,
props: {
title: {
'$blocksuite:internal:text$': true,
delta: [],
},
},
children: [
{
type: 'block',
id: 'block:Y4J-oO9h9d',
flavour: 'affine:surface',
version: 5,
props: {
elements: {},
},
children: [],
},
{
type: 'block',
id: 'block:1Ll22zT992',
flavour: 'affine:note',
version: 1,
props: {
xywh: '[0,0,800,95]',
background: DEFAULT_NOTE_BACKGROUND_COLOR,
index: 'a0',
hidden: false,
displayMode: 'both',
edgeless: {
style: {
borderRadius: 8,
borderSize: 4,
borderStyle: 'solid',
shadowType: '--affine-note-shadow-box',
},
},
},
children: [
{
type: 'block',
id: 'block:Fd0ZCYB7a4',
flavour: 'affine:list',
version: 1,
props: {
type: 'numbered',
text: {
'$blocksuite:internal:text$': true,
delta: [
{
insert: 'aaa',
},
],
},
checked: false,
collapsed: false,
},
children: [
{
type: 'block',
id: 'block:8-GeKDc06x',
flavour: 'affine:list',
version: 1,
props: {
type: 'numbered',
text: {
'$blocksuite:internal:text$': true,
delta: [
{
insert: 'bbb',
},
],
},
checked: false,
collapsed: false,
},
children: [],
},
{
type: 'block',
id: 'block:f0c-9xKaEL',
flavour: 'affine:list',
version: 1,
props: {
type: 'bulleted',
text: {
'$blocksuite:internal:text$': true,
delta: [
{
insert: 'ccc',
},
],
},
checked: false,
collapsed: false,
},
children: [],
},
{
type: 'block',
id: 'block:f0c-9xKaEL',
flavour: 'affine:list',
version: 1,
props: {
type: 'numbered',
text: {
'$blocksuite:internal:text$': true,
delta: [
{
insert: 'ddd',
},
],
},
checked: false,
collapsed: false,
},
children: [],
},
],
},
{
type: 'block',
id: 'block:Fd0ZCYB7a5',
flavour: 'affine:list',
version: 1,
props: {
type: 'numbered',
text: {
'$blocksuite:internal:text$': true,
delta: [
{
insert: 'eee',
},
],
},
checked: false,
collapsed: false,
},
children: [],
},
],
},
],
};

const markdown = `1. aaa
1. bbb
* ccc
1. ddd
2. eee
`;

const mdAdapter = new MarkdownAdapter(createJob());
const target = await mdAdapter.fromBlockSnapshot({
snapshot: blockSnapshot,
});
expect(target.file).toEqual(markdown);
});

test('code inline', async () => {
const blockSnapshot: BlockSnapshot = {
type: 'block',
Expand Down
Loading

0 comments on commit 55a9903

Please sign in to comment.