// Load the markdown-it regex plugin
const mdRegex = require('markdown-it-regexp')

// Set our chord's identifier regex pattern and replacement string
const chordPattern = mdRegex(
  // regexp to match
  // Assuming anything within square brackets to be a chord
  /\[(\w+)\]/,

  // this function will be called when something's in square brackets
  function(match, utils) {
    return '<span class="chord"><span class="inner">' + match[1] + '</span></span>';
  }
)

// Import markdown-it and configure it to use our chordpattern
const md = require('markdown-it')({
  html:         false,        // Enable HTML tags in source
  xhtmlOut:     true,         // Use '/' to close single tags (<br />).
                              // This is only for full CommonMark compatibility.
  breaks:       true,         // Convert '\n' in paragraphs into <br>
  linkify:      true,         // Autoconvert URL-like text to links

  // Enable some language-neutral replacement + quotes beautification
  typographer:  false,

  // Double + single quotes replacement pairs, when typographer enabled,
  // and smartquotes on. Could be either a String or an Array.
  quotes: '“”‘’'
}).use(chordPattern)


module.exports = {

  // Our exported function
  toHtml: function (chordMarkdownText) {
    if(chordMarkdownText === undefined) {
      throw new Error('Argument chordMarkdownText is required.');
    }
    return md.render(chordMarkdownText)
  }

}

@@ -264,13 +264,77 @@
  /%5C%5B
-(%5Cw+)
+%5BA-G%5D(#%7Cb%7Cm%7CM%7C7%7C9%7C11%7C13%7C%5C(%7C%5C)%7Cadd%7Csub%7Cdim%7Caug%7Cmaj%7Cmin)*(%5C/%5BA-G%5D#?b?)?
 %5C%5D/,

Improve the chord matching regex