chore(turndown-plugin-gfm): integrate tests

This commit is contained in:
Elian Doran 2025-04-28 23:27:00 +03:00
parent b9af4e4e28
commit 64f315437e
No known key found for this signature in database
12 changed files with 2078 additions and 156 deletions

View File

@ -1,5 +0,0 @@
dist
lib
node_modules
npm-debug.log
test/*browser.js

View File

@ -1,4 +0,0 @@
language: node_js
node_js:
- "node"
- "6"

View File

@ -1,64 +0,0 @@
# turndown-plugin-gfm
A [Turndown](https://github.com/domchristie/turndown) plugin which adds GitHub Flavored Markdown extensions.
This is a fork of the original [turndown-plugin-gfm](https://github.com/domchristie/turndown-plugin-gfm) for use with [Joplin](https://github.com/laurent22/joplin). The changes are:
- New: Always render tables even if they don't have a header.
- New: Don't render the border of tables that contain other tables (frequent for websites that do the layout using tables). Only render the inner tables, if any, and if they also don't contain other tables.
- New: Replace newlines (`\n`) with `<br>` inside table cells so that multi-line content is displayed correctly as Markdown.
- New: Table cells are at least three characters long (padded with spaces) so that they render correctly in GFM-compliant renderers.
- New: Handle colspan in TD tags
- Fixed: Ensure there are no blank lines inside tables (due for example to an empty `<tr>` tag)
- Fixed: Fixed importing tables that contain pipes.
## Installation
npm:
```
npm install @joplin/turndown-plugin-gfm
```
## Usage
```js
// For Node.js
var TurndownService = require('@joplin/turndown')
var turndownPluginGfm = require('@joplin/turndown-plugin-gfm')
var gfm = turndownPluginGfm.gfm
var turndownService = new TurndownService()
turndownService.use(gfm)
var markdown = turndownService.turndown('<strike>Hello world!</strike>')
```
turndown-plugin-gfm is a suite of plugins which can be applied individually. The available plugins are as follows:
- `strikethrough` (for converting `<strike>`, `<s>`, and `<del>` elements)
- `tables`
- `taskListItems`
- `gfm` (which applies all of the above)
So for example, if you only wish to convert tables:
```js
var tables = require('@joplin/turndown-plugin-gfm').tables
var turndownService = new TurndownService()
turndownService.use(tables)
```
### Typescript
To use this in a typescript project, add this to a `declarations.d.ts` file, as described in https://www.npmjs.com/package/@joplin/turndown, and then add:
```ts
declare module "@joplin/turndown-plugin-gfm" {
export const gfm: any;
// Add other named exports if necessary
}
```
## License
turndown-plugin-gfm is copyright © 2017+ Dom Christie and released under the MIT license.

View File

@ -1,8 +0,0 @@
#!/bin/bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT_DIR="$SCRIPT_DIR/../.."
npm run build
cd $ROOT_DIR/packages/app-cli && npm run test -- HtmlToMd

View File

@ -1,40 +0,0 @@
{
"name": "@triliumnext/turndown-plugin-gfm",
"description": "Turndown plugin to add GitHub Flavored Markdown extensions.",
"publishConfig": {
"access": "public"
},
"version": "1.0.61",
"author": "Dom Christie",
"main": "src/gfm.js",
"devDependencies": {
"browserify": "^17.0.1",
"rollup": "^4.36.0",
"standard": "^17.1.2",
"turndown": "7.2.0",
"turndown-attendant": "0.0.3"
},
"files": [
"lib",
"dist"
],
"keywords": [
"turndown",
"turndown-plugin",
"html-to-markdown",
"html",
"markdown",
"github-flavored-markdown",
"gfm"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/laurent22/joplin-turndown-plugin-gfm.git"
},
"type": "module",
"scripts": {
"build-test": "browserify test/turndown-plugin-gfm-test.js --outfile test/turndown-plugin-gfm-test.browser.js"
},
"gitHead": "05a29b450962bf05a8642bbd39446a1f679a96ba"
}

View File

@ -1,3 +0,0 @@
#!/bin/bash
npm version patch
npm publish

View File

@ -1,13 +0,0 @@
const Attendant = require('turndown-attendant');
const TurndownService = require('turndown');
const gfm = require('../lib/turndown-plugin-gfm.cjs').gfm;
const attendant = new Attendant({
file: `${__dirname}/index.html`,
TurndownService: TurndownService,
beforeEach: function(turndownService) {
turndownService.use(gfm);
},
});
attendant.run();

View File

@ -1,7 +1,64 @@
# turndown-plugin-gfm
This library was generated with [Nx](https://nx.dev).
A [Turndown](https://github.com/domchristie/turndown) plugin which adds GitHub Flavored Markdown extensions.
## Building
This is a fork of the original [turndown-plugin-gfm](https://github.com/domchristie/turndown-plugin-gfm) for use with [Joplin](https://github.com/laurent22/joplin). The changes are:
Run `nx build turndown-plugin-gfm` to build the library.
- New: Always render tables even if they don't have a header.
- New: Don't render the border of tables that contain other tables (frequent for websites that do the layout using tables). Only render the inner tables, if any, and if they also don't contain other tables.
- New: Replace newlines (`\n`) with `<br>` inside table cells so that multi-line content is displayed correctly as Markdown.
- New: Table cells are at least three characters long (padded with spaces) so that they render correctly in GFM-compliant renderers.
- New: Handle colspan in TD tags
- Fixed: Ensure there are no blank lines inside tables (due for example to an empty `<tr>` tag)
- Fixed: Fixed importing tables that contain pipes.
## Installation
npm:
```
npm install @joplin/turndown-plugin-gfm
```
## Usage
```js
// For Node.js
var TurndownService = require('@joplin/turndown')
var turndownPluginGfm = require('@joplin/turndown-plugin-gfm')
var gfm = turndownPluginGfm.gfm
var turndownService = new TurndownService()
turndownService.use(gfm)
var markdown = turndownService.turndown('<strike>Hello world!</strike>')
```
turndown-plugin-gfm is a suite of plugins which can be applied individually. The available plugins are as follows:
- `strikethrough` (for converting `<strike>`, `<s>`, and `<del>` elements)
- `tables`
- `taskListItems`
- `gfm` (which applies all of the above)
So for example, if you only wish to convert tables:
```js
var tables = require('@joplin/turndown-plugin-gfm').tables
var turndownService = new TurndownService()
turndownService.use(tables)
```
### Typescript
To use this in a typescript project, add this to a `declarations.d.ts` file, as described in https://www.npmjs.com/package/@joplin/turndown, and then add:
```ts
declare module "@joplin/turndown-plugin-gfm" {
export const gfm: any;
// Add other named exports if necessary
}
```
## License
turndown-plugin-gfm is copyright © 2017+ Dom Christie and released under the MIT license.

View File

@ -1,6 +1,8 @@
{
"name": "@triliumnext/turndown-plugin-gfm",
"version": "0.0.1",
"version": "1.0.61",
"description": "Turndown plugin to add GitHub Flavored Markdown extensions.",
"author": "Dom Christie",
"private": true,
"type": "module",
"main": "./dist/index.js",
@ -15,6 +17,21 @@
"default": "./dist/index.js"
}
},
"gitHead": "05a29b450962bf05a8642bbd39446a1f679a96ba",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/laurent22/joplin-turndown-plugin-gfm.git"
},
"keywords": [
"turndown",
"turndown-plugin",
"html-to-markdown",
"html",
"markdown",
"github-flavored-markdown",
"gfm"
],
"nx": {
"sourceRoot": "packages/turndown-plugin-gfm/src",
"targets": {
@ -32,10 +49,17 @@
],
"declarationRootDir": "packages/turndown-plugin-gfm/src"
}
},
"test": {
"command": "node packages/turndown-plugin-gfm/test/turndown-plugin-gfm-test.js"
}
}
},
"dependencies": {
"@swc/helpers": "~0.5.11"
},
"devDependencies": {
"turndown": "7.2.0",
"turndown-attendant": "0.0.3"
}
}

View File

@ -0,0 +1,16 @@
import Attendant from 'turndown-attendant';
import TurndownService from 'turndown';
import { gfm } from '../src/lib/gfm.js';
import { fileURLToPath } from "url";
import { dirname } from "path";
const scriptDir = dirname(fileURLToPath(import.meta.url));
const attendant = new Attendant({
file: `${scriptDir}/index.html`,
TurndownService: TurndownService,
beforeEach: function(turndownService) {
turndownService.use(gfm);
},
});
attendant.run();

1992
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff