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

inline-token has content? #184

Closed
iliakan opened this issue Jan 1, 2016 · 2 comments
Closed

inline-token has content? #184

iliakan opened this issue Jan 1, 2016 · 2 comments

Comments

@iliakan
Copy link

iliakan commented Jan 1, 2016

A regular inline-token has .content with it's text.

E.g: https://markdown-it.github.io/#md3=%7B%22source%22%3A%22!%5Bdesc%20%2Ame%2A%7Cheight%3D100%5D%28fig.png%20%5C%22title%5C%22%29%22%2C%22defaults%22%3A%7B%22html%22%3Afalse%2C%22xhtmlOut%22%3Afalse%2C%22breaks%22%3Afalse%2C%22langPrefix%22%3A%22language-%22%2C%22linkify%22%3Atrue%2C%22typographer%22%3Atrue%2C%22_highlight%22%3Atrue%2C%22_strict%22%3Afalse%2C%22_view%22%3A%22debug%22%7D%7D

Note the "content": "my *inline* token" in the inline tag.

But in case of an image, the image alt forms 1 more children level. A one more inline token. Here it has no content: https://markdown-it.github.io/#md3=%7B%22source%22%3A%22!%5Bdesc%20%2Ame%2A%7Cheight%3D100%5D%28fig.png%29%22%2C%22defaults%22%3A%7B%22html%22%3Afalse%2C%22xhtmlOut%22%3Afalse%2C%22breaks%22%3Afalse%2C%22langPrefix%22%3A%22language-%22%2C%22linkify%22%3Atrue%2C%22typographer%22%3Atrue%2C%22_highlight%22%3Atrue%2C%22_strict%22%3Afalse%2C%22_view%22%3A%22debug%22%7D%7D

Note that the 1st-level inline tag actually has the content: "content": "![desc *me*|height=100](fig.png)".

But what's different with the image tag: it has children, but it's content is empty.
I'd suggest to let it has a string in content just like the regular inline-tag.

Guess the patch should be somewhere here: https://github.com/markdown-it/markdown-it/blob/master/lib/rules_inline/image.js#L139 (if appropriate).

@rlidwka
Copy link
Member

rlidwka commented Jan 4, 2016

We could easily add "content" to this tag, just add this line somewhere below:

token.content = state.src.slice(labelStart, labelEnd);

But children property is there to stay, because with the current tag structure it seems to be only good way to conform to CommonMark tests (img tag has an alt attribute with markdown syntax stripped out, so we'd need to store this markdown syntax somewhere).

@rlidwka rlidwka closed this as completed in f2344b5 Jan 4, 2016
@rlidwka
Copy link
Member

rlidwka commented Jan 4, 2016

content property added, thanks for the suggestion!

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

No branches or pull requests

2 participants