Skip to content
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
88 changes: 88 additions & 0 deletions packages/comark/SPEC/COMARK/attribute-del.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## Input

```md
Here ~~del~~{bool} ~~del~~{#id1} ~~del~~{.class1} ~~del~~{attr="value"} ~~`x`~~{.gone} ~~*x*~~{.gone}
```

## AST

```json
{
"frontmatter": {},
"meta": {},
"nodes": [
[
"p",
{},
"Here ",
[
"del",
{
":bool": "true"
},
"del"
],
" ",
[
"del",
{
"id": "id1"
},
"del"
],
" ",
[
"del",
{
"class": "class1"
},
"del"
],
" ",
[
"del",
{
"attr": "value"
},
"del"
],
" ",
[
"del",
{
"class": "gone"
},
[
"code",
{},
"x"
]
],
" ",
[
"del",
{
"class": "gone"
},
[
"em",
{},
"x"
]
]
]
]
}
```

## HTML

```html
<p>Here <del bool>del</del> <del id="id1">del</del> <del class="class1">del</del> <del attr="value">del</del> <del class="gone"><code>x</code></del> <del class="gone"><em>x</em></del></p>
```

## Markdown

```md
Here ~~del~~{bool} ~~del~~{#id1} ~~del~~{.class1} ~~del~~{attr="value"} ~~`x`~~{.gone} ~~*x*~~{.gone}
```
58 changes: 58 additions & 0 deletions packages/comark/SPEC/common-mark/paragraph-del-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
## Input

```md
~~`x`~~ ~~a **b** `c`~~
```

## AST

```json
{
"frontmatter": {},
"meta": {},
"nodes": [
[
"p",
{},
[
"del",
{},
[
"code",
{},
"x"
]
],
" ",
[
"del",
{},
"a ",
[
"strong",
{},
"b"
],
" ",
[
"code",
{},
"c"
]
]
]
]
}
```

## HTML

```html
<p><del><code>x</code></del> <del>a <strong>b</strong> <code>c</code></del></p>
```

## Markdown

```md
~~`x`~~ ~~a **b** `c`~~
```
16 changes: 13 additions & 3 deletions packages/comark/src/internal/stringify/handlers/del.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import type { State } from 'comark/render'
import type { ElementNode } from 'comark'
import { textContent } from '../../../utils/index.ts'
import { comarkAttributes } from '../attributes.ts'

export function del(node: ElementNode, _: State) {
return `~~${textContent(node)}~~`
export async function del(node: ElementNode, state: State) {
const [_, attrs, ...children] = node

let content = ''
for (const child of children) {
content += await state.one(child, state, node)
}
content = content.trim()

const attrsString = Object.keys(attrs).length > 0 ? comarkAttributes(attrs) : ''

return `~~${content}~~${attrsString}`
}
2 changes: 1 addition & 1 deletion packages/comark/src/internal/stringify/handlers/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { indent } from '../../../utils/index.ts'

const textBlocks = new Set(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'td', 'th'])
const selfCloseTags = new Set(['br', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr'])
const inlineTags = new Set(['strong', 'em', 'code', 'a', 'br', 'span', 'img'])
const inlineTags = new Set(['strong', 'em', 'del', 'code', 'a', 'br', 'span', 'img'])
const blockTags = new Set([
'p',
'h1',
Expand Down
2 changes: 1 addition & 1 deletion test/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('package bundle size', { timeout: 60_000 }, () => {
"@comark/react": "43.6k (74 files)",
"@comark/svelte": "43.9k (82 files)",
"@comark/vue": "60.5k (78 files)",
"comark": "422k (156 files)",
"comark": "423k (156 files)",
}
`)
})
Expand Down
Loading