Skip to content

Commit

Permalink
Added the source code of my 'md-table-tools' project directly
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisDiligens committed Jan 8, 2023
1 parent 02a7210 commit 84fce30
Show file tree
Hide file tree
Showing 15 changed files with 1,879 additions and 36 deletions.
Binary file removed lib/md-table-tools-1.0.0.tgz
Binary file not shown.
55 changes: 26 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
"license": "MIT",
"keywords": [
"joplin-plugin",
"multimarkdown", "multimd", "markdown", "md"
"multimarkdown",
"multimd",
"markdown",
"md"
],
"files": [
"publish"
],
"devDependencies": {
"@types/codemirror": "^5.60.5",
"@types/turndown": "^5.0.1",
"@types/node": "^14.0.14",
"chalk": "^4.1.0",
"copy-webpack-plugin": "^6.1.0",
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
"md-table-tools": "file:./lib/md-table-tools-1.0.0.tgz",
"markdown-it-multimd-table": "file:./lib/markdown-it-multimd-table-4.2.0.tgz",
"on-build-webpack": "^0.1.0",
"tar": "^6.0.5",
Expand All @@ -31,6 +35,6 @@
"yargs": "^16.2.0"
},
"dependencies": {
"@types/codemirror": "^5.60.5"
"turndown": "^7.1.1"
}
}
10 changes: 9 additions & 1 deletion plugin.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
"dialogs.ts",
"markdownItExtension.ts",
"settings.ts",
"tableUtils.ts"
"tableUtils.ts",
"tables/common.ts",
"tables/csvTable.ts",
"tables/gfmTable.ts",
"tables/htmlTable.ts",
"tables/multiMarkdownTable.ts",
"tables/table.ts",
"tables/tableParser.ts",
"tables/tableRenderer.ts"
]
}
2 changes: 1 addition & 1 deletion src/cmPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor } from "codemirror";
import { Table, TextAlignment } from "md-table-tools";
import { Table, TextAlignment } from "./tables/table";
import { createPosition, getColumnRanges, getRangeOfTable, isCursorInTable, replaceAllTablesFunc, replaceRange, replaceRangeFunc, replaceSelectionFunc } from "./cmUtils";
import { getCSVRenderer, getHTMLRenderer, getMarkdownParser, getMarkdownRenderer, parseTable } from "./tableUtils";

Expand Down
9 changes: 8 additions & 1 deletion src/tableUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { MultiMarkdownTableParser, MinifiedMultiMarkdownTableRenderer, PrettyMultiMarkdownTableRenderer, TableParser, TableRenderer, GitHubFlavoredMarkdownTableParser, GitHubFlavoredMarkdownTableRenderer, HTMLTableParser, HTMLTableRenderer, CSVTableParser, CSVTableRenderer, Table } from 'md-table-tools';
// import { MultiMarkdownTableParser, MinifiedMultiMarkdownTableRenderer, PrettyMultiMarkdownTableRenderer, TableParser, TableRenderer, GitHubFlavoredMarkdownTableParser, GitHubFlavoredMarkdownTableRenderer, HTMLTableParser, HTMLTableRenderer, CSVTableParser, CSVTableRenderer, Table } from 'md-table-tools';
import { Table } from "./tables/table";
import { TableParser } from "./tables/tableParser";
import { TableRenderer } from "./tables/tableRenderer";
import { MultiMarkdownTableParser, MinifiedMultiMarkdownTableRenderer, PrettyMultiMarkdownTableRenderer } from "./tables/multiMarkdownTable";
import { HTMLTableParser, HTMLTableRenderer } from "./tables/htmlTable";
import { GitHubFlavoredMarkdownTableParser, GitHubFlavoredMarkdownTableRenderer } from "./tables/gfmTable";
import { CSVTableParser, CSVTableRenderer } from "./tables/csvTable";

const multimdParser = new MultiMarkdownTableParser();
const multimdMinifiedRenderer = new MinifiedMultiMarkdownTableRenderer();
Expand Down
72 changes: 72 additions & 0 deletions src/tables/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import TurndownService from "turndown";
//import { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } from 'node-html-markdown';

export function removeInvisibleCharacters(str: string): string {
// See: https://www.utf8-chartable.de/unicode-utf8-table.pl
// https://stackoverflow.com/a/13836410
// /[^\u0000-\u007E]/g
// /\u00AD/g - soft hyphen
// /[^\u0020-\u007E\u00A1-\u00AC\u00AE-\u00FF]/g
return str
.replace(/[\u0000-\u0009\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, "") // Control characters
.replace(/[\u00AD\u2007\u200C\u2028-\u202F\u2060-\u206F\uFEFF]/g, "") // Invisible characters, such as ­ or "Zero Width Non-Joiner"
.replace(/\u00A0/g, " ")
.replace(/\u2002/g, " ")
.replace(/\u2003/g, " ")
.replace(/\u2009/g, " ")
//.replace(/[\u0378\u0379\u0380-\u0383\u038B\u038D\u03A2\u0530\u0557\u0558\u058B\u058C\u0590\u05C8-\u05CF\u05EB-\u05EE\u05F5-\u05FF\u070E\u074B\u074C\u07B2-\u07BF\u07FB\u07FC\u082E\u082F\u083F]/g, ""); // Weird characters
}

/** Returns a TurndownService object configured for my own taste... deal with it 😎
* (nah, jk, if you don't like it, you can configure it to fit your needs) */
export function getTurndownService(): TurndownService {
const turndownService = new TurndownService({
headingStyle: 'atx',
hr: '---',
bulletListMarker: '-',
codeBlockStyle: 'fenced',
fence: '```',
emDelimiter: '*',
strongDelimiter: '**',
linkStyle: 'inlined',
linkReferenceStyle: 'full'
});

// Add strikethrough:
turndownService.addRule('strikethrough', {
filter: ['del', 's'], // , 'strike'
replacement: function (content) {
return '~~' + content + '~~';
}
});

// Add blockquote:
/*turndownService.addRule('blockquote', {
filter: ['blockquote'],
replacement: function (content) {
return '> ' + content;
}
});*/

// Filter table tags:
turndownService
.remove('table')
.remove('tbody')
.remove('thead')
.remove('tr')
.remove('td')
.remove('th');

return turndownService;
}

/*export function getNodeHtmlMarkdown(): NodeHtmlMarkdown {
return new NodeHtmlMarkdown(
{
bulletMarker: '-',
emDelimiter: '*',
strongDelimiter: '**',
ignore: ['table', 'tbody', 'thead', 'tr', 'td', 'th']
}
);
}*/
Loading

0 comments on commit 84fce30

Please sign in to comment.