Skip to content

Get image/link title offset range. #441

@frondeus

Description

@frondeus

Hello, thank you for your fantastic project.

I'm writing a small language with markdown support, and I wanted to add syntax highlighting for Neovim.
Therefore I have to parse markdown. Pulldown-cmark works great in most cases, because you provide me access to offsets via into_offset_iter().

However, this gets me a range for the whole tag. For example:

![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")

This would give me (0..112) - the range for the whole text.

There are cases when I need to process or highlight only part, for example, title, therefore I need to somehow calculate the range for both src, title, and of course, the body (displayed text, alt text, etc.).

The third one is easy, It lives under different event. The first one is also quite interesting and possible. Because it's under CowStr::Borrowed - I can perform the offset calculation (by subtracting pointers to the slice, which is, in fact, continuous memory. Note that I assume nobody made any owned event and everything is referencing to the original single source).

However, the title is under CowStr::Inlined - which means my only solution, for now, is to perform a classic search to find where exactly lives. However, even this can be tricky - what if the title has the same content as for example link or alt text?

Anyway - do you see here any possible good solution?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions