def test_escaping():
    # This is "valid", e.g.
    # https://www.reddit.com/r/programmingcirclejerk/comments/9v7ix9/github_cee_lo_green_implements_fk_you_as_a_feature/e9adb06/
    widget = newmarkdown.make_markdown_widget('Please refer to <url> for')
    assert_matches_snapshot('newmarkdown--escaping', snapshot_widget(widget))

    w = newmarkdown.make_markdown_widget('Code: `<hello></hello>`')
    assert_matches_snapshot('newmarkdown--escaping-code', snapshot_widget(w))

    w = newmarkdown.make_markdown_widget('& I <3 you')
    assert_matches_snapshot('newmarkdown--escaping-amp', snapshot_widget(w))
예제 #2
0
    def _init_post(self, post):
        self.got_post_data.emit(post)

        self._top = posttopbar.PostTopBar(self._api,
                                          post,
                                          self,
                                          hideable=False,
                                          refreshable=True,
                                          show_subreddit=True)
        self._top.get_style_context().add_class('root-comments-bar')
        self._box.add(self._top)
        self._top.show()

        body = '# ' + post['title']
        if post.get('selftext'):
            body = body + '\n\n' + post['selftext']

        selfpost_label = newmarkdown.make_markdown_widget(body)
        selfpost_label.get_style_context().add_class('root-comments-label')
        self._box.add(selfpost_label)
        selfpost_label.show()

        self._comments = None
        self._load_full = None
        self._selected = self._top
def test_code():
    widget = newmarkdown.make_markdown_widget('''
hello:

    <html>
    </html>
''')
    assert_matches_snapshot('newmarkdown--code', snapshot_widget(widget))
예제 #4
0
    def __got_info_cb(self, data):
        expander = self._g('expander')
        child = expander.get_child()
        if child is not None:
            expander.remove(ch)
            ch.destroy()

        markdown = data['data']['description']
        expander.add(newmarkdown.make_markdown_widget(markdown))
def test_list():
    widget = newmarkdown.make_markdown_widget('''
1. hello
3. world

* yeah
* sam
    ''')
    assert_matches_snapshot('newmarkdown--list', snapshot_widget(widget))
def test_hr():
    widget = newmarkdown.make_markdown_widget('''
hello

---

world
    ''')
    assert_matches_snapshot('newmarkdown--hr', snapshot_widget(widget))
def test_blockquote():
    widget = newmarkdown.make_markdown_widget('''
hello world

> **quoted**
>
> > sub quote
    ''')
    assert_matches_snapshot('newmarkdown--quote', snapshot_widget(widget))
    def __got_info_cb(self, data):
        expander = self._g('expander')
        child = expander.get_child()
        if child is not None:
            expander.remove(ch)
            ch.destroy()

        markdown = data['data']['description']
        expander.add(newmarkdown.make_markdown_widget(markdown))
def test_link():
    widget = newmarkdown.make_markdown_widget('/r/linux')
    assert_matches_snapshot('newmarkdown--link--r', snapshot_widget(widget))

    cb = MagicMock()
    label = find_widget(widget, label='<a href="/r/linux">/r/linux</a>')
    label.get_toplevel().load_uri_from_label = cb

    label.emit('activate-link', '/r/linux')
    assert cb.called
    (link,), _ = cb.call_args
    assert link == '/r/linux'
예제 #10
0
    def __init__(self, api: RedditAPI, data):
        Gtk.ListBoxRow.__init__(self)
        self.get_style_context().add_class('link-row')
        self.add_events(Gdk.EventMask.KEY_PRESS_MASK)
        self._api = api
        self.data = data['data']

        is_comment_reply = self.data.get('subreddit') is not None

        self._builder = Gtk.Builder.new_from_resource(
            '/today/sam/reddit-is-gtk/row-comment.ui')
        self._g = self._builder.get_object
        self.add(self._g('box'))

        read = not self.data.get('new', True)
        if read:
            self.read()

        # Keep a reference so the GC doesn't collect them
        self._abb = AuthorButtonBehaviour(self._g('author'), self.data)
        self._tbb = TimeButtonBehaviour(self._g('time'), self.data)
        if is_comment_reply:
            self._srbb = SubButtonBehaviour(self._g('subreddit'), self.data)
        else:
            self._g('subreddit').props.sensitive = False
            self._g('subreddit').props.label = 'PM'

        self._g('nsfw').props.visible = self.data.get('over_18')
        self._g('saved').props.visible = self.data.get('saved')

        self._g('title').props.label = (self.data.get('link_title')
                                        or self.data['subject'])
        content = newmarkdown.make_markdown_widget(self.data['body'])
        self._g('grid').attach(content, 0, 2, 3, 1)

        if is_comment_reply:
            self._g('type-private-message').props.visible = False
        else:
            self._g('type-comment-reply').props.visible = False
    def __init__(self, api: RedditAPI, data):
        Gtk.ListBoxRow.__init__(self)
        self.get_style_context().add_class('link-row')
        self.add_events(Gdk.EventMask.KEY_PRESS_MASK)
        self._api = api
        self.data = data['data']

        is_comment_reply = self.data.get('subreddit') is not None

        self._builder = Gtk.Builder.new_from_resource(
            '/today/sam/reddit-is-gtk/row-comment.ui')
        self._g = self._builder.get_object
        self.add(self._g('box'))

        read = not self.data.get('new', True)
        if read:
            self.read()

        # Keep a reference so the GC doesn't collect them
        self._abb = AuthorButtonBehaviour(self._g('author'), self.data)
        self._tbb = TimeButtonBehaviour(self._g('time'), self.data)
        if is_comment_reply:
            self._srbb = SubButtonBehaviour(self._g('subreddit'), self.data)
        else:
            self._g('subreddit').props.sensitive = False
            self._g('subreddit').props.label = 'PM'

        self._g('nsfw').props.visible = self.data.get('over_18')
        self._g('saved').props.visible = self.data.get('saved')

        self._g('title').props.label = (self.data.get('link_title') or
                                        self.data['subject'])
        content = newmarkdown.make_markdown_widget(self.data['body'])
        self._g('grid').attach(content, 0, 2, 3, 1)

        if is_comment_reply:
            self._g('type-private-message').props.visible = False
        else:
            self._g('type-comment-reply').props.visible = False
예제 #12
0
    def _init_post(self, post):
        self.got_post_data.emit(post)

        self._top = posttopbar.PostTopBar(
            self._api, post, self, hideable=False,
            refreshable=True, show_subreddit=True)
        self._top.get_style_context().add_class('root-comments-bar')
        self._box.add(self._top)
        self._top.show()

        body = '# ' + post['title']
        if post.get('selftext'):
            body = body + '\n\n' + post['selftext']

        selfpost_label = newmarkdown.make_markdown_widget(body)
        selfpost_label.get_style_context().add_class('root-comments-label')
        self._box.add(selfpost_label)
        selfpost_label.show()

        self._comments = None
        self._load_full = None
        self._selected = self._top
def test_hello():
    widget = newmarkdown.make_markdown_widget('hello')
    assert_matches_snapshot('newmarkdown--hello', snapshot_widget(widget))
def test_heading():
    widget = newmarkdown.make_markdown_widget('''
# big
### small
    ''')
    assert_matches_snapshot('newmarkdown--heading', snapshot_widget(widget))
def test_super():
    w = newmarkdown.make_markdown_widget('hello ^my world')
    assert_matches_snapshot('newmarkdown--super', snapshot_widget(w))

    w = newmarkdown.make_markdown_widget('hello ^(woah long) world')
    assert_matches_snapshot('newmarkdown--super-long', snapshot_widget(w))
def test_inline():
    widget = newmarkdown.make_markdown_widget('**b** _i_ ~~s~~ `<code>`')
    assert_matches_snapshot('newmarkdown--inline', snapshot_widget(widget))