-
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.
Добавлено извлечение текста из markdown в Discord
- Loading branch information
1 parent
40092f5
commit 4a03550
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
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,13 @@ | ||
import { markdownToTxt } from './markdown'; | ||
|
||
describe('markdownToTxt', () => { | ||
describe('underline', () => { | ||
it('inline with space', () => expect(markdownToTxt('д __а__')).toBe('д а')); | ||
it('inline no space', () => expect(markdownToTxt('д__а__')).toBe('да')); | ||
it('underline space', () => expect(markdownToTxt('д __ __ а')).toBe('д а')); | ||
}); | ||
|
||
describe('quote', () => { | ||
it('simple quote', () => expect(markdownToTxt('> да')).toBe('да')); | ||
}); | ||
}); |
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,19 @@ | ||
import { parse as parseMarkdown } from 'discord-markdown-parser'; | ||
|
||
export function markdownToTxt(str: string): string { | ||
return parseMarkdown(str).map(recursiveFindText).join(''); | ||
} | ||
|
||
// I can't introduce valid typings since they're seems to be invalid in first place. | ||
// Use tests to know the possible node types | ||
function recursiveFindText(node: any): string { | ||
if (typeof node.content === 'string') { | ||
return node.content; | ||
} | ||
|
||
if (node.content !== undefined) { | ||
return recursiveFindText(node.content); | ||
} | ||
|
||
return node.map(recursiveFindText).join(''); | ||
} |
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 |
---|---|---|
|
@@ -1027,6 +1027,19 @@ | |
dependencies: | ||
undici-types "~5.26.4" | ||
|
||
"@types/prop-types@*": | ||
version "15.7.12" | ||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.12.tgz#12bb1e2be27293c1406acb6af1c3f3a1481d98c6" | ||
integrity sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q== | ||
|
||
"@types/react@>=16.0.0": | ||
version "18.2.78" | ||
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.78.tgz#94aec453d0ccca909998a2b4b2fd78af15a7d2fe" | ||
integrity sha512-qOwdPnnitQY4xKlKayt42q5W5UQrSHjgoXNVEtxeqdITJ99k4VXJOP3vt8Rkm9HmgJpH50UNU+rlqfkfWOqp0A== | ||
dependencies: | ||
"@types/prop-types" "*" | ||
csstype "^3.0.2" | ||
|
||
"@types/request@*": | ||
version "2.48.12" | ||
resolved "https://registry.yarnpkg.com/@types/request/-/request-2.48.12.tgz#0f590f615a10f87da18e9790ac94c29ec4c5ef30" | ||
|
@@ -1540,6 +1553,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.3: | |
shebang-command "^2.0.0" | ||
which "^2.0.1" | ||
|
||
csstype@^3.0.2: | ||
version "3.1.3" | ||
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.3.tgz#d80ff294d114fb0e6ac500fbf85b60137d7eff81" | ||
integrity sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw== | ||
|
||
dashdash@^1.12.0: | ||
version "1.14.1" | ||
resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" | ||
|
@@ -1648,6 +1666,13 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.37.61.tgz#9dd8e58c624237e6f1b23be2d29579af268b8c5b" | ||
integrity sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw== | ||
|
||
discord-markdown-parser@^1: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/discord-markdown-parser/-/discord-markdown-parser-1.1.0.tgz#bfc5c3c2963690a6b21fdedb49039e96b0ca91cd" | ||
integrity sha512-o2+iFgt5qer6UYY5hVTPGq2mGzleKRGYKcvymg67FdKg4AMJ061KbebKunCERWKjx79dmNHMDnGV2F0DRGCNkw== | ||
dependencies: | ||
simple-markdown "^0.7.3" | ||
|
||
discord.js@^14: | ||
version "14.14.1" | ||
resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-14.14.1.tgz#9a2bea23bba13819705ab87612837610abce9ee3" | ||
|
@@ -3405,6 +3430,13 @@ signal-exit@^4.0.1: | |
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.1.0.tgz#952188c1cbd546070e2dd20d0f41c0ae0530cb04" | ||
integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw== | ||
|
||
simple-markdown@^0.7.3: | ||
version "0.7.3" | ||
resolved "https://registry.yarnpkg.com/simple-markdown/-/simple-markdown-0.7.3.tgz#e32150b2ec6f8287197d09869fd928747a9c5640" | ||
integrity sha512-uGXIc13NGpqfPeFJIt/7SHHxd6HekEJYtsdoCM06mEBPL9fQH/pSD7LRM6PZ7CKchpSvxKL4tvwMamqAaNDAyg== | ||
dependencies: | ||
"@types/react" ">=16.0.0" | ||
|
||
sisteransi@^1.0.5: | ||
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" | ||
|