Some checks failed
Verify / Install node dependencies (push) Failing after 2s
Verify / Build packages (push) Has been skipped
Verify / Check linting & formatting (push) Has been skipped
Verify / Run unit tests (push) Has been skipped
Verify / Run e2e tests (shard 1/4) (push) Has been skipped
Verify / Run e2e tests (shard 2/4) (push) Has been skipped
Verify / Run e2e tests (shard 3/4) (push) Has been skipped
Verify / Run e2e tests (shard 4/4) (push) Has been skipped
Publish / Resolve publish config (push) Failing after 2s
Publish / Send notification to Slack (push) Has been skipped
Publish / Send failure notification to Slack (push) Failing after 8s
Verify / Merge e2e reports (push) Has been skipped
Publish / Build (push) Has been skipped
Publish / Bump Versions OR Release to Registry (push) Has been skipped
330 lines
8.2 KiB
TypeScript
330 lines
8.2 KiB
TypeScript
import { Bold } from '@tiptap/extension-bold'
|
|
import { Document } from '@tiptap/extension-document'
|
|
import { Italic } from '@tiptap/extension-italic'
|
|
import { Paragraph } from '@tiptap/extension-paragraph'
|
|
import { Text } from '@tiptap/extension-text'
|
|
import { describe, expect, it } from 'vite-plus/test'
|
|
|
|
import { MarkdownManager } from '../../src/MarkdownManager.js'
|
|
|
|
describe('Inline marks containing only punctuation', () => {
|
|
const extensions = [Document, Paragraph, Text, Bold, Italic]
|
|
const markdownManager = new MarkdownManager({ extensions })
|
|
|
|
describe('Bold marks with punctuation - whitespace-separated (CommonMark compliant)', () => {
|
|
it('should parse standalone bold punctuation marks', () => {
|
|
const markdown = '**)**'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: ')',
|
|
marks: [{ type: 'bold' }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should parse bold punctuation when preceded by whitespace', () => {
|
|
const markdown = 'text **)**'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: 'text ',
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ')',
|
|
marks: [{ type: 'bold' }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should parse bold punctuation when followed by whitespace', () => {
|
|
const markdown = '**)** text'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: ')',
|
|
marks: [{ type: 'bold' }],
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ' text',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should parse bold punctuation when surrounded by whitespace', () => {
|
|
const markdown = 'text **)** more'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: 'text ',
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ')',
|
|
marks: [{ type: 'bold' }],
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ' more',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should parse bold punctuation when preceded by other punctuation', () => {
|
|
const markdown = '[**)**]'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: '[',
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ')',
|
|
marks: [{ type: 'bold' }],
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ']',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should parse multiple bold punctuation marks', () => {
|
|
const markdown = '**,** **.**'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: ',',
|
|
marks: [{ type: 'bold' }],
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ' ',
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: '.',
|
|
marks: [{ type: 'bold' }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('Bold marks without required whitespace (CommonMark limitation)', () => {
|
|
it('should NOT parse bold punctuation when directly preceded by alphanumeric characters', () => {
|
|
const markdown = 'text**)**'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
// Per CommonMark flanking rules, this is not recognized as bold
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: 'text**)**',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should NOT parse bold punctuation when directly followed by alphanumeric characters', () => {
|
|
const markdown = '**)**text'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
// Per CommonMark flanking rules, this is not recognized as bold
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: '**)**text',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should NOT parse bold punctuation when surrounded by alphanumeric characters', () => {
|
|
const markdown = 'text**)**text'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
// Per CommonMark flanking rules, this is not recognized as bold
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: 'text**)**text',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('Italic marks with punctuation', () => {
|
|
it('should parse standalone italic punctuation', () => {
|
|
const markdown = '*)*'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: ')',
|
|
marks: [{ type: 'italic' }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should parse italic punctuation with whitespace', () => {
|
|
const markdown = 'text *,* more'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: 'text ',
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ',',
|
|
marks: [{ type: 'italic' }],
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: ' more',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
|
|
it('should NOT parse italic punctuation without whitespace', () => {
|
|
const markdown = 'text*,*text'
|
|
const json = markdownManager.parse(markdown)
|
|
|
|
expect(json).toEqual({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: 'text*,*text',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('Roundtrip serialization', () => {
|
|
it('should maintain bold punctuation through parse-serialize cycle', () => {
|
|
const markdown = 'text **)** more'
|
|
const json = markdownManager.parse(markdown)
|
|
const serialized = markdownManager.serialize(json)
|
|
|
|
expect(serialized).toBe(markdown)
|
|
})
|
|
|
|
it('should maintain italic punctuation through parse-serialize cycle', () => {
|
|
const markdown = 'text *,* more'
|
|
const json = markdownManager.parse(markdown)
|
|
const serialized = markdownManager.serialize(json)
|
|
|
|
expect(serialized).toBe(markdown)
|
|
})
|
|
})
|
|
})
|