Skip to content

Commit

Permalink
feat: Add sanitizeHeading function to html2md.js (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpauli authored Feb 12, 2024
1 parent aa6a497 commit dee0154
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/html2md.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import gfm from 'remark-gfm';
import {
imageReferences,
sanitizeTextAndFormats,
sanitizeHeading,
} from '@adobe/helix-markdown-support';
import { remarkMatter } from '@adobe/helix-markdown-support/matter';
import remarkGridTable from '@adobe/remark-gridtables';
Expand Down Expand Up @@ -263,6 +264,7 @@ export async function html2md(html, opts) {

await processImages(log, mdast, mediaHandler, url);
imageReferences(mdast);
sanitizeHeading(mdast);
sanitizeTextAndFormats(mdast);

// noinspection JSVoidFunctionReturnValueUsed
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/breaks-in-headings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title>Breaks in Headings</title>
</head>
<body>
<main>
<div>
<h1>Break<br>in<br>Heading</h1>
</div>
</main>
</body>
</html>
7 changes: 7 additions & 0 deletions test/fixtures/breaks-in-headings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Break<br>in<br>Heading

+----------------------------+
| Metadata |
+=======+====================+
| title | Breaks in Headings |
+-------+--------------------+
4 changes: 4 additions & 0 deletions test/html2md.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ describe('html2md Tests', () => {
it('convert a document with underling, sub-, and superscript', async () => {
await test('sub-sup-u');
});

it('convert a document with headline and soft breaks correctly', async () => {
await test('breaks-in-headings');
});
});

describe('className to block type tests', () => {
Expand Down

0 comments on commit dee0154

Please sign in to comment.