Skip to content

Commit

Permalink
Remove static phrasing content
Browse files Browse the repository at this point in the history
Previously, there was a difference between static and dynamic phrasing
content.
There was also transparent content, to “inherit” the (static or dynamic)
content model from a parent.
This was used to prohibit links in links.

However, while it is unwise to put links in links, it is possible with
markdown to do so, by embedding autolinks in links with resources or
references.
Take for example:

```markdown
[alpha <https://bravo> charlie](delta)
```

Yields, per CommonMark:

```html
<p><a href="delta">alpha <a href="https://bravo">https://bravo</a> charlie</a></p>
```

See also: commonmark/commonmark-spec#719.

There is also the case where while it is unwise to author such markdown,
tools transforming mdast might inject links.
It’s probably good to handle such cases in `mdast-util-to-markdown` and
such?

Not allowing links in links is also something imposed by HTML (particularly
the parsing side[^1]): perhaps mdast could be used in places where this
restriction doesn’t need to be imposed.

Finally, it is hard to type such inherited content models.
As in, transparent content is not used in `@types/mdast` (I don’t think it
can be typed?):

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3b052a3e5b59b0efaa22669d9bd8f268bd689835/types/mdast/index.d.ts#L286

So, this PR is a proposal to remove the difference and simplify the AST.

Closes GH-42.

[^1]: You can produce nested `a`s with the DOM:

    ```js
    let a1 = document.createElement('a'); a1.textContent = 'alpha';
    let a2 = document.createElement('a'); a2.textContent = 'bravo';
    a1.appendChild(a2)
    document.body.appendChild(a1)
    ```
  • Loading branch information
wooorm authored Jun 15, 2023
1 parent eace3f0 commit f7df75f
Showing 1 changed file with 16 additions and 38 deletions.
54 changes: 16 additions & 38 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ The latest released version is [`4.0.0`][latest].
* [`Content`](#content)
* [`ListContent`](#listcontent)
* [`PhrasingContent`](#phrasingcontent)
* [`StaticPhrasingContent`](#staticphrasingcontent)
* [`TransparentContent`](#transparentcontent)
* [Extensions](#extensions)
* [GFM](#gfm)
* [Frontmatter](#frontmatter)
Expand Down Expand Up @@ -527,7 +525,7 @@ Yields:
```idl
interface Emphasis <: Parent {
type: 'emphasis'
children: [TransparentContent]
children: [PhrasingContent]
}
```

Expand All @@ -536,7 +534,7 @@ contents.

**Emphasis** can be used where [**phrasing**][dfn-phrasing-content] content is
expected.
Its content model is [**transparent**][dfn-transparent-content] content.
Its content model is [**phrasing**][dfn-phrasing-content] content.

For example, the following markdown:

Expand Down Expand Up @@ -568,7 +566,7 @@ Yields:
```idl
interface Strong <: Parent {
type: 'strong'
children: [TransparentContent]
children: [PhrasingContent]
}
```

Expand All @@ -577,7 +575,7 @@ or urgency for its contents.

**Strong** can be used where [**phrasing**][dfn-phrasing-content] content is
expected.
Its content model is [**transparent**][dfn-transparent-content] content.
Its content model is [**phrasing**][dfn-phrasing-content] content.

For example, the following markdown:

Expand Down Expand Up @@ -674,7 +672,7 @@ Yields:
```idl
interface Link <: Parent {
type: 'link'
children: [StaticPhrasingContent]
children: [PhrasingContent]
}
Link includes Resource
Expand All @@ -684,7 +682,7 @@ Link includes Resource

**Link** can be used where [**phrasing**][dfn-phrasing-content] content is
expected.
Its content model is [**static phrasing**][dfn-static-phrasing-content] content.
Its content model is also [**phrasing**][dfn-phrasing-content] content.

**Link** includes the mixin [**Resource**][dfn-mxn-resource].

Expand Down Expand Up @@ -747,7 +745,7 @@ Yields:
```idl
interface LinkReference <: Parent {
type: 'linkReference'
children: [StaticPhrasingContent]
children: [PhrasingContent]
}
LinkReference includes Reference
Expand All @@ -758,7 +756,7 @@ association, or its original source if there is no association.

**LinkReference** can be used where [**phrasing**][dfn-phrasing-content] content
is expected.
Its content model is [**static phrasing**][dfn-static-phrasing-content] content.
Its content model is also [**phrasing**][dfn-phrasing-content] content.

**LinkReference** includes the mixin [**Reference**][dfn-mxn-reference].

Expand Down Expand Up @@ -961,27 +959,12 @@ type ListContent = ListItem
### `PhrasingContent`

```idl
type PhrasingContent = Link | LinkReference | StaticPhrasingContent
type PhrasingContent = Break | Emphasis | HTML | Image | ImageReference
| InlineCode | Link | LinkReference | Strong | Text
```

**Phrasing** content represent the text in a document, and its markup.

### `StaticPhrasingContent`

```idl
type StaticPhrasingContent =
Break | Emphasis | HTML | Image | ImageReference | InlineCode | Strong | Text
```

**StaticPhrasing** content represent the text in a document, and its
markup, that is not intended for user interaction.

### `TransparentContent`

The **transparent** content model is derived from the content model of its
[parent][dfn-parent].
Effectively, this is used to prohibit nested links (and link references).

## Extensions

Markdown syntax is often extended.
Expand Down Expand Up @@ -1196,7 +1179,7 @@ or indeterminate or not applicable (when `null` or not present).
```idl
interface Delete <: Parent {
type: 'delete'
children: [TransparentContent]
children: [PhrasingContent]
}
```

Expand All @@ -1205,7 +1188,7 @@ accurate or no longer relevant.

**Delete** can be used where [**phrasing**][dfn-phrasing-content] content is
expected.
Its content model is [**transparent**][dfn-transparent-content] content.
Its content model is [**phrasing**][dfn-phrasing-content] content.

For example, the following markdown:

Expand Down Expand Up @@ -1269,11 +1252,10 @@ type RowContent = TableCell
type ListContentGfm = ListItemGfm
```

#### `StaticPhrasingContent` (GFM)
#### `PhrasingContent` (GFM)

```idl
type StaticPhrasingContentGfm =
FootnoteReference | Delete | StaticPhrasingContent
type PhrasingContentGfm = FootnoteReference | Delete | PhrasingContent
```

### Frontmatter
Expand Down Expand Up @@ -1365,10 +1347,10 @@ Yields:
}
```

#### `StaticPhrasingContent` (footnotes)
#### `PhrasingContent` (footnotes)

```idl
type StaticPhrasingContentFootnotes = Footnote | StaticPhrasingContent
type PhrasingContentFootnotes = Footnote | PhrasingContent
```

### MDX
Expand Down Expand Up @@ -1671,10 +1653,6 @@ projects!

[dfn-phrasing-content]: #phrasingcontent

[dfn-static-phrasing-content]: #staticphrasingcontent

[dfn-transparent-content]: #transparentcontent

[gfm-section]: #gfm

[gfm-footnote]: https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/
Expand Down

0 comments on commit f7df75f

Please sign in to comment.