Skip to content

Commit

Permalink
Merge pull request #4365 from nextcloud-libraries/feat/noid/support-g…
Browse files Browse the repository at this point in the history
…ithub-markdown

feat(`NcRichText`) add support of GFM (extended markdown)
  • Loading branch information
Antreesy authored Jan 23, 2024
2 parents 72f56e0 + ce2389d commit a53dcda
Show file tree
Hide file tree
Showing 8 changed files with 943 additions and 766 deletions.
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

0 comments on commit a53dcda

Please sign in to comment.