PrismJS / prism

Lightweight, robust, elegant syntax highlighting.
https://prismjs.com
MIT License
12.28k stars 1.3k forks source link

[AutoLinker] Only works inside comemnts #1077

Closed BjarkeCK closed 7 years ago

BjarkeCK commented 7 years ago

I'm creating a Code reference documentation wiki page, and i want certan types / elements / tags to have a custom URL. What would be the best way to go about that?

[Text you want to see](http://url-goes-here.com)

If i could use that feature from AutoLinker outside comments as well, it would solve my issue

Example public class SomeClass : [SomeBaseClass](/SomeBaseClass) public class SomeClass :SomeBaseClass

Alternatively if i could provide The WebPlatform Docs plugin with a custom dictionary of types and urls that would be great.

For now though, how would recommend me achieving this?

Golmote commented 7 years ago

Hi. I don't understand exactly what you're trying to achieve. Could you provide an online example reproducing the issue and explain the behaviour you'd expect?

Regarding the WPD plugin, that's a great a idea, though it will require some smart thinking to implement ^^

BjarkeCK commented 7 years ago

Hi,

Thansk for the reply, maybe looking at my current solution clarifies the problem :p

Prism.hooks.add('wrap', function (env) {
    if (documentationUrlTable[env.content] !== undefined) {
        env.content = "<a href='" + documentationUrlTable[env.content] + "'>" + env.content + "</a>";
    }
});

However it doesn't quite work in all cases, since it's not all types / elements that gets evaluated by the wrap hook.

But basicly, i want stuff to be clickable^^

Here is an example using csharp syntax where the wrap hook does not work.

[SkippedByTheWrapHookForSomeReason]
[NotSkippedSinceItNowsItIsAFunction()] // i guess^^
public class NotSkippedItKnowsItsAClass : BaseClassIsAlsoSkipped
{
}

Update Since csharp syntax doesn't identify classes correctly i'm just gonna go away from PrismJS. Too many complications with my current approach.

LeaVerou commented 7 years ago

Autolinker has a candidates array with token names that are candidates for autolinking. If we make this a property of Prism.autolinker then external devs can modify it for their purposes. Would that solve your use case @EliasCK?

BjarkeCK commented 7 years ago

Yeah, i think it would, then i could just add all possible tokens, and have links work everywhere.

But it turned out that in order to get proper syntax coloring i needed a much more reliable type identification than PrismJs or any other js parser out there i could find. So I ended up making a custom parser that retrieves type meta data directly from a compiled assembly in order to associate tokens with the correct types.