Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for block elements in headings #111

Open
eikowagenknecht opened this issue Jul 14, 2024 · 2 comments
Open

Support for block elements in headings #111

eikowagenknecht opened this issue Jul 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@eikowagenknecht
Copy link
Contributor

Obsidian itself also supports block elements in headings, like this:

grafik

Maybe this could be added here as well, for feature parity? :-)

@r4ai
Copy link
Owner

r4ai commented Jul 19, 2024

It would be great to support that feature!

Thanks for the feedback.

@r4ai r4ai added the enhancement New feature or request label Jul 21, 2024
@r4ai
Copy link
Owner

r4ai commented Jul 31, 2024

After researching various options, it seems challenging to implement this feature due to the specifications of mdast and remark.

For example, consider the following markdown:

> [!note] title here
> body here

This is transformed into the following mdast, and this plugin generates the callout by manipulating this mdast.

{
  "type": "root",
  "children": [
    {
      "type": "blockquote",
      "children": [
        {
          "type": "paragraph",
          "children": [
            {
              "type": "text",
              "value": "[!note] # title here\nbody here",
              "position": {
                "start": {
                  "line": 1,
                  "column": 3,
                  "offset": 2
                },
                "end": {
                  "line": 2,
                  "column": 12,
                  "offset": 34
                }
              }
            }
          ],
          "position": {
            "start": {
              "line": 1,
              "column": 3,
              "offset": 2
            },
            "end": {
              "line": 2,
              "column": 12,
              "offset": 34
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "end": {
          "line": 2,
          "column": 12,
          "offset": 34
        }
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1,
      "offset": 0
    },
    "end": {
      "line": 2,
      "column": 12,
      "offset": 34
    }
  }
}

https://astexplorer.net/#/gist/10d8f7b32e0123fee005f49d8d75defa/6017a37f56a4098ff295b3c4730a217ef8132089

Notice that the title part of the callout exists as a paragraph in the mdast. According to the CommonMark specifications, only inline elements are allowed as children of a paragraph. Therefore, block elements cannot exist within a paragraph, making it impossible to use block elements as the title of a callout.

Furthermore, the heading included in the title part exists as text within the mdast. To recognize this as a heading element, the plugin would need to re-parse this string with remark, which is somewhat difficult to do accurately on the plugin side.

I am in favor of adding this feature, so if anyone is able to implement it, please feel free to mention me or send a PR.
Thank you for proposing this feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants