rhysd / remark-emoji

Remark markdown transformer to replace :emoji: in text
MIT License
124 stars 18 forks source link

it broke the remark containers when emoticon is enabled #23

Closed talatkuyuk closed 1 year ago

talatkuyuk commented 1 year ago

In the markdown, when I create a custom container: (with remark-custom-container)

::: danger Title

bla bla bla

:::

the regex RE_SHORT (for detecting emoticon) matches also container markup triple colon :::, and broke the container.

Is there any emoji or emoticon which contains triple colon :::?

Actually the triple colon ::: is well-known pattern to make containers in the remark ecosystem.

When I use the remark-emoji after the remark-custom-container, the custom containers are okey, but in that case it broke something else, which I don't prefer.

Is it necessary to match triple colon :::?. If not, I think the RE_SHORT needs to be refactored, but I don't know which regex pattern ignores the triple colon ::: and matches the actual emoticons.

rhysd commented 1 year ago

Is there any emoji or emoticon which contains triple colon :::?

I don't think so. RE_SHORT is simply not perfect to precisely match emoticons.

rhysd commented 1 year ago

https://github.com/rhysd/remark-emoji/blob/a5018376aa7bfea2c114a8667f8e9a8497775a68/index.js#L46

Though the regex matches to :::, it is not found in emoticons list. So the matcher just returns the original text without modification here.

rhysd commented 1 year ago

I tried the following and it worked fine.

import { remark } from 'remark';
import emoji from 'remark-emoji';

const emoticon = remark().use(emoji, { emoticon: true });
const input = '::: danger Title\n\nbla bla bla\n\n:::\n';
const file = await emoticon.process(input);
const output = String(file);
console.log(output);

It seems a problem of the remark-custom-container that it does not handle the nested text node correctly. Closing.

rhysd commented 1 year ago

This situation might be improved at v3.1.1 because remark-emoji no longer replace the matched text with a text node when no emoji corresponding to the text is found.

talatkuyuk commented 1 year ago

I will try, and let you know, thanks.

talatkuyuk commented 1 year ago

I tested and see that it is fixed, no more side-effects, thanks..

danielfabriq commented 5 months ago

Having similar issue with links

image
rhysd commented 5 months ago

@danielfabriq This issue is already closed hence it is not tracked. Can you make a new issue with an example input (the input string and the JavaScript code you tried) which can reproduce it? I guess this is a conflict with some other plugins (auto-linking?).