Including Flash content inline in a custom Weblog? - python

I'm trying to think of a way to place Flash content into a blog post so that it appears inline between paragraphs. I'm writing a custom weblog application in Django (still learning) and I'll be using SWFObject for the embedding.
The blog is for me only so the back-end isn't too fancy. I'm simply using Django's built in admin interface. No TinyMCE rich text editor (like Wordpress), rather I've implemented Markdown.
I'd like to add Flash content into the body of a post, between paragraphs, in a way that is not coupled to any third party script. Meaning, I would prefer not to include javascript within the body of the blog post as it introduces a dependency on SWFObject. For example, I could quite easily add the following to an entry via the back-end to embed a SWF inline:
Paragraph one...
<script type="text/javascript">
swfobject.embedSWF("/path/to/flash.swf", "myContent", "200", "200", "9.0.0");
</script>
<div id="myContent"></div>
Paragraph two...
As you can see this is quite wordy and a lot to remember but it also refers to SWFObject directly. This WILL work, however I would prefer to write it in a "cleaner" more abstract way. What I was thinking of doing is creating my own parser which would translate a custom string into the above just before rendering a template.
[#SWF swf="/path/to/flash.swf" w="200" h="200" ver="9.0.0"]
I'm wondering if anyone has encountered this issue. I'd love to know how you solved it.

You might want to look into OEmbed, specifically the django-oembed project.

Related

Best way to store web page content in database using Django and a single template for web pages

I'm building a web site and the bulk of the content will be the same general type and layout on the page. I'm going to use a single template to handle each post and the actual content will be stored in a database.
The content will just be html paragraphs, headers, sub headers, different lists, quotes, code blocks, etc.
Web pages will typically be the same or at least similar. All html components should follow the same guidelines to make sure everything looks and feels the same. Currently I'll be the only author, but in the future I plan to incorporate other authors as well.
At first I thought, just copy and paste this html content into a textfield in the database and I can add new posts/articles on the admin site.
Then I thought, maybe use a textfield and copy and paste json of a list of ['type': , 'content': ]. and then I can have the single template page iterate over this list and display the content based on the 'type'. My idea here is that it would shorten the data I have to add to the database by stripping the html tags out of the equation.
Considering I hope to have future authors as well, just curious of some ideas on how I can accomplish this to make it easy for myself to post new content.
That sounds pretty much exactly like the example of this fantastic tutorial by Miguel Grinberg. He sets up a flask environment to be used as his personal blog. With user log in and everything you would need.

How to parse text before being loaded into Django's admin for editing

I am creating a dynamic blog. I use Django's admin to add posts, and I have created some simple tags that python then substitutes for the actual html and css that are needed by the browser. This makes each blog easier to create and easier to read while creating.
Before Django saves the new blog, I've coded my model to send the text to a python script, which parses the code and creates the finished html.
This all works great, but I would also like to be able to parse the code before Django loads it, that way I can remove the html/css programatically, changing it back to the easier to read tags, making it easier to edit an already created blog.
Is there a way to capture control of Django admin BEFORE it loads model data into the form for editing?
The more simple solution is to have two fields, the original and the generated HTML.
Use the original as you are using it now and save the generated HTML to the other field.
Use the other field for your templates.

Best way to programmatically save a webpage to a Static HTML File

The more research I do, the more grim the outlook becomes.
I am trying to Flat Save, or Static Save a webpage with Python. This means merging all the styles to inline properties, and changing all links to absolute URLs.
I've tried nearly every free conversion website, api, and even libraries on github. None are that impressive. The best python implementation I could find for flattening styles is https://github.com/davecranwell/inline-styler. I adapted that slightly for Flask, but the generated file isn't that great. Here's how it looks:
Obviously, it should look better. Here's what it should look like:
https://dzwonsemrish7.cloudfront.net/items/3U302I3Y1H0J1h1Z0t1V/Screen%20Shot%202012-12-19%20at%205.51.44%20PM.png?v=2d0e3d26
It seems like a neverending struggle dealing with Malformed html, unrecognized CSS properties, Unicode errors, etc. So does anyone have a suggestion on a better way to do this? I understand I can go to file -> save in my local browser, but when I am trying to do this en mass, and extract a particular xpath that's not really viable.
It looks like Evernote's web clipper uses iFrames, but that seems more complicated than I think it should be. But at least the clippings look decent on Evernote.
After walking away for a while, I managed to install a ruby library that flattens the CSS much much better than anything else I've used. It's the library behind the very slow web interface here http://premailer.dialect.ca/
Thank goodness they released the source on Github, it's the best hands down.
https://github.com/alexdunae/premailer
It flattens styles, creates absolute urls, works with a URL or string, and can even create plain text email templates. Very impressed with this library.
Update Nov 2013
I ended up writing my own bookmarklet that works purely client side. It is compatible with Webkit and FireFox only. It recurses through each node and adds inline styles then sends the flattened HTML to the clippy.in API to save to the user's dashboard.
Client Side Bookmarklet
It sounds like inline styles might be a deal-breaker for you, but if not, I suggest taking another look at Evernote Web Clipper. The desktop app has an Export HTML feature for web clips. The output is a bit messy as you'd expect with inline styles, but I've found the markup to be a reliable representation of the saved page.
Regarding inline vs. external styles, for something like this I don't see any way around inline if you're doing a lot of pages from different sites where class names would have conflicting style rules.
You mentioned that Web Clipper uses iFrames, but I haven't found this to be the case for the HTML output. You'd likely have to embed the static page as an iFrame if you're re-publishing on another site (legally I assume), but otherwise that shouldn't be an issue.
Some automation would certainly help so you could go straight from the browser to the HTML output, and perhaps for relocating the saved images to a single repo with updated src links in the HTML. If you end up working on something like this, I'd be grateful to try it out myself.

simple markup for jinja2 or html textarea

I am writing a google app engine web app using python and jinja2. Is there a simple lightweight textarea markup that I can use either for jinja2 or just generally for an HTML text area. I just want line breaks to come across and italics and bold and maybe one or two other things but I don't just want to mark is safe (and not autoescape the rest of it).
I am surprised that no one has asked a similar question and they probably have so maybe I'm just using the wrong keywords.
You could use TinyMCE to add markup features to a textarea. Visitors of your site (or administrators, if that's where you happen to use it) can then add HTML markup in a user-friendly way.
Alternatively, you could add a Markdown parser (or a similar language) that allows users to add markup using basic symbols. Your website would parse and process the content prior to displaying it.

CMS or Wiki for creating XHTML ebook + blog

For a long time I have been wanting to start a blog. But knowing myself, I know I won't update it often. So, I would like to club my blog with an "ebook". I'd like to write some beginner level ebook/course on Biostatistics.
Here are some examples of other blogs (+ebooks) that follow this approach:
A Byte of Python: http://www.swaroopch.com/notes/Python
BabyPips (FX trading): http://www.babypips.com/school/
Learn Python the Hard way (ebook only): http://learnpythonthehardway.org/book/
I could simply use WordPress or Tumblr or some blog site to create a blog and write my tutorials there. One post for each tutorial. BUT I am leaning towards creating a more structured book with table-of-contents, sequential chapters, prev/next navigation, and even quizzes (if possible) etc. Blog-post style is better suited for independent tutorials that don't follow a structured course/book format.
For Blog section, there is WordPress etc. But I haven't figured out how to create a structured ebook like these guys have created. What software/plugin/CMS/wiki plugin to use for this?
PS: eventually, I'd also like to convert my web ebook to PDF, MOBI, EPUB format. But that is probably not hard. Most important is to publish a web ebook like these guys have done it.
UPDATE:
Ideally, I just want to be able to login and click create-> new book or new chapter or something and just write like I'd write in a WYSIWYG editor. That script should take care of generating table of content and navigation etc. I think this probably resemebles wiki script but wiki-script probably won't take care of next/prev navigation.
http://www.swaroopch.com/notes/Python uses MediaWiki, which is okay for writing books. If you want to publish in several formats, a sophisticated markup language like Markdown or reStructuredText might be more appropriate. You can use different utilities to create static web pages using those, like Sphinx, Hyde or Jinja.

Categories

Resources