Topic on Extension talk:SyntaxHighlight

SomeArthena (talkcontribs)

Hello, I am reading everywhere it is not possible to embed links into code blocks.

However, I have seen it being done on cppreference.com, and they also use this extension, so there must be some hack or something.

I don't mind if I have to update something inside the extension.

PerfektesChaos (talkcontribs)

By definition any content than </syntaxhighlight> will be produced as regular text on wiki page.

  • However, people might post-process the result of this extension.
  • They could interact on server side with the API of the pygments software.
  • They could manipulate the generated HTML document on client side by JavaScript, identifying interesting things like URL and link those URL, or other connected formats and identified items. Every token is an HTML element equipped with a class, which makes it easy to find certain types of items, analyse this text and replace the plain text content by a HTML link to somewhere.
  • You might even try to integrate HTML link generation into your language.

Greetings

213.147.167.226 (talkcontribs)

Ah got it, so I won't get around writing my own extension.

Thanks for the elaborate answer, appreciate it. :)

BDavis (WMF) (talkcontribs)

cppreference.com is running a version of MediaWiki and SyntaxHighlight from 2013, so feature comparisons are questionable in any case. The version of SyntaxHighlight in use there would have still used GeSHi as the highlighting engine. The modern extension uses Pygments which is not only a different implementation, it is also written in a different programming language.

PerfektesChaos (talkcontribs)

Example for JavaScript postprocessing:

  • de:Hilfe:Textgestaltung/HTML
  • Find all elements (which should be descendants of the <syntaxhighlight> blocks) which match the span.nt selector.
  • Read the content of the span, create an URL to a website explaining HTML elements, linking this particular tag name. Wrap the span into an a href="" element.

Enjoy

Reply to "Links in code block"