New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@notable/html2markdown

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@notable/html2markdown - npm Package Compare versions

Comparing version 1.1.3 to 2.0.0

dist/utils.d.ts

5

dist/index.d.ts

@@ -1,5 +0,4 @@

/// <reference types="turndown" />
import type { Options } from './types.js';
declare const html2markdown: (html: string, options?: import("turndown").Options | undefined) => string;
import type { Options, TurndownOptions } from './types.js';
declare const html2markdown: (html: string, options?: TurndownOptions) => string;
export default html2markdown;
export type { Options };

50

dist/index.js

@@ -1,11 +0,7 @@

"use strict";
/* IMPORT */
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mime_1 = __importDefault(require("./mime"));
const turndown_1 = __importDefault(require("./turndown"));
const turndown_plugin_tables_1 = __importDefault(require("./turndown.plugin.tables"));
const turndown_plugin_tasks_1 = __importDefault(require("./turndown.plugin.tasks"));
import Mime from './mime.js';
import turndown from './turndown.js';
import turndownPluginTables from './turndown.plugin.tables.js';
import turndownPluginTasks from './turndown.plugin.tasks.js';
import { isElement } from './utils.js';
/* MAIN */

@@ -29,5 +25,5 @@ // Custom elements are transformed into regular non-empty "<div>" elements, otherwise they will be ignored

/* TURNDOWN */
const service = (0, turndown_1.default)(options);
service.use(turndown_plugin_tables_1.default);
service.use(turndown_plugin_tasks_1.default);
const service = turndown(options);
service.use(turndownPluginTables);
service.use(turndownPluginTasks);
service.addRule('strikethrough', {

@@ -53,7 +49,9 @@ filter: ['del', 's'],

filter: node => node.nodeName !== 'TABLE' && node.nodeName !== 'TR' && node.nodeName !== 'TD' && node.nodeName !== 'TH' && (node.getAttribute('style') || '').includes('text-align:'),
replacement: (str, ele) => {
replacement: (str, element) => {
if (!isElement(element))
return str;
str = str.trim();
if (!str.length)
return '';
const style = ele.getAttribute('style');
const style = element.getAttribute('style');
if (!style)

@@ -64,3 +62,3 @@ return '';

return `${str}\n\n`;
const nodeName = ele.nodeName;
const nodeName = element.nodeName;
const tag = /^h\d$/i.test(nodeName) ? nodeName.toLowerCase() : 'p';

@@ -85,7 +83,9 @@ if (str.includes('\n'))

filter: node => node.nodeName === 'DIV' && node.getAttribute('node') === 'EN-MEDIA' && !!node.getAttribute('hash') && !!node.getAttribute('type'),
replacement: (str, ele) => {
const hash = ele.getAttribute('hash');
const type = ele.getAttribute('type') || '';
const filename = `${hash}${mime_1.default.getExtension(type)}`;
const isImage = mime_1.default.isImage(type);
replacement: (str, element) => {
if (!isElement(element))
return str;
const hash = element.getAttribute('hash');
const type = element.getAttribute('type') || '';
const filename = `${hash}${Mime.getExtension(type)}`;
const isImage = Mime.isImage(type);
if (isImage) {

@@ -101,7 +101,9 @@ return `<img src="@attachment/${filename}" />`;

filter: ['font', 'span'],
replacement: (str, ele) => {
replacement: (str, element) => {
if (!isElement(element))
return str;
if (!str.trim())
return '';
/* STYLE */
const style = ele.getAttribute('style');
const style = element.getAttribute('style');
let newStyle = '';

@@ -153,3 +155,3 @@ if (style) {

/* COLOR */
const colorAttr = ele.getAttribute('color'); // Color
const colorAttr = element.getAttribute('color'); // Color
if (colorAttr && colorAttr !== '#010101') {

@@ -188,2 +190,2 @@ newStyle += `color: ${colorAttr};`;

/* EXPORT */
exports.default = html2markdown;
export default html2markdown;

@@ -1,8 +0,3 @@

"use strict";
/* IMPORT */
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mime2ext_1 = __importDefault(require("mime2ext"));
import mime2ext from 'mime2ext';
/* MAIN */

@@ -12,3 +7,3 @@ const Mime = {

getExtension: (mime) => {
const ext = (0, mime2ext_1.default)(mime);
const ext = mime2ext(mime);
return ext ? `.${ext}` : '';

@@ -21,2 +16,2 @@ },

/* EXPORT */
exports.default = Mime;
export default Mime;

@@ -1,4 +0,2 @@

"use strict";
// @ts-nocheck
Object.defineProperty(exports, "__esModule", { value: true });
function extend(destination) {

@@ -736,2 +734,2 @@ for (var i = 1; i < arguments.length; i++) {

}
exports.default = TurndownService;
export default TurndownService;

@@ -1,4 +0,2 @@

"use strict";
// @ts-nocheck
Object.defineProperty(exports, "__esModule", { value: true });
var indexOf = Array.prototype.indexOf;

@@ -72,3 +70,3 @@ var every = Array.prototype.every;

}
function tables(turndownService) {
export default function tables(turndownService) {
// Better to convert malformed tables too, more convenient

@@ -81,2 +79,1 @@ // turndownService.keep(function (node) {

}
exports.default = tables;

@@ -1,5 +0,3 @@

"use strict";
// @ts-nocheck
Object.defineProperty(exports, "__esModule", { value: true });
function taskListItems(turndownService) {
export default function taskListItems(turndownService) {
turndownService.addRule('taskListItems', {

@@ -14,2 +12,1 @@ filter: function (node) {

}
exports.default = taskListItems;

@@ -15,2 +15,2 @@ declare type Options = {

declare type TurndownService = import('turndown');
export { Options, TurndownOptions, TurndownService };
export type { Options, TurndownOptions, TurndownService };

@@ -1,3 +0,2 @@

"use strict";
/* MAIN */
Object.defineProperty(exports, "__esModule", { value: true });
export {};
{
"name": "@notable/html2markdown",
"repository": "github:fabiospampinato/@notable/html2markdown",
"description": "A small function for converting HTML to Markdown.",
"version": "1.1.3",
"version": "2.0.0",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rimraf dist",
"compile": "tsc --skipLibCheck",
"compile:watch": "tsc --skipLibCheck --watch",
"test": "fava",
"test:watch": "fava -w",
"clean": "tsex clean",
"compile": "tsex compile",
"compile:watch": "tsex compile --watch",
"test": "tsex test",
"test:watch": "tsex test --watch",
"prepublishOnly": "npm run clean && npm run compile && npm run test"
},
"bugs": {
"url": "https://github.com/fabiospampinato/html2markdown/issues"
},
"license": "MIT",
"author": {
"name": "Fabio Spampinato",
"email": "spampinabio@gmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/fabiospampinato/html2markdown.git"
},
"keywords": [

@@ -33,3 +24,3 @@ "html",

"dependencies": {
"mime2ext": "^1.0.1"
"mime2ext": "^2.0.0"
},

@@ -39,6 +30,6 @@ "devDependencies": {

"domino": "^2.1.6",
"fava": "^0.0.5",
"rimraf": "^3.0.2",
"typescript": "^4.6.3"
"fava": "^0.0.6",
"tsex": "^1.1.2",
"typescript": "^4.8.4"
}
}

@@ -8,2 +8,3 @@

import turndownPluginTasks from './turndown.plugin.tasks';
import {isElement} from './utils';
import type {Options, TurndownOptions, TurndownService} from './types.js';

@@ -63,10 +64,11 @@

filter: node => node.nodeName !== 'TABLE' && node.nodeName !== 'TR' && node.nodeName !== 'TD' && node.nodeName !== 'TH' && ( node.getAttribute ( 'style' ) || '' ).includes ( 'text-align:' ),
replacement: ( str, ele: HTMLElement ) => {
replacement: ( str, element ) => {
if ( !isElement ( element ) ) return str;
str = str.trim ();
if ( !str.length ) return '';
const style = ele.getAttribute ( 'style' );
const style = element.getAttribute ( 'style' );
if ( !style ) return '';
const alignment = style.match ( /text-align:\s*(\S+?);/ );
if ( !alignment ) return `${str}\n\n`;
const nodeName = ele.nodeName;
const nodeName = element.nodeName;
const tag = /^h\d$/i.test ( nodeName ) ? nodeName.toLowerCase () : 'p';

@@ -91,5 +93,6 @@ if ( str.includes ( '\n' ) ) str = `\n\n${str}\n\n`;

filter: node => node.nodeName === 'DIV' && node.getAttribute ( 'node' ) === 'EN-MEDIA' && !!node.getAttribute ( 'hash' ) && !!node.getAttribute ( 'type' ),
replacement: ( str, ele: HTMLElement ) => {
const hash = ele.getAttribute ( 'hash' );
const type = ele.getAttribute ( 'type' ) || '';
replacement: ( str, element ) => {
if ( !isElement ( element ) ) return str;
const hash = element.getAttribute ( 'hash' );
const type = element.getAttribute ( 'type' ) || '';
const filename = `${hash}${Mime.getExtension ( type )}`;

@@ -107,6 +110,7 @@ const isImage = Mime.isImage ( type );

filter: ['font', 'span'],
replacement: ( str, ele: HTMLElement ) => {
replacement: ( str, element ) => {
if ( !isElement ( element ) ) return str;
if ( !str.trim () ) return '';
/* STYLE */
const style = ele.getAttribute ( 'style' );
const style = element.getAttribute ( 'style' );
let newStyle = '';

@@ -153,3 +157,3 @@ if ( style ) {

/* COLOR */
const colorAttr = ele.getAttribute ( 'color' ); // Color
const colorAttr = element.getAttribute ( 'color' ); // Color
if ( colorAttr && colorAttr !== '#010101' ) {

@@ -156,0 +160,0 @@ newStyle += `color: ${colorAttr};`

@@ -23,2 +23,2 @@

export {Options, TurndownOptions, TurndownService};
export type {Options, TurndownOptions, TurndownService};
/* IMPORT */
const domino = require ( 'domino' );
const {describe} = require ( 'fava' );
const fs = require ( 'fs' );
const path = require ( 'path' );
const {default: html2markdown} = require ( '../dist' );
import domino from 'domino';
import {describe} from 'fava';
import fs from 'node:fs';
import path from 'node:path';
import html2markdown from '../dist/index.js';

@@ -34,4 +34,4 @@ /* HELPERS */

const inputPath = path.join ( __dirname, 'fixtures', 'input.html' );
const outputPath = path.join ( __dirname, 'fixtures', 'output.md' );
const inputPath = path.join ( process.cwd (), 'test', 'fixtures', 'input.html' );
const outputPath = path.join ( process.cwd (), 'test', 'fixtures', 'output.md' );
const input = fs.readFileSync ( inputPath, 'utf8' ).trimEnd ();

@@ -38,0 +38,0 @@ const output = fs.readFileSync ( outputPath, 'utf8' ).trimEnd ();

{
"compilerOptions": {
"alwaysStrict": true,
"declaration": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"inlineSourceMap": false,
"jsx": "react",
"lib": ["dom", "esnext"],
"module": "commonjs",
"moduleResolution": "node",
"newLine": "LF",
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
"outDir": "dist",
"pretty": true,
"resolveJsonModule": true,
"strictNullChecks": true,
"target": "es2020"
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
"extends": "tsex/tsconfig.json"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc