镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Set type member for all nodes #2000

Description

@sapristi

What pain point are you perceiving?.

Not all nodes have a type member set, namely the def (see

_proto.def = function def(src) {

and also in one case for the space node:

return {

Having a defined type member would help discriminating them when iterating the markdown tree.
It also seems to be an issue for the https://www.npmjs.com/package/@types/marked packages, where the Def interface does't have a type member, and thus it is not possible to discriminate node types in typescript (I guess it could be possible to add a type member in the interface, but it would be troublesome if this project later chose a different string).

Describe the solution you'd like

Add a type member to all nodes of the markdown tree.

Activity

  1. added
    L2 - annoyingSimilar to L1 - broken but there is a known workaround available for the issue
    on Apr 8, 2021
  2. UziTech commented on Apr 8, 2021

    @UziTech
    Member

    If you would like to create a PR to add the type that would be much appreciated.

    You should just need to add a type property to the def tokenizer's return object

    marked/src/Tokenizer.js

    Lines 344 to 356 in d0f9ffd

    def(src) {
    const cap = this.rules.block.def.exec(src);
    if (cap) {
    if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
    const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
    return {
    tag,
    raw: cap[0],
    href: cap[2],
    title: cap[3]
    };
    }
    }

  3. sapristi commented on Apr 9, 2021

    @sapristi
    ContributorAuthor

    Ok I will do one. What about the case where the space node doesn't define a type member ?

    Edit: It seems the case where space doesn't define type member is rejectedby the lexer, so I guess it can stay as it is.

    if (token.type) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    L2 - annoyingSimilar to L1 - broken but there is a known workaround available for the issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions