Markdown extension for embedding tweets using twitter OEmbed API
Free software: BSD license
How to use
Allows you to embed tweets into your Markdown.
Just install the package:
pip install mdx-twitter
Because Twitter API 1.1 requires you to authenticate, you will need to create a config file with your credentials at ‘~/.mdx_twitter.cfg’:
[Twitter] CONSUMER_KEY=xxxxxxxxxxxx CONSUMER_SECRET=xxxxxxxxxxxx ACCESS_TOKEN=xxxxxxxxxxxx ACCESS_TOKEN_SECRET=xxxxxxxxxxxx
Then just add ‘twitter’ to the list of your extensions:
import markdown md = markdown.Markdown(extensions=['twitter'])
Twitter urls in your Makdown will become embedded tweets:
https://twitter.com/jasoncosta/status/240192632003911681
Django integration
Since Twitter has a rate limit on their APIs, and doing network calls all the time just to render Markdown is a bad idea anyways, we would need some caching.
If you are using mdx-twitter in a Django project, it will automatically use your cache settings to cache HTML returned from Twitter API.
Also, you could place your API credentials in TWITTER_SETTINGS variable in your project’s settings.py, instead of using .cfg file
TWITTER_SETTINGS = { 'CONSUMER_KEY': '', 'CONSUMER_SECRET': '', 'ACCESS_TOKEN': '', 'ACCESS_TOKEN_SECRET': '', }
Embedding tweets in UIWebView
There are currently some problems with embedding tweets in UIWebView.
Protocol agnostic src attribute “//platform.twitter.com/widgets.js” doesn’t allow script to load
There seems to be a problem with automatically determining width of the container
So there is a ‘width’ configuration option that offers a quick ‘fix’ for those problems. Just specify expected width of your tweet in pixels.
import markdown md = markdown.Markdown(extensions=['twitter(width=300)'])
It will only work with ‘style’ full.
Styles
You can customize appearance of your tweets using ‘style’ configuration options. Default style is ‘full’, which includes script javascript, you could also use ‘simple’ style, which just includes tweet in a blockquote tag without javascript.
Another option would be to specify a path to your own function, which accepts Twitter response json as an argument and should return final html.
An example custom style is included in the library. You can use it by specifying ‘style=mdx_twitter.custom_style’
TODO
If we embed multiple tweets, we don’t need to have script tag after each tweet. We should probably just have a script tag at the end of the document.
History
0.1.0 (2013-08-31)
First release on PyPI.
Metadata
Release files for mdx-twitter 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mdx-twitter-0.2.6.tar.gz | 7.4 kB | Without provenance | Details for mdx-twitter-0.2.6.tar.gz |
Release files / mdx-twitter-0.2.6.tar.gz
| Download URL | mdx-twitter-0.2.6.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97159a27ad24bff8420bfe74d2a5b54ff647c5a27b517000d10ec314f63bfbc1
|
|
BLAKE2b-256 checksum How to use checksums |
a2b86876229e985805202db0177d48c60dbd9b799cfe8c49563a73d24902c84f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for mdx-twitter 0.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.