Skip to content
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

fix(YfmTabs): correct serialization of yfm-tabs inside blockqoute #201

Merged
merged 1 commit into from
Feb 22, 2024
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
62 changes: 59 additions & 3 deletions src/extensions/yfm/YfmTabs/YfmTabs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {builders} from 'prosemirror-test-builder';
import {createMarkupChecker} from '../../../../tests/sameMarkup';
import {ExtensionsManager} from '../../../core';
import {BaseNode, BaseSpecsPreset} from '../../base/specs';
import {blockquoteNodeName, italicMarkName} from '../../markdown/specs';
import {BlockquoteSpecs, blockquoteNodeName, italicMarkName} from '../../markdown/specs';

import {TabsNode, YfmTabsSpecs} from './YfmTabsSpecs';

Expand All @@ -19,10 +19,11 @@ afterEach(() => {
});

const {schema, parser, serializer} = new ExtensionsManager({
extensions: (builder) => builder.use(BaseSpecsPreset, {}).use(YfmTabsSpecs, {}),
extensions: (builder) =>
builder.use(BaseSpecsPreset, {}).use(BlockquoteSpecs).use(YfmTabsSpecs, {}),
}).buildDeps();

const {doc, p, tab, tabs, tabPanel, tabsList} = builders<
const {doc, p, bq, tab, tabs, tabPanel, tabsList} = builders<
'doc' | 'p' | 'bq' | 'tab' | 'tabPanel' | 'tabs' | 'tabsList'
>(schema, {
doc: {nodeType: BaseNode.Doc},
Expand Down Expand Up @@ -119,4 +120,59 @@ describe('YfmTabs extension', () => {
),
);
});

it('should correct parse and serialize yfm-tabs inside blockqute', () => {
const markup = `
> {% list tabs %}
>
> - Tab
>
> Content
>
> {% endlist %}`.trim();

same(
markup,
doc(
bq(
tabs(
{
class: 'yfm-tabs',
'data-diplodoc-group': `defaultTabsGroup-${generatedId}`,
},
tabsList(
{
class: 'yfm-tab-list',
role: 'tablist',
},
tab(
{
id: 'unknown',
class: 'yfm-tab active',
role: 'tab',
'aria-controls': generatedId,
'aria-selected': 'true',
tabindex: '-1',
'data-diplodoc-is-active': 'true',
'data-diplodoc-id': 'tab',
'data-diplodoc-key': 'tab',
},
'Tab',
),
),
tabPanel(
{
id: generatedId,
class: 'yfm-tab-panel active',
role: 'tabpanel',
'data-title': 'Tab',
'aria-labelledby': 'tab',
},
p('Content'),
),
),
),
),
);
});
});
10 changes: 8 additions & 2 deletions src/extensions/yfm/YfmTabs/YfmTabsSpecs/toYfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const toYfm: Record<TabsNode, SerializerNodeToken> = {
},

[TabsNode.Tabs]: (state, node) => {
state.write('{% list tabs %}\n\n');
state.write('{% list tabs %}');
state.write('\n');
state.write('\n');

const children: Node[] = [];
node.content.forEach((a) => {
children.push(a);
Expand All @@ -24,7 +27,10 @@ export const toYfm: Record<TabsNode, SerializerNodeToken> = {
const tabList = children[0].content;

tabList.forEach((tab, _, i) => {
state.write('- ' + (tab.textContent || getPlaceholderContent(tab)) + '\n\n');
state.write('- ' + (tab.textContent || getPlaceholderContent(tab)));
state.write('\n');
state.write('\n');

if (children[i + 1]) state.renderList(children[i + 1], ' ', () => ' ');
});

Expand Down
Loading