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

Set type member for all nodes #2000

Closed
sapristi opened this issue Apr 8, 2021 · 2 comments · Fixed by #2001 or #2002
Closed

Set type member for all nodes #2000

sapristi opened this issue Apr 8, 2021 · 2 comments · Fixed by #2001 or #2002
Labels
L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue

Comments

@sapristi
Copy link
Contributor

sapristi commented Apr 8, 2021

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.

@UziTech UziTech added the L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue label Apr 8, 2021
@UziTech
Copy link
Member

UziTech commented Apr 8, 2021

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]
};
}
}

@sapristi
Copy link
Contributor Author

sapristi commented Apr 9, 2021

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
Labels
L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue
Projects
None yet
2 participants