docsify

I cannot install the copy code plugin for docsify


I am trying to install the docsify copy code plugin. However it doesn't work nothing change in my HTML yet I did all the required steps to make this works.

<script src="//cdn.jsdelivr.net/npm/docsify-copy-code"></script>
<script>
window.$docsify = {

      copyCode: {
        buttonText : 'Copy to clipboard',
        errorText  : 'Error',
        successText: 'Copied'
      },
      plugins: [
        window.DocsifyCopyCodePlugin.init()
      ]
    }
<srcipt>

Any suggestion ?


Solution

  • The order you load scripts is important in docsify. You start by defining your configuration (window.$docsify), then loading the main script and finally adding any plugins.

    Here are your tags in the right order so they should work together :

    <!-- Configuration -->
    <script>
    window.$docsify = {
          copyCode: {
            buttonText : 'Copy to clipboard',
            errorText  : 'Error',
            successText: 'Copied'
          }
        }
    </script>
    <!-- Main Script -->
    <script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script>
    <!-- Docsify plugins -->
    <script src="//cdn.jsdelivr.net/npm/docsify-copy-code"></script>
    

    Also usage of the init function of plugins is usually not required as they'll init as soon as they load.