|
48 | 48 | * break-on-newline: Alias for the on_newline option in the breaks extra. |
49 | 49 | * code-friendly: Disable _ and __ for em and strong. |
50 | 50 | * cuddled-lists: Allow lists to be cuddled to the preceding paragraph. |
| 51 | +* emojis: add emoji support using emoji codes |
51 | 52 | * fenced-code-blocks: Allows a code block to not have to be indented |
52 | 53 | by fencing it with '```' on a line before and after. Based on |
53 | 54 | <http://github.github.com/github-flavored-markdown/> with support for |
@@ -3503,6 +3504,33 @@ def test(self, text: str): |
3503 | 3504 | ) |
3504 | 3505 |
|
3505 | 3506 |
|
| 3507 | +class Emojis(Extra): |
| 3508 | + ''' |
| 3509 | + Enable emoji support in markdown text using the [emoji library](https://github.com/carpedm20/emoji) |
| 3510 | + ''' |
| 3511 | + name = 'emojis' |
| 3512 | + order = (), (Stage.PARAGRAPHS,) |
| 3513 | + |
| 3514 | + def __init__(self, md: Markdown, options: Optional[dict]): |
| 3515 | + super().__init__(md, options) |
| 3516 | + self.options.setdefault('language', 'alias') |
| 3517 | + |
| 3518 | + def run(self, text): |
| 3519 | + try: |
| 3520 | + import emoji |
| 3521 | + except ImportError: |
| 3522 | + raise ImportError('the "emoji" extra requires the "emoji" package to be installed') |
| 3523 | + |
| 3524 | + if self.options: |
| 3525 | + return emoji.emojize(text, **self.options) |
| 3526 | + return emoji.emojize(text) |
| 3527 | + |
| 3528 | + def test(self, text): |
| 3529 | + # emoji identifiers can have all sorts of chars (eg: `:A_button_(blood_type):`) |
| 3530 | + # but they all start and end with a colon and don't have spaces in as far as I can see |
| 3531 | + return re.search(r':[\S]+:', text) |
| 3532 | + |
| 3533 | + |
3506 | 3534 | class FencedCodeBlocks(Extra): |
3507 | 3535 | ''' |
3508 | 3536 | Allows a code block to not have to be indented |
@@ -4324,6 +4352,7 @@ def test(self, text): |
4324 | 4352 | Alerts.register() |
4325 | 4353 | Breaks.register() |
4326 | 4354 | CodeFriendly.register() |
| 4355 | +Emojis.register() |
4327 | 4356 | FencedCodeBlocks.register() |
4328 | 4357 | Latex.register() |
4329 | 4358 | LinkPatterns.register() |
|
0 commit comments