-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from praw-dev/inline_media
Add ability to submit selttext with inline media
- Loading branch information
Showing
14 changed files
with
871 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Provide classes related to inline media.""" | ||
|
||
|
||
class InlineMedia: | ||
"""Provides a way to embed media in self posts.""" | ||
|
||
TYPE = None | ||
|
||
def __init__(self, path: str, caption: str = None): | ||
"""Create an InlineMedia instance. | ||
:param path: The path to a media file. | ||
:param caption: An optional caption to add to the image. (default: None) | ||
""" | ||
self.path = path | ||
self.caption = caption | ||
self.media_id = None | ||
|
||
def __eq__(self, other: "InlineMedia"): | ||
"""Return whether the other instance equals the current.""" | ||
return all( | ||
[ | ||
getattr(self, attr) == getattr(other, attr) | ||
for attr in ["TYPE", "path", "caption", "media_id"] | ||
] | ||
) | ||
|
||
def __repr__(self) -> str: | ||
"""Return a string representation of the InlineMedia instance.""" | ||
return f"<{self.__class__.__name__} caption={self.caption!r}>" | ||
|
||
def __str__(self): | ||
"""Return a string representation of the media in Markdown format.""" | ||
return f'\n\n![{self.TYPE}]({self.media_id} "{self.caption if self.caption else ""}")\n\n' | ||
|
||
|
||
class InlineGif(InlineMedia): | ||
"""Class to provide a gif to embed in text.""" | ||
|
||
TYPE = "gif" | ||
|
||
|
||
class InlineVideo(InlineMedia): | ||
"""Class to provide a video to embed in text.""" | ||
|
||
TYPE = "video" | ||
|
||
|
||
class InlineImage(InlineMedia): | ||
"""Class to provide am image to embed in text.""" | ||
|
||
TYPE = "img" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
InlineGif | ||
========= | ||
|
||
.. autoclass:: asyncpraw.models.InlineGif | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
InlineImage | ||
=========== | ||
|
||
.. autoclass:: asyncpraw.models.InlineImage | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
InlineMedia | ||
=========== | ||
|
||
.. autoclass:: asyncpraw.models.InlineMedia | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
InlineVideo | ||
=========== | ||
|
||
.. autoclass:: asyncpraw.models.InlineVideo | ||
:inherited-members: |
Oops, something went wrong.