Markdown extension: inline wrap functions doesn't recognize BBCode tags with empty content anymore

I’m using this code in my plugin:

helper.allowList(['span.dpg-balloon-text'])

helper.registerPlugin(md => {
  md.inline.bbcode.ruler.push('dpgb', {
    tag: 'dpgb',
    wrap: function (startToken, endToken, tagInfo) {
      startToken.tag = endToken.tag = 'span'
      startToken.content = endToken.content = ''
      startToken.type = "span_open";
      endToken.type = "span_close";    
      startToken.nesting = 1;
      endToken.nesting = -1;    
      startToken.attrs = [['class', 'dpg-balloon-text']].concat(
        Object.keys(tagInfo.attrs).map(key => [
          `data-dpg-${key}`,
          tagInfo.attrs[key]
        ])
      )
    }
  })
})

The above used to work on both empty and non-empty BBCode tags. But I’ve discovered today that now it only triggers when the BBCode tag has content (such as [dpgb]Some content[/dpgb]) and fails to trigger when the BBCode tag has non content (such as [dpgb][/dpgb]). Is it a new design choice?

2 Likes

Not sure, can you dig through the source to see the commit that made the behavior change?

2 Likes

The upgrade to Markdown.it v13 broke empty inline BBCodes The behavior of the processDelimiters function changed. It doesn’t update the end attribute of our BBCode delimiters anymore when the BBCode doesn’t have any content.

I’ve created a PR that restores the previous behavior and adds a test.

2 Likes