Plans to support Markdownit Ruler for BBCode?

AI-generated summary

The discussion revolves around the feasibility and need for supporting Markdownit’s Ruler in BBCode for greater flexibility in enabling/disabling rules during parsing. hawm explains that the current custom Ruler doesn’t allow dynamic rule control, which limits functionality—such as conditionally parsing BBCode content. They suggest using the Ruler to enable rules only when needed, similar to native Markdownit behavior. sam questions the necessity, suggesting it might be better handled via a custom plugin. TheDarkWizard proposes an alternative project, but hawm clarifies that their use case differs, focusing on maintaining existing BBCode logic while improving parsing control. The conversation highlights a desire for more modular and maintainable BBCode handling within Markdownit, though the need for core implementation remains debated.

My use case is to disable/enable bbcode rules when using the replace rule of bbcode.

replace: function (state, tagInfo, content) {
  const source = state.push("my_token", "div", 0);
  try {
    md.block.bbcode.ruler.disable("ruleName")
    source.children = state.md.parse(content, {});
  } finally {
    md.block.bbcode.ruler.enable("ruleName")
  }
  return true
}

I noticed that the TODO comment here was from a long time ago, any plans to implement it?

I guess my #1 question here is why? what problems would this solve?

Would our project interest you instead? We are getting closer to the end:

https://github.com/RpNation/bbcode

We determined that using markdownit for any complex bbcode was a pain, so we are inserting bbob into Discourse instead.

Move to markdownit ruler will allow to enable/disable rules when starting a new parse, it makes flexibility and behavior like the native markdownit rules.

For example, I want to push some bbcode rules but not enable them by default, then enable them when I need them (like the example on the OP). Currently, this is not possible with the custom Ruler, maybe can do that with some tricky (through the parse env or modify the rules of ruler manually)?

[foo]
not wrapping inside the bar should not tokenize
[/foo]

[bar]
[foo]
wrap inside the bar should be tokenized
[/foo]
[/bar]

The reason why I’m not creating native markdownit rules other than using the bbcode is implementing rules like bbcode will be difficult and hard to maintain, and bbcode is already here.


Great job, but my use case is something different.

And I like your code here which inspires me on the other concern problems.

As in treat all bbcode like [wrap] is treated now? wrap them in in divs?

I would say what you are describing sound like a custom markdownit rule / plugin vs something core needs to implement?