brussell98 / discord-markdown Goto Github PK
View Code? Open in Web Editor NEWA markdown parser with the same rules as Discord
License: MIT License
A markdown parser with the same rules as Discord
License: MIT License
It seems that the package contains an error in the transcription to TypeScript, I have been investigating and the problem seems to be another package installed in the same simple-markdown@latestversion
Generic type 'Output' requires 1 type argument (s)
document: node_modules/simple-markdown/simple-markdown.d.ts
line: 64
node: ASTNode,
state?: OptionalState
) => Result;
HTML in multi-line code blocks is not escaped, even with the escapeHTML option set.
Ex:
```
<div style="background: blue">Hello World</div>
```
Will not have the </> signs HTML escaped within the code block.
Both inline code and code block are handled as code blocks.
https://gyazo.com/579c6729504fb4e7d1da5ca78f101a65
Spoilers are wrapped with {{
and }}
. More details on how this works will follow as it releases.
i just noticed how all the discord-specific mentions are always wrapped in <span>
now, which might be unwanted behaviour for the user. Maybe they just want e.g. the plaintext name, not wrapped into a span.
This is conflicting at least with where we use this package, as we are only working with a limited subset of HTML and try to keep things as minimal as possible
This could be e.g. toggle-able behaviour with the default being on
EDIT: or maybe if all things mapped in cssModuleNames are empty strings it doesn't wrap it in a <span>
? just tossing around ideas
Discord quotes use a single >
to create a blockquote for the current line. >>>
creates a blockquote which contains all text after it.
Discord-Markdown: 2.5.0
[TEXT](URL) ---> [TEXT](<a href="URL">URL</a>)
It's not parsing hyperlinks, it should be added. It's a basic Markdown feature
Discord has updated their Markdown spec to include headings and (un)ordered + nested lists -- would love to see this get support for the new stuff.
Hello, I have created a demo where people can see the formatted text as well as the generated HTML.
The demo can be accessed here: https://dcmarkdown.vott.us/
Sincerely,
Vottus
I cannot find a possibility to add specific or completely external custom parser for elements(Like regex-defined) such as time like <t:1666821660:F>.
Did I oversee it or any idea how to bring this functionality to live?
The title is self explanatory, it would be great if the package could parse markdown directly into JSX
Input:
_this *is* a test_
Discord:
<em>this is a test</em>
discord-markdown:
<em>this <em>is</em> a test</em>
Italics *italics* or _italics_Underline italics __*underline italics*__
Bold **bold**Underline bold __**underline bold**__
Bold Italics ***bold italics***underline bold italics
__***underline bold italics***__
Underline __underline__
Strikethrough ~~Strikethrough~~
```py
if print("hello",5)
```
> hello
> hi
Goes to:
<br>Italics <em>italics</em> or _italics_Underline italics <u><em>underline italics</em></u><br>Bold <strong>bold</strong>Underline bold <u><strong>underline bold</strong></u><br>Bold Italics <em><strong>bold italics</strong></em>underline bold italics<br> <u><em><strong>underline bold italics</strong></em></u><br>Underline <u>underline</u><br>Strikethrough <del>Strikethrough</del><br><pre><code class="hljs py"><span class="hljs-keyword">if</span> <span class="hljs-built_in">print</span>(<span class="hljs-string">"hello"</span>,<span class="hljs-number">5</span>)</code></pre><br><blockquote>hello<br>hi<br></blockquote>
Why is there all these Unicode Â's?
I've tried adding:
paragraph: markdown.defaultRules.paragraph,
to the list of rules, but it doesn't seem to be doing anything, despite a lot of tinkering. I've been able to add other rules in from markdown.defaultRules
, but not this one. Any idea how to get it working?
In discord, you can format your text in italics like so, *hello*
, but this does not get parsed properly in discord-markdown - it comes out just as it went in.
Here is the interface for DiscordCallback
interface DiscordCallback {
user?: (id: number) => string;
channel?: (id: number) => string;
role?: (id: number) => string;
everyone?: () => string;
here?: () => string;
}
However, this is incorrect. None of the first three actually take an id as a parameter. user
takes a user object, channel
takes a channel object, and role
takes a role object. See:
const discordCallbackDefaults = {
user: node => '@' + markdown.sanitizeText(node.id),
channel: node => '#' + markdown.sanitizeText(node.id),
role: node => '&' + markdown.sanitizeText(node.id),
everyone: () => '@everyone',
here: () => '@here'
};
Could these typings be fixed to reflect the actual usage for the callback?
As this lib does not provide any .d.ts file or @types/discord-markdown package, it is unusable with typescript.
The call to discordCallback.emoji was completely removed in favor of custom emoji image generation (I assume).
Can the call be restored in the event it is provided, please?
The current implementation is significantly less flexible, and also seems to be generating stray img end tag errors in HTML validators.
Normally markdown processors have the functionality to transform MD to HTML and vice versa. I think that it would be great if that were to be implemented here and that is the reason behind this feature request.
Such functionality, in particular, would help me a great deal in an extensive array of projects and I'm sure many others would feel the same. Some of the probable use-case scenarios:
Having done something similar to this myself using basic regular expressions and JavaScript, I have stumbled upon the following issues, so I'm gonna share them here for you to consider:
<code><strong>
which would not work on Discord. This would have to be converted to <strong><code>
to avoiding showing **
in the monospaced block,<pre><code>
is simply ```. For this in particular, it would be great if the library can detect highlight.js (hljs) code blocks and use the language defined therewithin.<div>
, <span>
etc. would have to be removed altogetherAll of this is probably already possible with existing libraries by tweaking them, but I thought this would be very appropriate for this repository.
Many thanks.
I don't really understand what the "embed" option does. Could you explain that one?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.