def link(self, link, title, text): link = mistune.escape_link(link) if not title: return '<a href="%s" target="_blank">%s</a>' % (link, text) title = escape(title, quote=True) return '<a href="%s" title="%s" target="_blank">%s</a>' % (link, title, text)
def link(self, link, title, text): link = mistune.escape_link(link) if not title: return '<a href="%s"%s>%s</a>' % (link, self._link_rel(link), text) title = mistune.escape(title, quote=True) return '<a href="%s" title="%s"%s>%s</a>' % ( link, title, self._link_rel(link), text)
def link(self, link, title, text): link = mistune.escape_link(link) if not title: return '<a href="%s" rel="nofollow">%s</a>' % (link, text) title = escape(title, quote=True) return '<a href="%s" title="%s" rel="nofollow">%s</a>' % (link, title, text)
def link(self, link, title, text): """Rendering a given link with content and title. :param link: href link for ``<a>`` tag. :param title: title content for `title` attribute. :param text: text content for description. """ link = escape_link(link) return [MdStyleInstructionLink(link)] + text
def autolink(self, link, is_email=False): """Rendering a given link or email address. :param link: link content or email address. :param is_email: whether this is an email or not. """ text = link = escape_link(link) if is_email: link = 'mailto:%s' % link return [MdStyleInstructionLink(link)] + text
def link(self, link, title, text): link = escape_link(link) site = Site.objects.get_current() nofollow = "" if link.find(site.domain) > 0 else "rel='nofollow'" if not link: link = "#" if not title: return '<a href="%s" %s>%s</a>' % (link, nofollow, text) title = escape(title, quote=True) return '<a href="%s" title="%s" %s>%s</a>' % (link, title, nofollow, text)
def link(self, link, title, text): link = escape_link(link) nofollow = "rel='nofollow'" if not link: link = "#" if not title: return '<a href="%s" %s>%s</a>' % (link, nofollow, text) title = escape(title, quote=True) return '<a href="%s" title="%s" %s>%s</a>' % (link, title, nofollow, text)
def link(self, link, title, text): link = escape_link(link, quote=True) site = Site.objects.get_current() nofollow = "" if link.find(site.domain) > 0 else "rel='nofollow'" if not link: link = "#" if not title: return '<a href="%s" %s>%s</a>' % (link, nofollow, text) title = escape(title, quote=True) return '<a href="%s" title="%s" %s>%s</a>' % (link, title, nofollow, text)
def image(self, src: str, title: str, text: str) -> str: src = escape_link(src) html = f'<img data-lazy-url="{src}"' if title: title = escape(title, quote=True) html = f'{html} title="{title}"' if text: text = escape(text, quote=True) html = f'{html} alt="{text}"' return f'{html}/>'
def link(self, Link, Title, Text): Link = mistune.escape_link(Link) if Link.startswith( "[0,") and not self.Notebook.StringIsValidIndexPath(Link): return Text + " (LINKED PAGE NOT FOUND)" if Link == "[deleted]": return Text + " (LINKED PAGE DELETED)" if not Title: return "<a href=\"" + Link + "\">" + Text + "</a>" Title = mistune.escape(Title, quote=True) return "<a href=\"" + Link + "\" title=\"" + Title + "\">" + Text + "</a>"
def image(self, src, title, text): src = mistune.escape_link(src) text = mistune.escape(text, quote=True) if title: title = mistune.escape(title, quote=True) html = f'<img class="pure-img" src="{src}" alt="{text}" title="{title}" ' else: html = f'<img class="pure-img" src="{src}" alt="{text}" ' if self.options.get("use_xhtml"): return f"{html} />" return f"{html} >"
def image(self, src, title, text, attribute=None): """Image rendering for assets""" asset_slug, args = self._asset_url_helper(src) if asset_slug is not None: asset = Asset.objects.filter(slug=asset_slug).first() if asset is not None: if asset.type == "video": return self.video(src, title, text) size = args.get('size', None) crop = args.get('crop', None) quality = args.get('quality', 99) asset = ImageAsset.objects.filter(slug=asset.slug).first() if asset is None: return super().image(src, title, text) if size is not None: image_asset = get_thumbnail(asset.asset, size, crop=crop, quality=quality) else: image_asset = asset.asset src = image_asset.url if not src: src = '' if title is None or len(title) == 0: title = asset.title if text is None or len(text) == 0: text = asset.description else: # - Check if Video asset if src.lower().split('.')[-1] in _VIDEO_EXTENSIONS: return self.video(src, title, text, attribute=attribute) if not attribute: attribute = "image-fluid" # - Render image HTML src = mistune.escape_link(src) text = mistune.escape(text, quote=True) if title: title = mistune.escape(title, quote=True) html = '<img src="%s" alt="%s" title="%s"' % (src, text, title) else: html = '<img src="%s" alt="%s"' % (src, text) if attribute: html = '%s class="%s"' % (html, attribute) if self.options.get('use_xhtml'): return '%s />' % html return '%s>' % html
def image(self, src, title, text): """Rendering a image with title and text. :param src: source link of the image. :param title: title text of the image. :param text: alt text of the image. """ src = escape_link(src) html = '[img]%s[/img]' % src if self.options.get('use_xhtml'): return '%s' % html return '%s' % html
def link(self, link, title, text): """Rendering a given link with content and title. :param link: href link for ``<a>`` tag. :param title: title content for `title` attribute. :param text: text content for description. """ link = escape_link(link) if not title: return '[url=%s]%s[/url]' % (link, text) title = escape(title, quote=True) return '[url=%s]%s[/url]' % (link, text)
def link(self, link, title, text): """Rendering a given link with content and title. :param link: href link for ``<a>`` tag. :param title: title content for `title` attribute. :param text: text content for description. """ link = mistune.escape_link(link) if not title: return '<a href="%s">%s</a>' % (link, text) title = mistune.escape(title, quote=True) return '<a href="%s" title="%s" class="%s">%s</a>' % ( link, title, self.cls['link'], text)
def link(self, link, title, text): """""" link = mistune.escape_link(link) site = get_current_site() nofollow = "" if link.find(site.domain) > 0 else 'rel = "nofollow"' if not link: link = "#" if not title: return "<a href='%s' %s>%s</a>" % (link, nofollow, text) title = mistune.escape(title, quote=True) return "<a href='%s' title='%s' %s>%s</a>" % (link, title, nofollow, text)
def image(self, src, title, text): """Rendering a image with title and text. :param src: source link of the image. :param title: title text of the image. :param text: alt text of the image. """ src = mistune.escape_link(src) text = mistune.escape(text, quote=True) if title: title = mistune.escape(title, quote=True) html = '<img src="%s" class="img-responsive" alt="%s" title="%s"' % (src, text, title) else: html = '<img src="%s" class="img-responsive" alt="%s"' % (src, text) return '%s />' % html
def image(self, src, title, text): # Derived from the mistune library source code src = mistune.escape_link(src) text = escape(text, quote=True) if title: title = escape(title, quote=True) output = ('<fig><title>{0}</title>\n' '<image href="{1}" alt="{2}"/></fig>'.format( title, src, text)) else: output = '<image href="{0}" alt="{1}"/>'.format(src, text) return output
def link(self, Link, Title, Text): Link = mistune.escape_link(Link) ValidIndexPath = self.Notebook.StringIsValidIndexPath(Link) if Link.startswith("[0,") and not ValidIndexPath: return Text + " (LINKED PAGE NOT FOUND)" if Title: Title = mistune.escape(Title, quote=True) if ValidIndexPath: if not Title: return "<a href=\"\" onclick=\"return SelectPage("" + Link + "");\">" + Text + "</a>" return "<a href=\"\" onclick=\"return SelectPage("" + Link + "");\" title=\"" + Title + "\">" + Text + "</a>" else: if not Title: return "<a href=\"" + Link + "\" target=\"_blank\">" + Text + "</a>" return "<a href=\"" + Link + "\" title=\"" + Title + "\" target=\"_blank\">" + Text + "</a>"
def _render_link(self, link, title, text, theme_tag): link = escape_link(link) link_color = {} text_color = {} start = '->' end = '<-' if self._theme is not None: theme_info = self._theme.get(theme_tag, {}) start = theme_info.get('start_symbol', start) end = theme_info.get('end_symbol', end) text_color = theme_info.get('text_color', text_color) link_color = theme_info.get('link_color', link_color) text = color(text, **text_color) link = color(f' {start} {link} {end}', **link_color) return f'{text}{link}'
def image(self, src, title, text): """Rendering a image with title and text. :param src: source link of the image. :param title: title text of the image. :param text: alt text of the image. """ src = escape_link(src) text = escape(text, quote=True) if title: title = escape(title, quote=True) html = '<img src="%s" alt="%s" title="%s"' % (src, text, title) else: html = '<img src="%s" alt="%s"' % (src, text) if self.options.get('use_xhtml'): return '%s />' % html return '%s>' % html
def image(self, src, title, text): """Rendering a image with title and text. :param src: source link of the image. :param title: title text of the image. :param text: alt text of the image. """ src = escape_link(src) text = escape(text, quote=True) if title: title = escape(title, quote=True) attributes = f'src="{src}" alt="{text}" title="{title}" width="100%"' else: attributes = f'src="{src}" alt="{text}" width="100%"' if self.options.get('use_xhtml'): return f'<img {attributes}/>' return f'<img {attributes}>'
def image(self, src, title, text): # if not an external image, use the static_url template function # doing it the lazy way and just checking if / is in the name # if not, it probably is image.png or sth similar # not doing proper escaping of quotes, but good enough if '/' not in src: src = '{{ static_url("external/images/faq/%s") }}' % src else: src = mistune.escape_link(src) # the rest is the same as the original function text = mistune.escape(text, quote=True) if title: title = mistune.escape(title, quote=True) html = '<img src="%s" alt="%s" title="%s"' % (src, text, title) else: html = '<img src="%s" alt="%s"' % (src, text) if self.options.get('use_xhtml'): return '%s />' % html return '%s>' % html
def link(self, link, title, text): link = mistune.escape_link(link) if not title: return f'<a href="{link}" target="_blank">{text}</a>' title = mistune.escape(title, quote=True) return f'<a href="{link}" title="{title}" target="_blank">{text}</a>'
def link(self, link, title, text): link = mistune.escape_link(link) if not title: return '<a href="%s"%s>%s</a>' % (link, self._link_rel(link), text) title = mistune.escape(title, quote=True) return '<a href="%s" title="%s"%s>%s</a>' % (link, title, self._link_rel(link), text)
def autolink(self, link, is_email=False): link = mistune.escape_link(link) if is_email: link = 'mailto:%s' % link target = 'target="_blank"' if not link_in_this_site(link) else '' return f'<a href="{link}" {target}>{link}</a>'
def link(self, link, title, content): link = mistune.escape_link(link) title = f'title="{title}"' if title else '' target = 'target="_blank"' if not link_in_this_site(link) else '' return f'<a href="{link}" {title} {target}>{content}</a>'
def video(self, src, title, text, video_width=None, video_height=None, autoplay=None, controls=None, loop=None, attribute=None): """Video html render function""" asset_slug, args = AssetRenderer._asset_url_helper(src) if asset_slug is not None: asset = VideoAsset.objects.filter(slug=asset_slug).first() size = args.get('size', None) if autoplay is None: autoplay = args.get('autoplay', None) if autoplay is not None: autoplay = autoplay == 'true' if controls is None: controls = args.get('controls', None) if controls is not None: controls = controls == 'true' if loop is None: loop = args.get('loop', None) if loop is not None: loop = loop == 'true' if asset is not None: if asset.asset.url: src = asset.asset.url else: src = '' if not title: title = asset.title if not text: text = asset.description if autoplay is None: autoplay = asset.autoplay if controls is None: controls = asset.controls if loop is None: loop = asset.loop if size is None: video_width = asset.video_width video_height = asset.video_height else: try: (video_width, video_height) = (int(x) for x in size.split('x')) except ValueError: pass if video_width is None: video_width = self.DEFAULT_VIDEO_WIDTH if video_height is None: video_height = self.DEFAULT_VIDEO_HEIGHT if loop is None: loop = False if controls is None: controls = self.DEFAULT_VIDEO_CONTROLS if autoplay is None: autoplay = self.DEFAULT_VIDEO_AUTOPLAY if not controls and not autoplay: autoplay = True src = mistune.escape_link(src) ext = src.split('.')[-1] if title: title = mistune.escape(title) if text: text = mistune.escape(text) # - Render html = '<video width="' if video_width: html += '{}" height="'.format(video_width) if video_height: html += '{}"'.format(video_height) if attribute: html += 'class="%s"' % (attribute,) if controls: html += " controls" if autoplay: html += " autoplay muted" if loop: html += " loop" html += ">" html += '<source src="{}" type="video/{}">'.format(src, ext) if title: html += title if text: html += ": " + text else: if text: html += text else: html += "Your browser does not support the video tag." html += "</video>" return html
def autolink(self, link, is_email=False): text = link = mistune.escape_link(link) if is_email: link = 'mailto:%s' % link return '<a href="%s" rel="nofollow">%s</a>' % (link, text)
def image(self, link, title, text): src = mistune.escape_link(link) return '<img src="%s" />' % src
def link(self, link, title, text): link = mistune.escape_link(link) return '[url=%s]%s[/url]' % (link, text)
def autolink(self, link, is_email=False): text = link = mistune.escape_link(link) if is_email: link = 'mailto:%s' % link return '[url=%s]%s[/url]' % (link, text)