Permalink
Browse files

Merge branch 'master' of https://github.com/EnigmaCurry/blogofile

  • Loading branch information...
2 parents fcb27c3 + 042eec8 commit 3938014f7e4d8d8baea9cccffe3ef7c99b907752 @nix committed Dec 21, 2011
View
@@ -10,3 +10,5 @@
/blogofile/site_init/*.zip
_site/*
_documentation/themes/blogofile/layout.html
+/.tox/*
+/MANIFEST
@@ -18,6 +18,7 @@
import codecs
import base64
import urllib
+from xml.sax import saxutils
import pytz
import yaml
@@ -169,7 +170,8 @@ def __post_process(self):
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
if not self.slug:
- self.slug = re.sub("[ ?]", "-", self.title).lower()
+ self.slug = saxutils.unescape(self.title)
+ self.slug = re.sub("[^a-zA-Z0-9$\-_\.+!*'(),]", "-", self.slug).lower()
if not self.date:
self.date = datetime.datetime.now(pytz.timezone(self.__timezone))
@@ -4,25 +4,9 @@
import pygments
from pygments import formatters, util, lexers
import blogofile_bf as bf
-
-config = {"name": "Syntax Highlighter",
- "description": "Highlights blocks of code based on syntax",
- "author": "Ryan McGuire",
- "css_dir": "/css",
- "preload_styles": []}
-
-
-def init():
- #This filter normally only loads pygments styles when needed.
- #This will force a particular style to get loaded at startup.
- for style in bf.config.filters.syntax_highlight.preload_styles:
- css_class = "pygments_{0}".format(style)
- formatter = pygments.formatters.HtmlFormatter(
- linenos=False, cssclass=css_class, style=style)
- write_pygments_css(style, formatter)
-
-example = """
+#Example usage:
+"""
This is normal text.
@@ -68,6 +52,23 @@ def to_s
This is normal text
"""
+config = {"name": "Syntax Highlighter",
+ "description": "Highlights blocks of code based on syntax",
+ "author": "Ryan McGuire",
+ "css_dir": "/css",
+ "preload_styles": []}
+
+
+def init():
+ #This filter normally only loads pygments styles when needed.
+ #This will force a particular style to get loaded at startup.
+ for style in bf.config.filters.syntax_highlight.preload_styles:
+ css_class = "pygments_{0}".format(style)
+ formatter = pygments.formatters.HtmlFormatter(
+ linenos=False, cssclass=css_class, style=style)
+ write_pygments_css(style, formatter)
+
+
css_files_written = set()
code_block_re = re.compile(
@@ -90,19 +91,21 @@ def to_s
"[,\r\n]" # ends in a comma or newline
)
-
def highlight_code(code, language, formatter):
try:
lexer = pygments.lexers.get_lexer_by_name(language)
except pygments.util.ClassNotFound:
lexer = pygments.lexers.get_lexer_by_name("text")
- #Highlight with pygments and surround by blank lines
- #(blank lines required for markdown syntax)
- highlighted = "\n\n{0}\n\n".format(
- pygments.highlight(code, lexer, formatter))
+ #Highlight with pygments
+ highlighted = pygments.highlight(code, lexer, formatter)
+ #Convert line endings to <br> tags:
+ highlighted = highlighted.replace("\n","<br/>")
+ #But get rid of the last <br> which throws off line numbers:
+ highlighted = "</pre></div>".join(highlighted.rsplit("</pre></div><br/>"))
+ #Surround the text with newlines so markdown etc parse properly:
+ highlighted = "\n\n{0}\n\n".format(highlighted)
return highlighted
-
def parse_args(args):
#Make sure the args are newline terminated (req'd by regex)
opts = {}
View
@@ -115,9 +115,9 @@ def __write_files(self):
#Copy this non-template file
f_path = util.path_join(root, t_fn)
logger.debug("Copying file: " + f_path)
- if self.config.site.overwrite_warning and os.path.exists(path):
- logger.warn("Location is used more than once: {0}".format(f_path))
out_path = util.path_join(self.output_dir, f_path)
+ if self.config.site.overwrite_warning and os.path.exists(out_path):
+ logger.warn("Location is used more than once: {0}".format(f_path))
if self.bf.config.site.use_hard_links:
# Try hardlinking first, and if that fails copy
try:

0 comments on commit 3938014

Please sign in to comment.