Skip to content

Commit

Permalink
Merge pull request #988 from skurfer/bltrversion
Browse files Browse the repository at this point in the history
new Documentation process
  • Loading branch information
pjrobertson committed Jul 19, 2012
2 parents 34c2ed6 + a32429c commit 057cd31
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 89 deletions.
8 changes: 4 additions & 4 deletions Quicksilver/Quicksilver.xcodeproj/project.pbxproj
Expand Up @@ -45,7 +45,7 @@
buildConfigurationList = 7F6B3E45085CE68E000735A8 /* Build configuration list for PBXAggregateTarget "Preflight" */;
buildPhases = (
4D8A0B3410AB23B6006AF163 /* CopyFiles */,
D4DCF31114D059DB006672AB /* Copy Markdown Python module */,
D4DCF31114D059DB006672AB /* Copy Markdown Python module and bltrversion */,
7F0399E8080EE58D001A9FA3 /* Remove PlugIns */,
7FA4EF1E0913AE44007DB407 /* Release Notes */,
);
Expand Down Expand Up @@ -3935,19 +3935,19 @@
shellPath = /usr/bin/python;
shellScript = "#!/usr/bin/env python\n# -*- encoding: utf-8 -*-\n\nimport os\nimport sys\nimport re\nimport codecs\nimport platform\n\nsrcroot = os.getenv('SRCROOT')\nif srcroot is None:\n sys.exit(78) # configuration error\n\n## location for input and output files\nsupp_dir = srcroot + \"/SharedSupport\"\n\n## fake the deployment target to make distutils happy\nos.environ['MACOSX_DEPLOYMENT_TARGET'] = '.'.join(platform.mac_ver()[0].split('.')[0:2])\n\n## import Markdown support\nsys.path.append(srcroot + \"/Tools/python-support\")\nimport markdown\n\n## get the original text\ninput_file = codecs.open(supp_dir + \"/CHANGELOG\", mode = \"r\", encoding = \"utf8\")\ntext = input_file.read()\n\n## make issue numbers link to GitHub\ntext = re.sub(r'#(\\d+)', u'[#\\g<1>](https://github.com/quicksilver/Quicksilver/issues/\\g<1>)', text)\n\n## convert to HTML\nmd = markdown.Markdown(extensions = ['extra'], output_format = 'html4')\nhtml = md.convert(text)\n\n## write the result\noutput_file = codecs.open(supp_dir + \"/Changes.html\", mode = \"w\", encoding = \"utf8\")\noutput_file.write(u'<!DOCTYPE html><html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"></head><body>\\n')\noutput_file.write(html)\noutput_file.write(u'\\n</body></html>\\n')\nbare_file = codecs.open(supp_dir + \"/ChangesBare.html\", mode = \"w\", encoding = \"utf8\")\nbare_file.write(html)\n";
};
D4DCF31114D059DB006672AB /* Copy Markdown Python module */ = {
D4DCF31114D059DB006672AB /* Copy Markdown Python module and bltrversion */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Markdown Python module";
name = "Copy Markdown Python module and bltrversion";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "mkdir -p \"$QS_BUILD_ROOT/Tools\"\ncp -r \"$SRCROOT/Tools/python-support\" \"$QS_BUILD_ROOT/Tools\"\n";
shellScript = "mkdir -p \"$QS_BUILD_ROOT/Tools\"\ncp -r \"$SRCROOT/Tools/python-support\" \"$QS_BUILD_ROOT/Tools\"\ncp \"$SRCROOT/Tools/bltrversion\" \"$QS_BUILD_ROOT/Tools\"\n";
};
E1A5676406FFDD8700BAD045 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
35 changes: 35 additions & 0 deletions Quicksilver/Tools/bltrversion
@@ -0,0 +1,35 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import sys
import os
import platform
import plistlib
import codecs
## fake the deployment target to make distutils happy
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '.'.join(platform.mac_ver()[0].split('.')[0:2])
import markdown

info_plist = os.environ['INFOPLIST_FILE']

if not os.path.exists(info_plist):
sys.exit(78) # configuration error

info = plistlib.readPlist(info_plist)

## increment version
version_hex = info['CFBundleVersion']
version_int = int(version_hex, 16)
new_version = hex(version_int + 1)[2:].upper() # uppercase, without 0x prefix
info['CFBundleVersion'] = new_version

## look for documentation and convert to HTML
srcroot = os.getenv('SRCROOT')
if srcroot is not None and os.path.exists(srcroot + "/Documentation.mdown"):
docfile = srcroot + "/Documentation.mdown"
doctext = codecs.open(docfile, mode = "r", encoding = "utf8").read()
md = markdown.Markdown(extensions = ['extra'], output_format = 'html4')
extended_description = md.convert(doctext)
info['QSPlugIn']['extendedDescription'] = extended_description

plistlib.writePlist(info, info_plist)
63 changes: 34 additions & 29 deletions Quicksilver/Tools/python-support/markdown/__init__.py
Expand Up @@ -10,7 +10,7 @@
import markdown
html = markdown.markdown(your_text_string)
See <http://www.freewisdom.org/projects/python-markdown/> for more
See <http://packages.python.org/Markdown/> for more
information and instructions on how to extend the functionality of
Python Markdown. Read that before you try modifying this file.
Expand All @@ -30,8 +30,8 @@
License: BSD (see LICENSE for details).
"""

version = "2.1.1"
version_info = (2,1,1, "final")
version = "2.2.0"
version_info = (2,2,0, "final")

import re
import codecs
Expand All @@ -55,15 +55,15 @@ class Markdown:
"""Convert Markdown to HTML."""

doc_tag = "div" # Element used to wrap document - later removed

option_defaults = {
'html_replacement_text' : '[HTML_REMOVED]',
'tab_length' : 4,
'enable_attributes' : True,
'smart_emphasis' : True,
'lazy_ol' : True,
}

output_formats = {
'html' : to_html_string,
'html4' : to_html_string,
Expand All @@ -73,9 +73,9 @@ class Markdown:
'xhtml5': to_xhtml_string,
}

ESCAPED_CHARS = ['\\', '`', '*', '_', '{', '}', '[', ']',
ESCAPED_CHARS = ['\\', '`', '*', '_', '{', '}', '[', ']',
'(', ')', '>', '#', '+', '-', '.', '!']

def __init__(self, *args, **kwargs):
"""
Creates a new Markdown instance.
Expand All @@ -86,7 +86,7 @@ def __init__(self, *args, **kwargs):
If they are of type string, the module mdx_name.py will be loaded.
If they are a subclass of markdown.Extension, they will be used
as-is.
* extension-configs: Configuration settingis for extensions.
* extension_configs: Configuration settingis for extensions.
* output_format: Format of output. Supported formats are:
* "xhtml1": Outputs XHTML 1.x. Default.
* "xhtml5": Outputs XHTML style tags of HTML 5
Expand Down Expand Up @@ -119,9 +119,13 @@ def __init__(self, *args, **kwargs):

# Loop through kwargs and assign defaults
for option, default in self.option_defaults.items():
setattr(self, option, kwargs.get(option, default))
setattr(self, option, kwargs.get(option, default))

self.safeMode = kwargs.get('safe_mode', False)
if self.safeMode and not kwargs.has_key('enable_attributes'):
# Disable attributes in safeMode when not explicitly set
self.enable_attributes = False

self.registeredExtensions = []
self.docType = ""
self.stripTopLevelTags = True
Expand All @@ -138,7 +142,7 @@ def __init__(self, *args, **kwargs):
def build_parser(self):
""" Build the parser from the various parts. """
self.preprocessors = build_preprocessors(self)
self.parser = build_block_parser(self)
self.parser = build_block_parser(self)
self.inlinePatterns = build_inlinepatterns(self)
self.treeprocessors = build_treeprocessors(self)
self.postprocessors = build_postprocessors(self)
Expand All @@ -161,7 +165,7 @@ def registerExtensions(self, extensions, configs):
if isinstance(ext, Extension):
# might raise NotImplementedError, but that's the extension author's problem
ext.extendMarkdown(self, globals())
else:
elif ext is not None:
raise ValueError('Extension "%s.%s" must be of type: "markdown.Extension".' \
% (ext.__class__.__module__, ext.__class__.__name__))

Expand All @@ -184,20 +188,21 @@ def build_extension(self, ext_name, configs = []):
pairs = [x.split("=") for x in ext_args.split(",")]
configs.update([(x.strip(), y.strip()) for (x, y) in pairs])

# Setup the module names
ext_module = 'markdown.extensions'
module_name_new_style = '.'.join([ext_module, ext_name])
module_name_old_style = '_'.join(['mdx', ext_name])
# Setup the module name
module_name = ext_name
if '.' not in ext_name:
module_name = '.'.join(['markdown.extensions', ext_name])

# Try loading the extension first from one place, then another
try: # New style (markdown.extensons.<extension>)
module = __import__(module_name_new_style, {}, {}, [ext_module])
module = __import__(module_name, {}, {}, [module_name.rpartition('.')[0]])
except ImportError:
module_name_old_style = '_'.join(['mdx', ext_name])
try: # Old style (mdx_<extension>)
module = __import__(module_name_old_style)
except ImportError:
logger.warn("Failed loading extension '%s' from '%s' or '%s'"
% (ext_name, module_name_new_style, module_name_old_style))
% (ext_name, module_name, module_name_old_style))
# Return None so we don't try to initiate none-existant extension
return None

Expand All @@ -208,7 +213,7 @@ def build_extension(self, ext_name, configs = []):
except AttributeError, e:
logger.warn("Failed to initiate extension '%s': %s" % (ext_name, e))
return None

def registerExtension(self, extension):
""" This gets called by the extension """
self.registeredExtensions.append(extension)
Expand Down Expand Up @@ -249,10 +254,10 @@ def convert(self, source):
1. A bunch of "preprocessors" munge the input text.
2. BlockParser() parses the high-level structural elements of the
pre-processed text into an ElementTree.
3. A bunch of "treeprocessors" are run against the ElementTree. One
such treeprocessor runs InlinePatterns against the ElementTree,
3. A bunch of "treeprocessors" are run against the ElementTree. One
such treeprocessor runs InlinePatterns against the ElementTree,
detecting inline markup.
4. Some post-processors are run against the text after the ElementTree
4. Some post-processors are run against the text after the ElementTree
has been serialized into text.
5. The output is written to a string.
Expand All @@ -261,7 +266,7 @@ def convert(self, source):
# Fixup the source text
if not source.strip():
return u"" # a blank unicode string

try:
source = unicode(source)
except UnicodeDecodeError, e:
Expand Down Expand Up @@ -353,8 +358,8 @@ def convertFile(self, input=None, output=None, encoding=None):
# Write to file or stdout
if output:
if isinstance(output, str):
output_file = codecs.open(output, "w",
encoding=encoding,
output_file = codecs.open(output, "w",
encoding=encoding,
errors="xmlcharrefreplace")
output_file.write(html)
output_file.close()
Expand Down Expand Up @@ -398,17 +403,17 @@ def markdown(text, *args, **kwargs):

def markdownFromFile(*args, **kwargs):
"""Read markdown code from a file and write it to a file or a stream.
This is a shortcut function which initializes an instance of Markdown,
and calls the convertFile method rather than convert.
Keyword arguments:
* input: a file name or readable object.
* output: a file name or writable object.
* encoding: Encoding of input and output.
* Any arguments accepted by the Markdown class.
"""
# For backward compatibility loop through positional args
pos = ['input', 'output', 'extensions', 'encoding']
Expand All @@ -421,7 +426,7 @@ def markdownFromFile(*args, **kwargs):
break

md = Markdown(**kwargs)
md.convertFile(kwargs.get('input', None),
md.convertFile(kwargs.get('input', None),
kwargs.get('output', None),
kwargs.get('encoding', None))

4 changes: 2 additions & 2 deletions Quicksilver/Tools/python-support/markdown/__main__.py
Expand Up @@ -20,11 +20,11 @@ def parse_options():
usage = """%prog [options] [INPUTFILE]
(STDIN is assumed if no INPUTFILE is given)"""
desc = "A Python implementation of John Gruber's Markdown. " \
"http://www.freewisdom.org/projects/python-markdown/"
"http://packages.python.org/Markdown/"
ver = "%%prog %s" % markdown.version

parser = optparse.OptionParser(usage=usage, description=desc, version=ver)
parser.add_option("-f", "--file", dest="filename", default=sys.stdout,
parser.add_option("-f", "--file", dest="filename", default=None,
help="Write output to OUTPUT_FILE. Defaults to STDOUT.",
metavar="OUTPUT_FILE")
parser.add_option("-e", "--encoding", dest="encoding",
Expand Down
9 changes: 5 additions & 4 deletions Quicksilver/Tools/python-support/markdown/blockparser.py
Expand Up @@ -89,9 +89,10 @@ def parseBlocks(self, parent, blocks):
"""
while blocks:
for processor in self.blockprocessors.values():
if processor.test(parent, blocks[0]):
processor.run(parent, blocks)
break
for processor in self.blockprocessors.values():
if processor.test(parent, blocks[0]):
if processor.run(parent, blocks) is not False:
# run returns True or None
break


4 changes: 3 additions & 1 deletion Quicksilver/Tools/python-support/markdown/blockprocessors.py
Expand Up @@ -306,6 +306,8 @@ class OListProcessor(BlockProcessor):
# 3. Item
# The ol tag will get starts="3" attribute
STARTSWITH = '1'
# List of allowed sibling tags.
SIBLING_TAGS = ['ol', 'ul']

def test(self, parent, block):
return bool(self.RE.match(block))
Expand All @@ -315,7 +317,7 @@ def run(self, parent, blocks):
items = self.get_items(blocks.pop(0))
sibling = self.lastChild(parent)

if sibling and sibling.tag in ['ol', 'ul']:
if sibling and sibling.tag in self.SIBLING_TAGS:
# Previous block was a list item, so set that as parent
lst = sibling
# make sure previous item is in a p- if the item has text, then it
Expand Down
Expand Up @@ -10,11 +10,11 @@
Contact: markdown@freewisdom.org
License: BSD (see ../../LICENSE for details)
License: BSD (see ../LICENSE.md for details)
Dependencies:
* [Python 2.4+](http://python.org)
* [Markdown 2.1+](http://www.freewisdom.org/projects/python-markdown/)
* [Markdown 2.1+](http://packages.python.org/Markdown/)
"""

Expand Down Expand Up @@ -120,8 +120,12 @@ def assign_attrs(self, elem, attrs):

class AttrListExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
# insert after 'inline' treeprocessor
md.treeprocessors.add('attr_list', AttrListTreeprocessor(md), '>inline')
if 'headerid' in md.treeprocessors.keys():
# insert after 'headerid' treeprocessor
md.treeprocessors.add('attr_list', AttrListTreeprocessor(md), '>headerid')
else:
# insert after 'inline' treeprocessor
md.treeprocessors.add('attr_list', AttrListTreeprocessor(md), '>inline')


def makeExtension(configs={}):
Expand Down
Expand Up @@ -8,14 +8,14 @@
Copyright 2006-2008 [Waylan Limberg](http://achinghead.com/).
Project website: <http://www.freewisdom.org/project/python-markdown/CodeHilite>
Project website: <http://packages.python.org/Markdown/extensions/code_hilite.html>
Contact: markdown@freewisdom.org
License: BSD (see ../docs/LICENSE for details)
License: BSD (see ../LICENSE.md for details)
Dependencies:
* [Python 2.3+](http://python.org/)
* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
* [Markdown 2.0+](http://packages.python.org/Markdown/)
* [Pygments](http://pygments.org/)
"""
Expand Down Expand Up @@ -138,7 +138,7 @@ def _getLang(self):
fl = lines.pop(0)

c = re.compile(r'''
(?:(?:::+)|(?P<shebang>[#]!)) # Shebang or 2 or more colons.
(?:(?:^::+)|(?P<shebang>^[#]!)) # Shebang or 2 or more colons.
(?P<path>(?:/\w+)*[/ ])? # Zero or 1 path
(?P<lang>[\w+-]*) # The language
''', re.VERBOSE)
Expand Down
Expand Up @@ -63,14 +63,14 @@
Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/).
Project website: <http://www.freewisdom.org/project/python-markdown/Fenced__Code__Blocks>
Project website: <http://packages.python.org/Markdown/extensions/fenced_code_blocks.html>
Contact: markdown@freewisdom.org
License: BSD (see ../docs/LICENSE for details)
Dependencies:
* [Python 2.4+](http://python.org)
* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
* [Markdown 2.0+](http://packages.python.org/Markdown/)
* [Pygments (optional)](http://pygments.org)
"""
Expand Down

0 comments on commit 057cd31

Please sign in to comment.