Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _add_icon(doc, icons, icon):
if "name" not in icon:
# Bad formed icon
debug("[WARNING] pandoc-latex-tip: Bad formed icon")
return
# Lower the color
lower_color = icon["color"].lower()
# Convert the color to black if unexisting
from PIL import ImageColor
if lower_color not in ImageColor.colormap:
debug(
"[WARNING] pandoc-latex-tip: "
+ lower_color
+ " is not a correct color name; using black"
)
lower_color = "black"
def get(key):
'''parsing alignment'''
key_lower = key.lower()
if key_lower not in align_dict:
panflute.debug(f"pantable: alignment: invalid character {key} found, replaced by the default 'd'.")
key_lower = 'd'
return align_dict[key_lower]
# alignment string can be None or empty; return None: set to default by
# panflute
if not alignment_string:
return
# test valid type
if not isinstance(alignment_string, str):
panflute.debug("pantable: alignment should be a string. Set to default instead.")
# return None: set to default by panflute
return
n = len(alignment_string)
if n > n_col:
alignment_string = alignment_string[:n_col]
panflute.debug("pantable: alignment string is too long, truncated.")
alignment = [get(key) for key in alignment_string]
# fill up with default if too short
if n < n_col:
alignment += ["AlignDefault"] * (n_col - n)
return alignment
# alignment string can be None or empty; return None: set to default by
# panflute
if not alignment_string:
return
# test valid type
if not isinstance(alignment_string, str):
panflute.debug("pantable: alignment should be a string. Set to default instead.")
# return None: set to default by panflute
return
n = len(alignment_string)
if n > n_col:
alignment_string = alignment_string[:n_col]
panflute.debug("pantable: alignment string is too long, truncated.")
alignment = [get(key) for key in alignment_string]
# fill up with default if too short
if n < n_col:
alignment += ["AlignDefault"] * (n_col - n)
return alignment
"""parse `options['width']` if it is list of non-negative numbers
else return None.
"""
if 'width' not in options:
return
width = options['width']
if len(width) != n_col:
panflute.debug("pantable: given widths different from no. of columns in the table.")
return
try:
width = [float(fractions.Fraction(x)) for x in width]
except ValueError:
panflute.debug("pantable: specified width is not valid number or fraction and is ignored.")
return
for width_i in width:
if width_i < 0.:
panflute.debug("pantable: width cannot be negative.")
return
return width
Plain(elem), input_format="panflute", output_format="latex"
)
)
except TypeError:
debug(
"[WARNING] pandoc-latex-tip: icon name "
+ icon["name"]
+ " does not exist in variant "
+ icon["variant"]
+ " for collection "
+ icon["collection"]
+ "-"
+ icon["version"]
)
except FileNotFoundError:
debug("[WARNING] pandoc-latex-tip: error in generating image")
return images
use_grid_tables = options.get('grid_tables', False)
try:
if use_pipe_tables or use_grid_tables:
# if both are specified, use grid_tables
return csv2table_markdown(options, data, use_grid_tables)
else:
return csv2table_ast(options, data)
# delete element if table is empty (by returning [])
# element unchanged if include is invalid (by returning None)
except FileNotFoundError:
panflute.debug("pantable: include path not found. Codeblock shown as is.")
return
except EmptyTableError:
panflute.debug("pantable: table is empty. Deleted.")
# [] means delete the current element
return []
except ImportError:
return
"extended-name": extended_name,
"color": lower_color,
"collection": icon["collection"],
"version": icon["version"],
"variant": icon["variant"],
"link": icon["link"],
}
)
else:
debug(
"[WARNING] pandoc-latex-tip: "
+ icon["name"]
+ " is not a correct icon name"
)
else:
debug(
"[WARNING] pandoc-latex-tip: "
+ icon["variant"]
+ " does not exist in version "
+ icon["version"]
)
except FileNotFoundError:
debug("[WARNING] pandoc-latex-tip: error in accessing to icons definition")
def _icon_font(collection, version, css, ttf):
folder = appdirs.AppDirs(
"pandoc_latex_tip", version=get_distribution("pandoc_latex_tip").version
).user_data_dir
try:
return icon_font_to_png.IconFont(
os.path.join(folder, collection, version, css),
os.path.join(folder, collection, version, ttf),
True,
)
except FileNotFoundError as exception:
debug("[ERROR] pandoc-latex-tip: " + str(exception))
def get_table_width(options):
"""parse `options['table-width']` if it is positive number
else return 1.
"""
if 'table-width' not in options:
return 1.
table_width = options['table-width']
try:
table_width = float(fractions.Fraction(table_width))
except ValueError:
panflute.debug("pantable: table width should be a number or fraction. Set to 1 instead.")
return 1.
if table_width <= 0.:
panflute.debug("pantable: table width must be positive. Set to 1 instead.")
return 1.
return table_width