Skip to content

Commit

Permalink
Revert "fix: Revert "fix: nested lists roundtrip" (#539)"
Browse files Browse the repository at this point in the history
This reverts commit ea645a9.
  • Loading branch information
maxakuru authored Sep 6, 2024
1 parent e92af55 commit 88392b9
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"deploy": "hedy -v --deploy --test",
"deploy-routes": "hedy --no-build --no-hints -l major",
"deploy-ci": "hedy -v --deploy --test --pkgVersion=ci$CI_BUILD_NUM -l ci --cleanup-ci 24h",
"prepare": "husky install"
"prepare": "husky"
},
"wsk": {
"target": "aws",
Expand Down
2 changes: 2 additions & 0 deletions src/html2md.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
TYPE_GRID_TABLE, TYPE_GT_BODY, TYPE_GT_CELL, TYPE_GT_ROW, handleTableAsGridTable,
} from './mdast-table-handler.js';
import formatPlugin from './markdownFormatPlugin.js';
import { unspreadLists } from './unspread-lists.js';

function m(type, children, props = {}) {
return {
Expand Down Expand Up @@ -282,6 +283,7 @@ export async function html2md(html, opts) {
imageReferences(mdast);
sanitizeHeading(mdast);
sanitizeTextAndFormats(mdast);
unspreadLists(mdast);

// noinspection JSVoidFunctionReturnValueUsed
const md = unified()
Expand Down
26 changes: 26 additions & 0 deletions src/unspread-lists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import { visit, CONTINUE } from 'unist-util-visit';

/**
* Collapse (un-spread) all lists
* @param {object} tree
*/
export function unspreadLists(tree) {
visit(tree, (node) => {
if (node.type === 'list' || node.type === 'listItem') {
// eslint-disable-next-line no-param-reassign
node.spread = false;
}
return CONTINUE;
});
}
4 changes: 0 additions & 4 deletions test/fixtures/codeblock.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
| Procedure |
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| 1. Log in to Azure with the Azure CLI. |
| |
| 2. Query Azure for your tenant and subscription IDs. . |
| |
| ``` |
| az account list |
| ``` |
| |
| 3. Copy the output which is similar to the following example. In the output, identify the `tenantId` tenant ID and the `id` of the subscription. |
| |
| ```bash |
| "cloudName": "AzureCloud", |
| "homeTenantId": <This value is not needed>, |
Expand Down
27 changes: 27 additions & 0 deletions test/roundtrip/roundtrip-fixtures/nested-lists.input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>

<head>
<title>Nested Lists</title>
</head>

<body>
<main>
<div>
<ul>
<li><a href="#" title="Navigate to Text 1">Text 1</a></li>
<li><a href="#" title="Navigate to Text 2">Text 2</a>
<ul>
<li><a href="#" title="Navigate to Text 2 / 1">Text 2 / 1</a>
<ul>
<li><a href="#" title="Navigate to Text 2 / 1 / 1">Text 2 / 1 / 1</a></li>
<li><a href="#" title="Navigate to Text 2 / 1 / 2">Text 2 / 1 / 2</a></li>
<li><a href="#" title="Navigate to Text 2 / 1 / 3">Text 2 / 1 / 3</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</main>
</body>
36 changes: 36 additions & 0 deletions test/roundtrip/roundtrip-fixtures/nested-lists.output.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>Nested Lists</title>
<link rel="canonical" href="https://undefined/">
<meta property="og:title" content="Nested Lists">
<meta property="og:url" content="https://undefined/">
<meta property="og:image" content="https://undefined/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<meta property="og:image:secure_url" content="https://undefined/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Nested Lists">
<meta name="twitter:image" content="https://undefined/default-meta-image.png?width=1200&#x26;format=pjpg&#x26;optimize=medium">
</head>
<body>
<header></header>
<main>
<div>
<ul>
<li><a href="#" title="Navigate to Text 1">Text 1</a></li>
<li><a href="#" title="Navigate to Text 2">Text 2</a>
<ul>
<li><a href="#" title="Navigate to Text 2 / 1">Text 2 / 1</a>
<ul>
<li><a href="#" title="Navigate to Text 2 / 1 / 1">Text 2 / 1 / 1</a></li>
<li><a href="#" title="Navigate to Text 2 / 1 / 2">Text 2 / 1 / 2</a></li>
<li><a href="#" title="Navigate to Text 2 / 1 / 3">Text 2 / 1 / 3</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</main>
<footer></footer>
</body>
</html>
1 change: 1 addition & 0 deletions test/roundtrip/roundtrip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const specs = [
'some-text',
'all-sections',
'microdata',
'nested-lists',
];

describe('Roundtrip tests', () => {
Expand Down

0 comments on commit 88392b9

Please sign in to comment.