George Edwards George Edwards - 3 months ago 13
Markdown Question

Extending Markdown tags without processing the code

I am working with Hexo - a nodeJS based static blogging CMS, I am extending the hexo API to register a new block tag called

tabblock
, see here:

hexo.extend.tag.register('tabblock', function (args, content) {
var tabNumber = NumberOfTabs(content);
var isTabbed = (tabNumber !== 0);
console.log("Args: " + content);
// Where my proper logic should go
result = '<h1> TAG </h1>';
return result;
}, { ends: true });


This is the source snippet I am trying to interpret:

{% tabblock %}
``` JavaScript
console.log("Double Tap");
```
``` TypeScript
console.log("Double Tap");
```
{% endtabblock %}


However, the console.log from the function which should be processing that source, outputs this:

Args: <!--0--> <!--1-->


??? I Assume this is because the code is being interpreted as code rather than content? So if I wrap the
{% tabblock %}
in
{% raw %}
tags then I get no output at all, however, if I put the raw tags inside the
tabblock
, then I get this output:

Args: {% raw


How can I get my desired content?

Answer

\``` code ```\ is interpreted by Hexo as a code block, that why it output a messy thing. Try with only 2 or 1 backstick, it will works; like this \`` code ``\

I created a tabbed-codeblock tag for Hexo, you should take a look how I did it. As you can see, I wrapped code with the hexo tag and I use this structure to separate code blocks to avoid conflict with source code.

<!-- tab [lang] -->
    code
<!-- endtab -->
<!-- tab [lang] -->
    code
<!-- endtab -->
Comments