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

feat(NcRichText) add support of GFM (extended markdown) #4365

Merged
merged 3 commits into from
Jan 23, 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
96 changes: 96 additions & 0 deletions cypress/component/richtext.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,59 @@ describe('NcRichText', () => {
})
})

describe('strikethrough text', () => {
it('strikethrough text (with single tilda syntax)', () => {
mount(NcRichText, {
propsData: {
text: '~strikethrough single~',
useExtendedMarkdown: true,
},
})

cy.get('del').should('have.text', 'strikethrough single')
})

it('strikethrough text (with double tilda syntax)', () => {
mount(NcRichText, {
propsData: {
text: '~~strikethrough double~~',
useExtendedMarkdown: true,
},
})

cy.get('del').should('have.text', 'strikethrough double')
})

it('strikethrough text (several in line with different syntax)', () => {
const outputs = ['strikethrough single', 'strikethrough double']
mount(NcRichText, {
propsData: {
text: 'normal text ~strikethrough single~ normal text ~~strikethrough double~~ normal text',
useExtendedMarkdown: true,
},
})

cy.get('del').should('have.length', 2)
cy.get('del').each((item, index) => {
expect(item).have.text(outputs[index])
})
})

it('strikethrough text (between normal texts with different syntax)', () => {
mount(NcRichText, {
propsData: {
text: 'text~strikethrough~text~~strikethrough~~text',
useExtendedMarkdown: true,
},
})

cy.get('del').should('have.length', 2)
cy.get('del').each((item) => {
expect(item).have.text('strikethrough')
})
})
})

describe('inline code', () => {
it('inline code (single with backticks syntax)', () => {
mount(NcRichText, {
Expand Down Expand Up @@ -515,6 +568,49 @@ describe('NcRichText', () => {
})
})

describe('task lists', () => {
it('task list (with `- [ ]` and `- [x]` syntax divided with space from text)', () => {
const testCases = [
{ input: '- [ ] item 1', output: 'item 1', checked: false },
{ input: '- [x] item 2', output: 'item 2', checked: true },
{ input: '- [ ] item 3', output: 'item 3', checked: false },
]

mount(NcRichText, {
propsData: {
text: testCases.map(i => i.input).join('\n'),
useExtendedMarkdown: true,
},
})

cy.get('ul').should('exist')
cy.get('li').should('have.length', testCases.length)
cy.get('li').each((item, index) => {
// Vue 2.7 renders three non-breaking spaces here for some reason
expect(item).have.text(' ' + testCases[index].output)
})
cy.get('input:checked').should('have.length', testCases.filter(test => test.checked).length)
})
})

describe('tables', () => {
it('table (with `-- | --` syntax)', () => {
mount(NcRichText, {
propsData: {
text: 'Table | Column A | Column B\n-- | -- | --\nRow 1 | Value A1 | Value B1\nRow 2 | Value A2 | Value B2',
useExtendedMarkdown: true,
},
})

cy.get('table').should('exist')
cy.get('thead').should('exist')
cy.get('tbody').should('exist')
cy.get('tr').should('have.length', 3)
cy.get('th').should('have.length', 3)
cy.get('td').should('have.length', 6)
})
})

describe('dividers', () => {
it('dividers (with different syntax)', () => {
mount(NcRichText, {
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
const ignorePatterns = [
'ansi-regex',
'bail',
'ccount', // ESM dependency of remark-gfm
'char-regex',
'comma-separated-tokens',
'decode-named-character-reference',
'devlop', // ESM dependency of unified
'escape-string-regexp',
'hast-*',
'is-*',
'longest-streak', // ESM dependency of remark-gfm
'markdown-table', // ESM dependency of remark-gfm
'mdast-util-*',
'micromark',
'property-information',
Expand All @@ -46,6 +49,7 @@ const ignorePatterns = [
'vfile',
'vue-material-design-icons',
'web-namespaces',
'zwitch', // ESM dependency of remark-gfm
]

module.exports = {
Expand Down
Loading
Loading