Wikipedia style links work! No more custom syntax :)

I need help with excluding results from Markdown fenced code blocks though. Can anyone guide me through this? I.e. Match [[link]] but not <code>[[link]]</code>

Here's my regex: (?!<code.?)(?:\[\[)(.+?)(?:\]\])(?!.?>)

· · Web · 1 · 0 · 0

@stephen Markdown parser creates the HTML, so I'd need to either ignore results between backticks (` or ```) or <code> blocks.

@hxii if you're already using markdown, why not use markdown-style links?

@stephen internal links for wiki, e.g. [[article title]]

@hxii ah, okay. So you're parsing these with php before the page is served, or with javascript on the client-side?

@stephen PHP, so currently Parsedown parses the Markdown into HTML and then I use:
preg_match_all('/(?<!<code)\[\[([^\]\[]*)\]\](?!\<\/code>)/', $data, $internal_links, PREG_SET_ORDER);

But I still get weird matches.

@hxii indeed. I believe that's why the common wisdom is "don't parse html with regex."

@hxii Are you using a php framework, or is it a homegrown application?

@hxii Actually, if you're using Parsedown you may want to write an extension for it instead – that way you can deal with the data in the right domain. Implement your internal links there, rather than regex-ing the Parsedown output.

Sign in to participate in the conversation

Merveilles is a community project aimed at the establishment of new ways of speaking, seeing and organizing information — A culture that seeks augmentation through the arts of engineering and design. A warm welcome to any like-minded people who feel these ideals resonate with them.