sphinx-contrib / emojicodes

An extension to use emoji codes in your Sphinx documentation! 😍
https://sphinxemojicodes.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
48 stars 15 forks source link

Support md files #40

Open meri-burgess opened 1 year ago

meri-burgess commented 1 year ago

Currently, emojis are only supported in .rst. It would be great to be able to use the tool for .md files as well

Peque commented 1 year ago

Thanks for your suggestion @meri-burgess! :blush:

Could you elaborate a bit more on your use case? I'm guessing you use an extension in Sphinx to support Markdown. If so, which one? Does it support variable substitutions like |release|, |version|?

casperdcl commented 10 months ago

In markdown, you can use eval-rst:

```{eval-rst}
|:white_check_mark:| hacky


to get:

✅ hacky
jdillard commented 9 months ago

I'm not positive, but it seems the extension only parses .rst: https://github.com/sphinx-contrib/emojicodes/blob/ec8f49dcefae36ac36ba7100f8c6211b1c39819d/sphinxemoji/sphinxemoji.py#L55

where as it should support everything in source_suffix?

casperdcl commented 9 months ago

Yes and I suppose the .md syntax would be [:smile:] or [](:smile:)

jdillard commented 9 months ago

myst-parser automatically adds .md to source_suffx: https://github.com/executablebooks/MyST-Parser/blob/ebf989fdae10c68dfbd3dcdfec4b86259b810cd9/myst_parser/sphinx_ext/main.py#L34

The problem isn't the syntax to be parsed, its the suffix (extension) of the files to be parsed.

casperdcl commented 9 months ago

yes I know, I was just commenting on what the future PR should probably support in terms of UX (in response to this) :)

dannybeckett commented 4 months ago

@Peque @casperdcl @jdillard

I am interested in trying to completely swap rst for md (I have no .rst files, only .md files).

I tried this:

apt-get update && apt-get install git -y
git clone https://github.com/sphinx-contrib/emojicodes.git ../emojicodes
sed -i "s/rst/md/" ../emojicodes/sphinxemoji/sphinxemoji.py
cat ../emojicodes/sphinxemoji/sphinxemoji.py
pip install build
python -m build ../emojicodes
pip install ../emojicodes/dist/*.whl

It successfully replaces rst with md + loads the extension in to Sphinx, but unfortunately still doesn't want to display emojis.

I am using the myst_parser extension to parse Markdown, which supports substitution.

In conf.py I have myst_enable_extensions = ['substitution']

In the .md file I have tried:

:white_check_mark:
[:white_check_mark:]
|:white_check_mark:|
{{:white_check_mark:}}
{{white_check_mark}}
{{"a" + "b"}}
```{eval-rst}
|:white_check_mark:|


Myst uses `{{ .. }}` as delimiters, but the [delimiter is configurable](https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#substitutions-with-jinja2).

The ones inside `{{ .. }}` in my list/code block above are replaced with blank strings, except `"a" + "b"` which successfully replaces to `ab`. The `{eval-rst}` still continues to show the emoji unexpectedly though.

Usually Myst expects you to feed it a list of substitutions in the `conf.py` or in the `.md` file.

Any help is much appreciated please!

See also: [Stack Overflow question](https://stackoverflow.com/questions/42087466/sphinx-extension-to-use-github-markdown-emoji-in-sphinx)

Many thanks
Peque commented 4 months ago

@dannybeckett I haven't had the time to look at this, but I'd be happy to review and integrate a PR if someone is able to implement it. :blush: