import { describe, expect, it } from 'vitest'
import { getMarkdown, parseMarkdownToStructure } from '../src'
describe('html_inline parsing', () => {
it('parses as link node with href and inner text', () => {
const md = getMarkdown()
const markdown = `This is a Example link.`
const nodes = parseMarkdownToStructure(markdown, md)
expect(nodes.length).toBeGreaterThan(0)
const para = nodes[0]
expect(para.type).toBe('paragraph')
const linkChild = (para as any).children.find((c: any) => c.type === 'link')
expect(linkChild).toBeDefined()
expect(linkChild.href).toBe('https://example.com')
expect(linkChild.children[0].content).toBe('Example')
})
it('preserves custom attributes on link node attrs', () => {
const md = getMarkdown()
const markdown = `Example`
const nodes = parseMarkdownToStructure(markdown, md)
const para = nodes[0] as any
const linkChild = para.children.find((c: any) => c.type === 'link')
expect(linkChild).toBeDefined()
expect(linkChild.href).toBe('https://example.com')
expect(linkChild.attrs).toEqual(expect.arrayContaining([
['href', 'https://example.com'],
['target', '_self'],
['rel', 'nofollow'],
['data-track', 'cta'],
]))
})
it('creates html_inline nodes for generic inline html like ', () => {
const md = getMarkdown()
const markdown = `Before inner span After`
const nodes = parseMarkdownToStructure(markdown, md)
const para = nodes[0]
const spanNode = (para as any).children.find((c: any) => c.type === 'html_inline')
expect(spanNode).toBeDefined()
expect(spanNode.content).toContain('')
expect(spanNode.children?.[0]?.content).toBe('inner span')
})
it('handles attribute values that include ">" characters', () => {
const md = getMarkdown()
const markdown = `Value Here end`
const nodes = parseMarkdownToStructure(markdown, md)
const para = nodes[0]
const linkChild = (para as any).children.find((c: any) => c.type === 'link')
expect(linkChild).toBeDefined()
// href extraction should capture full quoted value including '>'
expect(linkChild.href).toBe('https://example.com?q=a>b&x=1')
})
it('handles missing closing tag gracefully (unclosed )', () => {
const md = getMarkdown()
const markdown = `Start Unclosed text`
const nodes = parseMarkdownToStructure(markdown, md)
// Should not throw; ensure raw input is preserved in some node
const serialized = JSON.stringify(nodes)
// JSON will escape quotes, so check for a less strict substring and for href URL
expect(serialized).toContain('