Add alt text on roles
This commit is contained in:
parent
1ff5dbc445
commit
4236146717
4 changed files with 51 additions and 35 deletions
5
CHANGES
5
CHANGES
|
@ -2,6 +2,11 @@
|
|||
Changes
|
||||
=======
|
||||
|
||||
1.0.0 (*2021-06-06*)
|
||||
====================
|
||||
|
||||
- Add alt on roles
|
||||
|
||||
0.1.4 (*2020-01-31*)
|
||||
====================
|
||||
|
||||
|
|
12
README.rst
12
README.rst
|
@ -13,8 +13,8 @@ in your `conf.py`:
|
|||
.. code:: python
|
||||
|
||||
fa_brands_path = '_static/fa/brands.svg'
|
||||
fa_regular_path = '_static/fa/brands.svg'
|
||||
fa_solid_path = '_static/fa/brands.svg'
|
||||
fa_regular_path = '_static/fa/regular.svg'
|
||||
fa_solid_path = '_static/fa/solid.svg'
|
||||
|
||||
Use inline references for brands, regular or solid:
|
||||
|
||||
|
@ -26,6 +26,10 @@ Use inline references for brands, regular or solid:
|
|||
:far:`icon`
|
||||
:fas:`icon`
|
||||
|
||||
:fab:`icon[alt text]`
|
||||
:far:`icon[alt text]`
|
||||
:fas:`icon[alt text]`
|
||||
|
||||
An icon with some attributes:
|
||||
|
||||
.. far:: icon
|
||||
|
@ -40,6 +44,10 @@ Use inline references for brands, regular or solid:
|
|||
:farlink:`icon: Text <url>`
|
||||
:faslink:`icon: Text <url>`
|
||||
|
||||
:fablink:`icon: Text[alt text] <url>`
|
||||
:farlink:`icon: Text[alt text] <url>`
|
||||
:faslink:`icon: Text[alt text] <url>`
|
||||
|
||||
.. warning::
|
||||
|
||||
Icon is not inserted in LaTeX document for now.
|
||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ with open("README.rst", "r") as fh:
|
|||
|
||||
setup(
|
||||
name="sphinx_fasvg",
|
||||
version="0.1.4",
|
||||
version="1.0.0",
|
||||
url="https://procrastinator.nerv-project.eu/nerv-project/sphinx_fasvg",
|
||||
license="EUPL 1.2",
|
||||
author="Kujiu",
|
||||
|
|
|
@ -19,7 +19,7 @@ from sphinx.writers.text import TextTranslator
|
|||
from sphinx.writers.manpage import ManualPageTranslator
|
||||
from sphinx.util.osutil import relative_uri
|
||||
|
||||
__version_info__ = (0, 1, 4)
|
||||
__version_info__ = (1, 0, 0)
|
||||
__version__ = '.'.join([str(val) for val in __version_info__])
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ class falink(nodes.General, nodes.Inline, nodes.Element):
|
|||
pass
|
||||
|
||||
|
||||
def html_visit_fa(self: HTMLTranslator, node: fa) -> None:
|
||||
def append_fa_image(self: HTMLTranslator, node: fa or falink) -> None:
|
||||
path = {
|
||||
'brands': self.builder.config.fa_brands_path,
|
||||
'regular': self.builder.config.fa_regular_path,
|
||||
|
@ -69,6 +69,10 @@ def html_visit_fa(self: HTMLTranslator, node: fa) -> None:
|
|||
self.body.append(
|
||||
'<use xlink:href="%s#%s"></use></svg>' % (path, node['icon'])
|
||||
)
|
||||
|
||||
|
||||
def html_visit_fa(self: HTMLTranslator, node: fa) -> None:
|
||||
append_fa_image(self, node)
|
||||
raise nodes.SkipNode
|
||||
|
||||
|
||||
|
@ -108,86 +112,85 @@ def create_fa_node(iconset, icon, html_id=None, html_class=None, alt=None):
|
|||
node['icon'] = icon
|
||||
node['html_id'] = html_id
|
||||
node['html_class'] = html_class
|
||||
node['alt'] = alt
|
||||
node['alt'] = alt or ''
|
||||
return node
|
||||
|
||||
|
||||
def html_visit_falink(self: HTMLTranslator, node: fa) -> None:
|
||||
path = {
|
||||
'brands': self.builder.config.fa_brands_path,
|
||||
'regular': self.builder.config.fa_regular_path,
|
||||
'solid': self.builder.config.fa_solid_path,
|
||||
}[node['iconset']]
|
||||
|
||||
path = relative_uri(
|
||||
self.builder.current_docname,
|
||||
self.builder.get_asset_paths()[0] + '/' + path
|
||||
)
|
||||
self.body.append(
|
||||
'<a class="fasvglink %s" href="%s">' %
|
||||
(node['icon'], node['url']))
|
||||
self.body.append(
|
||||
'<svg aria-hidden="true" class="icon" role="img"'
|
||||
+ ' xlink:title=""'
|
||||
+ ' xmlns="http://www.w3.org/2000/svg"'
|
||||
+ ' xmlns:xlink="http://www.w3.org/1999/xlink">'
|
||||
)
|
||||
append_fa_image(self, node)
|
||||
|
||||
self.body.append(
|
||||
'<use xlink:href="%s#%s"></use>' % (path, node['icon'])
|
||||
)
|
||||
self.body.append('</svg> %s</a>' % node['text'])
|
||||
self.body.append(' %s</a>' % node['text'])
|
||||
raise nodes.SkipNode
|
||||
|
||||
|
||||
def latex_visit_falink(self: LaTeXTranslator, node: fa) -> None:
|
||||
self.body.append('\\href{%s}{%s}' % (node['url'], node['text']))
|
||||
self.body.append('\\href{%s}{%s %s}' % (
|
||||
node['url'], node['alt'], node['text']))
|
||||
raise nodes.SkipNode
|
||||
|
||||
|
||||
def texinfo_visit_falink(self: TexinfoTranslator, node: fa) -> None:
|
||||
self.body.append('\\href{%s}{%s}' % (node['url'], node['text']))
|
||||
self.body.append('\\href{%s}{%s %s}' % (
|
||||
node['url'], node['alt'], node['text']))
|
||||
raise nodes.SkipNode
|
||||
|
||||
|
||||
def text_visit_falink(self: TextTranslator, node: fa) -> None:
|
||||
self.add_text('%s <%s>' % (node['text'], node['url']))
|
||||
self.add_text('%s %s <%s>' % (node['alt'], node['text'], node['url']))
|
||||
raise nodes.SkipNode
|
||||
|
||||
|
||||
def gemini_visit_falink(self, node: fa) -> None:
|
||||
self.end_block()
|
||||
self.add_text('=> %s %s' % (node['url'], node['text']))
|
||||
self.add_text('=> %s %s %s' % (node['alt'], node['url'], node['text']))
|
||||
self.end_block()
|
||||
raise nodes.SkipNode
|
||||
|
||||
|
||||
def man_visit_falink(self: ManualPageTranslator, node: fa) -> None:
|
||||
self.body.append('%s <%s>' % (node['text'], node['url']))
|
||||
self.body.append('%s %s <%s>' % (node['text'], node['alt'], node['url']))
|
||||
raise nodes.SkipNode
|
||||
|
||||
|
||||
def create_falink_node(iconset, text):
|
||||
node = falink()
|
||||
regex = re.compile(r'(?P<icon>[a-zA-Z-_]*):(?P<text>.*)<(?P<url>.*)>')
|
||||
regex = re.compile(
|
||||
r'(?P<icon>[a-zA-Z-_]*):(?P<text>.*)'
|
||||
+ r'(?P<alt>\[.*\] *)<(?P<url>.*)>')
|
||||
parsed = regex.search(text)
|
||||
node['iconset'] = iconset
|
||||
node['icon'] = parsed.group('icon')
|
||||
node['url'] = parsed.group('url').strip()
|
||||
node['alt'] = (parsed.group('alt') or '').strip().strip('[]')
|
||||
node['text'] = parsed.group('text').strip()
|
||||
return node
|
||||
|
||||
|
||||
def fab(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||
return [create_fa_node('brands', text)], []
|
||||
regex = re.compile(r'(?P<icon>[a-zA-Z-_]*)(?P<alt>\[.*\] *)')
|
||||
parsed = regex.search(text)
|
||||
alt = (parsed.group('alt') or '').strip().strip('[]')
|
||||
icon = parsed.group('icon').strip()
|
||||
return [create_fa_node('brands', icon, alt=alt)], []
|
||||
|
||||
|
||||
def far(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||
return [create_fa_node('regular', text)], []
|
||||
regex = re.compile(r'(?P<icon>[a-zA-Z-_]*)(?P<alt>\[.*\] *)')
|
||||
parsed = regex.search(text)
|
||||
alt = (parsed.group('alt') or '').strip().strip('[]')
|
||||
icon = parsed.group('icon').strip()
|
||||
return [create_fa_node('regular', icon, alt=alt)], []
|
||||
|
||||
|
||||
def fas(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||
return [create_fa_node('solid', text)], []
|
||||
regex = re.compile(r'(?P<icon>[a-zA-Z-_]*)(?P<alt>\[.*\] *)')
|
||||
parsed = regex.search(text)
|
||||
alt = (parsed.group('alt') or '').strip().strip('[]')
|
||||
icon = parsed.group('icon').strip()
|
||||
return [create_fa_node('solid', icon, alt=alt)], []
|
||||
|
||||
|
||||
def fablink(role, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||
|
|
Loading…
Reference in a new issue