-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the source code of my 'md-table-tools' project directly
- Loading branch information
1 parent
02a7210
commit 84fce30
Showing
15 changed files
with
1,879 additions
and
36 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
} | ||
); | ||
}*/ |
Oops, something went wrong.