EddyLuten / mkdocs-alias-plugin

An MkDocs plugin allowing links to your pages using a custom alias
MIT License
12 stars 2 forks source link

Is it possible to force escaping double square brackets in code blocks? #1

Closed marcemv90 closed 2 years ago

marcemv90 commented 2 years ago

Hello 👋

First of all congratulations for the great plugin, I find it very useful. But now I'm facing something that maybe wasn't taken into account when the plugin was developed, or maybe I'm doing something wrong. I hope somebody can shed some light over this.

The issue happens when I want to put literally [[ something ]], enclosed by double square brackets inside a code block.

Specifically, I want to put a code block with something like:

```shell
   [[ ! -d $HOME/myfolder ]] && mkdir $HOME/myfolder
```

which renders just fine in Markdown, but the MKDocs console prints it as a warning because the double square brackets are interpreted as an alias that doesn't exist.

WARNING  -  Alias ' ! -d $HOME/myfolder ' not found in 'test.md'

I know it can be legit using aliases within code blocks, in fact I use them, but just wondering if there could be a way to force escaping them, so they are not interpreted as an alias. As said, this is not a big deal, as the website renders good, it is just to avoid that WARNING message in the console log.

Great job with the plugin! 💪

Thanks and regards.

EddyLuten commented 2 years ago

Hi @marcemv90, thanks for reporting this. You're right, I certainly didn't foresee this use case, and it's a bug that needs to be addressed.

I wonder if aliases should be allowed within fenced code blocks since any other Markdown syntax doesn't work there either. Although technically, this plugin isn't extending Markdown and processes the page before the Markdown is parsed in MkDocs, it certainly appears as an extension of Markdown while using it.

I think you're right that a kind of escape sequence is needed.

Another bug your example exposes is that the internal regex to find aliases matches spaces within the brackets, which isn't a valid use case.

Thanks for reporting the bug, and I'll include a fix/workaround for this in the next minor release. Also, thanks for using the plugin! It's always nice to see real people other than myself using it!

EddyLuten commented 2 years ago

This is now fixed in v0.4.0 using a new escape syntax. Let me know if this works for you.

marcemv90 commented 2 years ago

This is now fixed in v0.4.0 using a new escape syntax. Let me know if this works for you.

Hello @EddyLuten,

I just tried the 0.4.0 release and it seems to work like a charm, no WARNING message in the mkdocs console and the website renders good.

Many thanks for the quick fix!

Regards.