Permalink
Browse files

default template changed, support rst

  • Loading branch information...
1 parent d65b747 commit 0ae700b6d938f7a8cfc74e02ff37e9d85bdda713 lepture committed May 30, 2012
Showing with 45 additions and 116 deletions.
  1. +19 −2 dotpy/doki.py
  2. +26 −114 dotpy/template.html
View
@@ -6,8 +6,11 @@
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
+from docutils.core import publish_parts
+import sphinx.directives.code
-__all__ = ['markdown']
+
+__all__ = ['markdown', 'rst']
_emoji_list = [
"-1", "0", "1", "109", "2", "3", "4", "5", "6", "7", "8", "8ball", "9",
@@ -186,6 +189,11 @@ def markdown(text, noclasses=False, lang=None):
return md.render(text)
+def rst(text, *args, **kwargs):
+ parts = publish_parts(text, writer_name='html')
+ return parts['body']
+
+
if __name__ == '__main__':
import os
import argparse
@@ -195,6 +203,8 @@ def markdown(text, noclasses=False, lang=None):
help='inline style for code')
parser.add_argument('-t', '--template', dest='template')
parser.add_argument('-l', '--language', dest='language')
+ parser.add_argument('--title', dest='title')
+ parser.add_argument('--github', dest='github')
args = parser.parse_args()
if args.template and args.template == 'default':
@@ -211,7 +221,14 @@ def markdown(text, noclasses=False, lang=None):
noclasses = False
text = ''
for f in args.file:
- text += markdown(open(f).read(), noclasses, args.language)
+ if f.endswith('.rst'):
+ text += rst(open(f).read(), noclasses, args.language)
+ else:
+ text += markdown(open(f).read(), noclasses, args.language)
text = template.replace('{{text}}', text)
+ if args.title:
+ text = text.replace('{{title}}', args.title)
+ if args.github:
+ text = text.replace('{{github}}', args.github)
print(text.encode('utf-8'))
View
@@ -1,124 +1,36 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
- <meta charset="UTF-8">
+ <meta charset="UTF-8" />
<title>{{title}}</title>
- <style type="text/css">
- html, body {
- background: #f9f9f9;
- color: #333;
- padding: 0;
- margin: 0;
- font: 14px/1.6 "Lucida Grande", "Helvetica", sans-serif;
- }
- h1,h2,h3,h4 {
- font-family: 'PT Sans', sans-serif;
- }
- h1 {
- margin-top: 0;
- font-size: 36px;
- }
- h2 {
- margin: 25px 0 5px;
- }
- h3 {
- margin: 20px 0 5px;
- }
- .container {
- width: 650px;
- margin: 0 auto;
- padding: 20px;
- }
-
- /* block level */
- blockquote {
- border-left: 0.4em solid #ddd;
- margin: 15px 0;
- padding: 0 15px;
- color: #777;
- }
- blockquote blockquote {
- padding: 0 0 0 1em;
- margin-left: 2em;
- border-left: 0.4em solid #ddd;
- }
-
- p {
- font-weight: normal;
- line-height: 160%;
- margin-bottom: 0.8em;
- }
- figure {margin:0; padding:0;}
-
- hr {
- border-top: 1px solid #dadada;
- border-bottom: 1px solid #dadada;
- }
-
- ul, ol {
- margin: 14px 0;
- padding-left: 30px;
- }
- ul {
- list-style: square;
- }
- li ul {
- list-style: disc;
- margin: 8px 0;
- }
-
- /* span level */
- img {
- max-width: 100%;
- }
- a {
- color: #4183C4;
- text-decoration: none;
- overflow: hidden;
- word-wrap: break-word;
- }
- a:hover {
- text-decoration: underline;
- }
- a img {
- vertical-align: middle;
- }
- strong {
- color: #424242;
- }
-
- /* code */
- pre, code{
- font: 12px Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
- }
- pre {
- margin: 1em 0;
- background-color: #f0f0f0;
- border: 1px solid #ddd;
- padding: 8px;
- line-height: 1.5em;
- color: #444;
- overflow: auto;
- box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset;
- border-radius: 3px;
- }
- pre code {
- padding:0;
- background-color: #eee;
- border: none;
- }
- code {
- font-size:12px;
- background-color:#f8f8ff;
- color:#444;
- padding:0 .2em;
- border:1px solid #dedede;
- }
- </style>
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0" />
+ <meta name="author" content="lepture" />
+ <link rel="alternate" type="application/rss+xml" href="http://feeds.lepture.com/lepture" title="Website Feed" />
+ <link rel="stylesheet" href="http://python-assets.b0.upaiyun.com/project/typo.css" />
+ <link rel="stylesheet" href="http://python-assets.b0.upaiyun.com/project/pygments.css" />
+ <script type="text/javascript">
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-21475122-1']);
+ _gaq.push(['_trackPageview']);
+ _gaq.push(['_trackPageLoadTime']);
+ _gaq.push(['_setCustomVar', 1, 'Project', '{{title}}', 2]);
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+ </script>
</head>
<body>
- <div class="container wrapper">
+ <div class="container">
{{text}}
</div>
+ <hr class="end" />
+ <div id="footer">
+ <a href="https://github.com/lepture">GitHub</a>
+ <a href="http://lepture.com">Website</a>
+ <a href="https://twitter.com/lepture">Twitter</a>
+ </div>
+ <a id="github" href="https://github.com/lepture/{{github}}" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0; z-index:999" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
</body>
</html>

0 comments on commit 0ae700b

Please sign in to comment.