From f7df75ff3e6fd5c89d8d8d53a5a117974ef16f55 Mon Sep 17 00:00:00 2001 From: Titus Date: Thu, 15 Jun 2023 12:37:41 +0200 Subject: [PATCH] Remove static phrasing content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 charlie](delta) ``` Yields, per CommonMark: ```html

alpha https://bravo charlie

``` See also: https://github.com/commonmark/commonmark-spec/issues/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) ``` --- readme.md | 54 ++++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/readme.md b/readme.md index 2ce6386..be8e4fb 100644 --- a/readme.md +++ b/readme.md @@ -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) @@ -527,7 +525,7 @@ Yields: ```idl interface Emphasis <: Parent { type: 'emphasis' - children: [TransparentContent] + children: [PhrasingContent] } ``` @@ -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: @@ -568,7 +566,7 @@ Yields: ```idl interface Strong <: Parent { type: 'strong' - children: [TransparentContent] + children: [PhrasingContent] } ``` @@ -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: @@ -674,7 +672,7 @@ Yields: ```idl interface Link <: Parent { type: 'link' - children: [StaticPhrasingContent] + children: [PhrasingContent] } Link includes Resource @@ -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]. @@ -747,7 +745,7 @@ Yields: ```idl interface LinkReference <: Parent { type: 'linkReference' - children: [StaticPhrasingContent] + children: [PhrasingContent] } LinkReference includes Reference @@ -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]. @@ -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. @@ -1196,7 +1179,7 @@ or indeterminate or not applicable (when `null` or not present). ```idl interface Delete <: Parent { type: 'delete' - children: [TransparentContent] + children: [PhrasingContent] } ``` @@ -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: @@ -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 @@ -1365,10 +1347,10 @@ Yields: } ``` -#### `StaticPhrasingContent` (footnotes) +#### `PhrasingContent` (footnotes) ```idl -type StaticPhrasingContentFootnotes = Footnote | StaticPhrasingContent +type PhrasingContentFootnotes = Footnote | PhrasingContent ``` ### MDX @@ -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/