Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix skipNoIDs logic when more IDs in other HTML elements #42

Merged
merged 2 commits into from
Jul 19, 2020

Conversation

WeixuanZ
Copy link
Contributor

Related to PR #32 & #33.

Currently, headers without ids would still be added to the TOC with skipNoIDs=true if there are ids in other HTML elements between two headers.

Markdown

{% capture markdown %}
## Sample Usage

<div>
  <h1 class="page-title">My Awesome Example Page</h1>
  <h2 class="page-subtitle">With an awesome subtitle</h2>
    <a href='/' id="dummy-link">Dummy Link</a>
</div>

### Known Problems

Lots!

### Resources

#### Paid

#### Free
{% endcapture %}
{% assign text = markdown | markdownify %}

TOC Usage

{% include toc.html html=text skipNoIDs=true %}

Expected TOC

<ul>
    <li>
        <a href="#sample-usage">Sample Usage</a>
        <ul>
            <li>
                <a href="#known-problems">Known Problems</a>
            </li>
            <li>
                <a href="#resources">Resources</a>
                <ul>
                    <li>
                        <a href="#paid">Paid</a>
                    </li>
                    <li>
                        <a href="#free">Free</a>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

Actual TOC

<ul>
  <li><a href="#sample-usage">Sample Usage</a></li>
  <li>With an awesome subtitle
    <ul>
      <li><a href="#known-problems">Known Problems</a></li>
      <li><a href="#resources">Resources</a>
        <ul>
          <li><a href="#paid">Paid</a></li>
          <li><a href="#free">Free</a></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

Now TOC entry will not be generated when skipNoIDs=true, in situations where some HTML with an id exist between two headers.

Its corresponding unit test `_tests/sktipHeadingsWithNoIDs.md` was modified accordingly.
@allejo allejo self-requested a review July 16, 2020 15:22
Copy link
Owner

@allejo allejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

_tests/skipHeadingsWithNoIDs.md Outdated Show resolved Hide resolved
@allejo allejo changed the title Modifying skipNoIDs logic Fix skipNoIDs logic when more IDs in other HTML elements Jul 19, 2020
@allejo allejo merged commit 8647f38 into allejo:master Jul 19, 2020
@allejo
Copy link
Owner

allejo commented Jul 19, 2020

Tagged as v1.0.13

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants