Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow ignoring class when finding parent elements that satisfy html path #308

Open
hmnd opened this issue Jan 19, 2022 · 0 comments
Open

Comments

@hmnd
Copy link

hmnd commented Jan 19, 2022

Issue

Currently, there is no way to instruct mammoth to ignore classes when finding a parent element to nest within. This presents a problem when trying to nest elements within elements that have varying classes set using style maps.

Example

With this style map:

{
  styleMap: [
    "p:ordered-list(1).list-type-decimal => ol.decimal > li:fresh",
    "p:ordered-list(2).list-type-decimal => ol|ul > li > ol.decimal > li:fresh",
    "p:ordered-list(1).list-type-lower-alpha => ol.alpha > li:fresh",
    "p:ordered-list(2).list-type-lower-alpha => ol|ul > li > ol.alpha > li:fresh",
    "p:ordered-list(1).list-type-roman-numeral => ol.roman> li:fresh",
    "p:ordered-list(2).list-type-roman-numeral => ol|ul > li > ol.roman> li:fresh",
  ],
}

This file would be expected to render like so (assuming the classes set the list-style-type with CSS):

<ol class="decimal">
  <li>
    Test
    <ol class="alpha">
      <li>
        Test
        <ol class="roman">
          <li>Test</li>
        </ol>
      </li>
    </ol>
  </li>
</ol>
<p>Test</p>
<p>Test</p>
<p>Test</p>
1. Test
    a. Test
        i. Test
Test
    Test
        Test

However, because the ol.alpha is not nested within an ol and our ol has a class applies to it, a new parent element is created. The document is actually rendered like so:

<ol class="decimal">
  <li>Test</li>
</ol>
<ol>
  <li>
    <ol class="alpha">
      <li>Test</li>
    </ol>
    <ul>
      <li>
        <ol class="roman">
          <li>Test</li>
        </ol>
      </li>
    </ul>
  </li>
</ol>
<p>Test</p>
<p>Test</p>
<p>Test</p>

1. Test
1.    1. Test
      •    i. Test
Test
    Test
        Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants