Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,3 @@ wrapping.
- `options.ignoreTags (string[], optional)` – Tags to keep intact in output (e.g., ["b", "mark"])
- `options.wrapWords (number, optional)` – Maximum words per line (takes priority over wrapLength)
- `options.wrapLength (number, optional)` – Maximum characters per line

## Examples

```ts
import { textify } from 'html-textify';

const html = `
<h1>Title</h1>
<p>Paragraph with <b>bold</b> and <i>italic</i></p>
<ul><li>Item 1</li><li>Item 2</li></ul>
`;

const text = textify({ html });
console.log(text);

/* Output:
Title

Paragraph with **bold** and *italic*

- Item 1
- Item 2
*/
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-textify",
"version": "1.0.0",
"version": "1.0.1",
"description": "Convert html to plain text",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { wrapByWords } from './utils/wrapByWords';

export interface TextifyOptions {
html: string;
preserveFormatting?: boolean; // optional, default true
ignoreTags?: string[]; // optional tags to keep intact
wrapLength?: number; // max chars per line
wrapWords?: number; // max words per line
preserveFormatting?: boolean;
ignoreTags?: string[];
wrapLength?: number;
wrapWords?: number;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/utils/preserveFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('preserveFormat', () => {

it('should handle links', () => {
const html = '<a href="https://example.com">Click here</a>';
const expected = 'Click here (https://example.com)';
const expected = '[Click here](https://example.com)';
expect(preserveFormat({ html })).toBe(expected);
});

Expand Down Expand Up @@ -119,7 +119,7 @@ describe('preserveFormat', () => {

const result = preserveFormat({ html });

const expected = `Main Heading\n\nParagraph with **bold** and *italic* text\n\n- Item 1\n- Item 2\n1. First\n2. Second\nLink (https://link.com)> Quote line 1\n> Quote line 2A1 B1\nA2 B2`;
const expected = `Main Heading\n\nParagraph with **bold** and *italic* text\n\n- Item 1\n- Item 2\n1. First\n2. Second\n[Link](https://link.com)> Quote line 1\n> Quote line 2A1 B1\nA2 B2`;
expect(result).toBe(expected);
});
});
2 changes: 1 addition & 1 deletion src/utils/preserveFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function preserveFormat({
html = !ignoreTags.includes('a')
? html.replace(
/<a\s+href="(.*?)".*?>(.*?)<\/a>/gi,
(_m, href: string, text: string) => `${text} (${href})`
(_m, href: string, text: string) => `[${text}](${href})`
)
: html;

Expand Down