How to use the publ.utils.make_tag function in Publ

To help you get started, we’ve selected a few Publ examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PlaidWeb / Publ / tests / test_utils.py View on Github external
""" test of utils.make_tag """

    assert utils.make_tag('a', {'href': 'foo'}, False) == '<a href="foo">'
    assert utils.make_tag('a',
                          [('href', 'foo'), ('href', 'bar')],
                          True) == '</a><a href="foo">'
    with pytest.raises(Exception):
        utils.make_tag('a', (('href', 'foo')))

    app = flask.Flask(__name__)
    with app.test_request_context():
        proxy = utils.CallableValue("")
        assert utils.make_tag('a', {'href': proxy}) == '</a><a href="<hello>">'

    escaped = flask.Markup("&amp;")
    assert utils.make_tag('a', {'href': escaped}) == '</a><a href="&amp;">'
</a>
github PlaidWeb / Publ / tests / test_utils.py View on Github external
def test_make_tag():
    """ test of utils.make_tag """

    assert utils.make_tag('a', {'href': 'foo'}, False) == '<a href="foo">'
    assert utils.make_tag('a',
                          [('href', 'foo'), ('href', 'bar')],
                          True) == '</a><a href="foo">'
    with pytest.raises(Exception):
        utils.make_tag('a', (('href', 'foo')))

    app = flask.Flask(__name__)
    with app.test_request_context():
        proxy = utils.CallableValue("")
        assert utils.make_tag('a', {'href': proxy}) == '</a><a href="<hello>">'

    escaped = flask.Markup("&amp;")
    assert utils.make_tag('a', {'href': escaped}) == '</a><a href="&amp;">'
</a>
github PlaidWeb / Publ / publ / html_entry.py View on Github external
# Remap the attributes
        out_attrs = []
        for key, val in attrs:
            if (key.lower() == 'href'
                    or key.startswith('$')
                    or (key.lower() == 'src' and tag.lower() != 'img')):
                if key.startswith('$'):
                    key = key[1:]
                out_attrs.append((key, links.resolve(
                    val, self._search_path, self._config.get('absolute'))))
            else:
                out_attrs.append((key, val))

        self.append(
            utils.make_tag(
                tag,
                out_attrs,
                self_closing))
github PlaidWeb / Publ / publ / markdown.py View on Github external
remain = 0
        for (spec, show) in spec_list:
            text += self._render_image(spec, show,
                                       container_args,
                                       alt)
            if not show:
                remain += 1

        if remain and 'more_text' in container_args:
            more_text = container_args['more_text'].format(
                count=len(spec_list),
                remain=remain)
            if 'more_link' in container_args:
                more_text = '{a}{text}'.format(
                    text=more_text,
                    a=utils.make_tag('a', {'href': container_args['more_link']}))
            if 'more_class' in container_args:
                more_text = '{div}{text}'.format(
                    text=more_text,
                    div=utils.make_tag('div', {'class': container_args['more_class']}))
            text += flask.Markup(more_text)

        if text and (container_args.get('div_class') or
                     container_args.get('div_style')):
            text = '{tag}{text}'.format(
                tag=utils.make_tag('div',
                                   {'class': container_args.get('div_class') or False,
                                    'style': container_args.get('div_style') or False}),
                text=text)

        # if text is ''/falsy then misaka interprets this as a failed parse...
        return text or ' '
github PlaidWeb / Publ / publ / image.py View on Github external
def _wrap_link_target(self, kwargs, text, title):
        if 'link' in kwargs and kwargs['link'] is not None:
            return '{}{}'.format(
                utils.make_tag(
                    'a', {'href': utils.remap_link_target(
                        kwargs['link'], kwargs.get('absolute')
                    )}),
                text)

        if 'gallery_id' in kwargs and kwargs['gallery_id'] is not None:
            return '{}{}'.format(
                self._fullsize_link_tag(kwargs, title), text)

        return text
github PlaidWeb / Publ / publ / image / image.py View on Github external
def _fullsize_link_tag(self, kwargs, title: typing.Optional[str]) -&gt; str:
        """ Render an <a href=""> that points to the fullsize rendition specified """

        return utils.make_tag('a', {
            'href': self.get_fullsize(kwargs),
            'data-lightbox': kwargs.get('gallery_id', False),
            'title': title or False,
            'class': kwargs.get('link_class', False)
        })</a>
github PlaidWeb / Publ / publ / markdown.py View on Github external
def footnote_ref(self, num):
        """ Render a link to this footnote """
        if self._config.get('_suppress_footnotes'):
            return '\u200b'  # zero-width space to prevent Misaka fallback

        return '{sup}{link}{content}'.format(
            sup=utils.make_tag('sup', {
                'id': self._footnote_id(num, "r"),
                'class': self._config.get('footnotes_class', False)
            }),
            link=utils.make_tag('a', {
                'href': self._footnote_url(num, "d"),
                'rel': 'footnote'
            }),
            content=self._footnote_num(num))
github PlaidWeb / Publ / publ / entry.py View on Github external
def og_tag(key, val) -> str:
                """ produce an OpenGraph tag with the given key and value """
                return utils.make_tag('meta', {'property': key, 'content': val}, start_end=True)
github PlaidWeb / Publ / publ / markdown.py View on Github external
def _wrap_code(self, source):
        line_number = 0
        for i, line in source:
            if i == 1:
                line_number += 1
                line_id = "{}L{}".format(self.line_id_prefix, line_number)

                yield 1, (utils.make_tag('span', {
                    'class': 'line',
                    'id': line_id
                }) + utils.make_tag('a', {
                    'class': 'line-number',
                    'href': self.link_base + '#' + line_id,
                }) + '' + utils.make_tag('span', {
                    'class': 'line-content',
                }) + line.rstrip().replace('  ', '&nbsp; ') + '\n')
github PlaidWeb / Publ / publ / markdown.py View on Github external
def footnote_ref(self, num):
        """ Render a link to this footnote """
        if self._config.get('_suppress_footnotes'):
            return '\u200b'  # zero-width space to prevent Misaka fallback

        return '{sup}{link}{content}'.format(
            sup=utils.make_tag('sup', {
                'id': self._footnote_id(num, "r"),
                'class': self._config.get('footnotes_class', False)
            }),
            link=utils.make_tag('a', {
                'href': self._footnote_url(num, "d"),
                'rel': 'footnote'
            }),
            content=self._footnote_num(num))