From cb99a22fdfd26715d6d705d2c7b5cd6002b93587 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Wed, 8 Apr 2020 17:40:36 +0200 Subject: [PATCH] Reverted emoji.py integration to be moved out to separate package --- docs/extensions/pymdown.md | 29 ----------------- material/emoji.py | 67 -------------------------------------- mkdocs.yml | 4 +-- src/emoji.py | 67 -------------------------------------- 4 files changed, 2 insertions(+), 165 deletions(-) delete mode 100644 material/emoji.py delete mode 100644 src/emoji.py diff --git a/docs/extensions/pymdown.md b/docs/extensions/pymdown.md index d2bbaba19..e6e24d744 100644 --- a/docs/extensions/pymdown.md +++ b/docs/extensions/pymdown.md @@ -201,35 +201,6 @@ To view all the available short names and emoji available, see files containing the short names and emoji associated with each supported index. -In addition, you can access all the Material icons and Fontawesome icons by using -Material for MkDocs's custom emoji index. It extends the Twemoji index with new -short names that access any of the included icons. To use the custom index, you -need to use the following options when including the Emoji extension: - -``` - - pymdownx.emoji: - emoji_index: !!python/name:material.emoji.material - emoji_generator: !!python/name:material.emoji.to_svg -``` - -Then we can access any of the icons: - -=== "Markdown" - ``` - We can use Material Icons :material-airplane:. - - We can also use Fontawesome Icons :fontawesome-solid-ambulance:. - - That's not all, we can also use Octicons :octicons-octoface:. - ``` - -=== "Results" - We can use Material Icons :material-airplane:. - - We can also use Fontawesome Icons :fontawesome-solid-ambulance:. - - That's not all, we can also use Octicons :octicons-octoface:. - !!! warning "Legal disclaimer" Material has no affiliation with [JoyPixles][15] or [Twemoji][14], both diff --git a/material/emoji.py b/material/emoji.py deleted file mode 100644 index bbe8bcb02..000000000 --- a/material/emoji.py +++ /dev/null @@ -1,67 +0,0 @@ -""" -Emoji extras for Material. - -Override the Twemoji Index with an extended version that includes short names for Material icons, Fontawesome, etc. -""" -import os -import glob -import copy -from pymdownx import twemoji_db -from pymdownx.emoji import TWEMOJI_SVG_CDN, add_attriubtes -import codecs -import xml.etree.ElementTree as etree - -RESOURCES = os.path.dirname(os.path.abspath(__file__)) - - -def material(): - """Provide a copied Twemoji index with additional codes for Material included icons.""" - - # Copy the Twemoji index - index = { - "name": 'twemoji', - "emoji": copy.deepcopy(twemoji_db.emoji), - "aliases": copy.deepcopy(twemoji_db.aliases) - } - - # Find our icons - icon_path = os.path.join(RESOURCES, '.icons') - norm_base = icon_path.replace('\\', '/') + '/' - for result in glob.glob(icon_path.replace('\\', '/') + '/**/*.svg', recursive=True): - name = ':{}:'.format(result.replace('\\', '/').replace(norm_base, '', 1).replace('/', '-').lstrip('.')[:-4]) - if name not in index['emoji'] and name not in index['aliases']: - # Easiest to just store the path and pull it out from the index - index["emoji"][name] = {'name': name, 'path': result} - - return index - - -def to_svg(index, shortname, alias, uc, alt, title, category, options, md): - """Return SVG element.""" - - is_unicode = uc is not None - - if is_unicode: - svg_path = TWEMOJI_SVG_CDN - - attributes = { - "class": options.get('classes', index), - "alt": alt, - "src": "%s%s.svg" % ( - options.get('image_path', svg_path), - uc - ) - } - - if title: - attributes['title'] = title - - add_attriubtes(options, attributes) - - return etree.Element("img", attributes) - else: - el = etree.Element('span', {"class": options.get('classes', index)}) - svg_path = md.inlinePatterns['emoji'].emoji_index['emoji'][shortname]['path'] - with codecs.open(svg_path, 'r', encoding='utf-8') as f: - el.text = md.htmlStash.store(f.read()) - return el \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 56ea5cf32..182cbcb92 100755 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -103,8 +103,8 @@ markdown_extensions: - pymdownx.critic - pymdownx.details - pymdownx.emoji: - emoji_index: !!python/name:material.emoji.material - emoji_generator: !!python/name:material.emoji.to_svg + emoji_index: !!python/name:pymdownx.emoji.twemoji + emoji_generator: !!python/name:pymdownx.emoji.to_svg # - pymdownx.highlight: # linenums_style: pymdownx-inline - pymdownx.inlinehilite diff --git a/src/emoji.py b/src/emoji.py deleted file mode 100644 index bbe8bcb02..000000000 --- a/src/emoji.py +++ /dev/null @@ -1,67 +0,0 @@ -""" -Emoji extras for Material. - -Override the Twemoji Index with an extended version that includes short names for Material icons, Fontawesome, etc. -""" -import os -import glob -import copy -from pymdownx import twemoji_db -from pymdownx.emoji import TWEMOJI_SVG_CDN, add_attriubtes -import codecs -import xml.etree.ElementTree as etree - -RESOURCES = os.path.dirname(os.path.abspath(__file__)) - - -def material(): - """Provide a copied Twemoji index with additional codes for Material included icons.""" - - # Copy the Twemoji index - index = { - "name": 'twemoji', - "emoji": copy.deepcopy(twemoji_db.emoji), - "aliases": copy.deepcopy(twemoji_db.aliases) - } - - # Find our icons - icon_path = os.path.join(RESOURCES, '.icons') - norm_base = icon_path.replace('\\', '/') + '/' - for result in glob.glob(icon_path.replace('\\', '/') + '/**/*.svg', recursive=True): - name = ':{}:'.format(result.replace('\\', '/').replace(norm_base, '', 1).replace('/', '-').lstrip('.')[:-4]) - if name not in index['emoji'] and name not in index['aliases']: - # Easiest to just store the path and pull it out from the index - index["emoji"][name] = {'name': name, 'path': result} - - return index - - -def to_svg(index, shortname, alias, uc, alt, title, category, options, md): - """Return SVG element.""" - - is_unicode = uc is not None - - if is_unicode: - svg_path = TWEMOJI_SVG_CDN - - attributes = { - "class": options.get('classes', index), - "alt": alt, - "src": "%s%s.svg" % ( - options.get('image_path', svg_path), - uc - ) - } - - if title: - attributes['title'] = title - - add_attriubtes(options, attributes) - - return etree.Element("img", attributes) - else: - el = etree.Element('span', {"class": options.get('classes', index)}) - svg_path = md.inlinePatterns['emoji'].emoji_index['emoji'][shortname]['path'] - with codecs.open(svg_path, 'r', encoding='utf-8') as f: - el.text = md.htmlStash.store(f.read()) - return el \ No newline at end of file