dafi / tocmd-generator

Table of Contents Generator for Markdown pages
MIT License
65 stars 11 forks source link

Example not working for me #4

Closed bosborne closed 7 years ago

bosborne commented 8 years ago
    <script src="/assets/jquery-1.11.3.min.js" type="text/javascript"></script>
    <script src="/assets/tocmd-generator/js/jquery.toc.js" type="text/javascript"></script>
    <script type="text/javascript">
      $('#main_content').toc({
        showAlways:true
      });
    </script>

This doesn't produce any text. No errors either. I also tried "#content" and "#page-content" (which is the id of the div that Jekyll uses, latest version). I also tried JQuery 2.1.4. Could you add a bit more to the example? Thank you in advance.

dafi commented 8 years ago

does $('.#content') or $('.#page-content') return elements?

bosborne commented 8 years ago

Get errors in the debugger with those:

Exception with thrown value: Error: Syntax error, unrecognized expression: .#page-content

Exception with thrown value: Error: Syntax error, unrecognized expression: .#content

bosborne commented 8 years ago

Should have added, this is on Mac OS, either Safari or Firefox.

dafi commented 8 years ago

jQuery can't throw error but at least returns an empty array, please check your environment because something is wrong unrelated to toc generator

bosborne commented 8 years ago

The latest tocmd-generator code also does not work at GitHub, here's an example:

http://bioperl.github.io/howtos/Beginners.html

I tried #content, #main_content, and #page-content. No TOC, and also no errors. It should make a little TOC, there are some H1's and H2's in there. I'm thinking this has to do with parsing, can you take a look at the HTML and verify that the parsing should work? Thank you in advance.

dafi commented 8 years ago

The error is in your code, you are defined page-content as class not id, try to replace the code with $('.page-content').toc();

Using the code above I can see the TOC

bosborne commented 8 years ago

This does not work, unfortunately:

    <script type="text/javascript">
      $('.page-content').toc({
        showAlways:true
      });
    </script>

See http://bioperl.github.io/howtos/Beginners.html. It might have to do with the Markdown converters that make the HTML. I am using redcarpet, what are you using? When you say the code works for you I think you are talking about HTML that's different from mine, and I'm thinking all of this has to do with parsing.That's my current hypothesis anyway.

dafi commented 8 years ago

I've added a sample demo page https://github.com/dafi/tocmd-generator/commit/9e8b9d718dc125ccd3672b85a4fd89ecbd86cf39 Tell me if it helps you