Thread: [Epydoc-commits] SF.net SVN: epydoc: [1155] trunk/epydoc/src/epydoc/markup/__init__.py
Brought to you by:
edloper
From: <ed...@us...> - 2006-04-04 02:23:07
|
Revision: 1155 Author: edloper Date: 2006-04-03 19:23:00 -0700 (Mon, 03 Apr 2006) ViewCVS: http://svn.sourceforge.net/epydoc/?rev=1155&view=rev Log Message: ----------- - Fixed bug in ConcatenatedDocstring that was causing it to return None for to_latex and to_plaintext Modified Paths: -------------- trunk/epydoc/src/epydoc/markup/__init__.py Modified: trunk/epydoc/src/epydoc/markup/__init__.py =================================================================== --- trunk/epydoc/src/epydoc/markup/__init__.py 2006-04-04 01:49:57 UTC (rev 1154) +++ trunk/epydoc/src/epydoc/markup/__init__.py 2006-04-04 02:23:00 UTC (rev 1155) @@ -313,11 +313,13 @@ latexstring = '' for doc in self._parsed_docstrings: latexstring += doc.to_latex(docstring_linker, **options) + return latexstring def to_plaintext(self, docstring_linker, **options): textstring = '' for doc in self._parsed_docstrings: textstring += doc.to_plaintext(docstring_linker, **options) + return textstring def index_terms(self): terms = [] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ed...@us...> - 2006-04-10 13:23:29
|
Revision: 1209 Author: edloper Date: 2006-04-10 06:23:24 -0700 (Mon, 10 Apr 2006) ViewCVS: http://svn.sourceforge.net/epydoc/?rev=1209&view=rev Log Message: ----------- - Added a markup language registry, which can be used by users to register support for new markup languages. Modified Paths: -------------- trunk/epydoc/src/epydoc/markup/__init__.py Modified: trunk/epydoc/src/epydoc/markup/__init__.py =================================================================== --- trunk/epydoc/src/epydoc/markup/__init__.py 2006-04-10 13:22:49 UTC (rev 1208) +++ trunk/epydoc/src/epydoc/markup/__init__.py 2006-04-10 13:23:24 UTC (rev 1209) @@ -77,6 +77,38 @@ ## Dispatcher ################################################## +_markup_language_registry = { + 'restructuredtext': 'epydoc.markup.restructuredtext', + 'epytext': 'epydoc.markup.epytext', + 'plaintext': 'epydoc.markup.plaintext', + 'javadoc': 'epydoc.markup.javadoc', + } + +def register_markup_language(name, parse_function): + """ + Register a new markup language named C{name}, which can be parsed + by the function C{parse_function}. + + @param name: The name of the markup language. C{name} should be a + simple identifier, such as C{'epytext'} or C{'restructuredtext'}. + Markup language names are case insensitive. + + @param parse_function: A function which can be used to parse the + markup language, and returns a L{ParsedDocstring}. It should + have the following signature: + + >>> def parse(s, errors): + ... 'returns a ParsedDocstring' + + Where: + - C{s} is the string to parse. (C{s} will be a unicode + string.) + - C{errors} is a list; any errors that are generated + during docstring parsing should be appended to this + list (as L{ParseError} objects). + """ + _markup_language_registry[name.lower()] = parse_function + MARKUP_LANGUAGES_USED = set() def parse(docstring, markup='plaintext', errors=None, **options): @@ -115,15 +147,29 @@ if not re.match(r'\w+', markup): _parse_warn('Bad markup language name %r. Treating ' 'docstrings as plaintext.' % markup) + import epydoc.markup.plaintext as plaintext return plaintext.parse_docstring(docstring, errors, **options) # Is the markup language supported? - try: exec('from epydoc.markup.%s import parse_docstring' % markup) - except ImportError: + if markup not in _markup_language_registry: _parse_warn('Unsupported markup language %r. Treating ' 'docstrings as plaintext.' % markup) + import epydoc.markup.plaintext as plaintext return plaintext.parse_docstring(docstring, errors, **options) + # Get the parse function. + parse_docstring = _markup_language_registry[markup] + + # If it's a string, then it names a function to import. + if isinstance(parse_docstring, basestring): + try: exec('from %s import parse_docstring' % parse_docstring) + except ImportError, e: + _parse_warn('Error importing %s for markup language %s: %s' % + (parse_docstring, markup, e)) + import epydoc.markup.plaintext as plaintext + return plaintext.parse_docstring(docstring, errors, **options) + _markup_language_registry[markup] = parse_docstring + # Keep track of which markup languages have been used so far. MARKUP_LANGUAGES_USED.add(markup) @@ -134,12 +180,14 @@ if epydoc.DEBUG: raise log.error('Internal error while parsing a docstring: %s; ' 'treating docstring as plaintext' % e) + import epydoc.markup.plaintext as plaintext return plaintext.parse_docstring(docstring, errors, **options) # Check for fatal errors. fatal_errors = [e for e in errors if e.is_fatal()] if fatal_errors and raise_on_error: raise fatal_errors[0] if fatal_errors: + import epydoc.markup.plaintext as plaintext return plaintext.parse_docstring(docstring, errors, **options) return parsed_docstring @@ -569,11 +617,3 @@ code.appendChild(doc.createTextNode(type(obj).__name__)) return ParsedEpytextDocstring(doc) -################################################## -## Sub-module Imports -################################################## -# By default, just import plaintext. That way we don't have to wait -# for other modules (esp restructuredtext) to load if we're not going -# to use them. - -import plaintext This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ed...@us...> - 2008-02-23 01:07:49
|
Revision: 1737 http://epydoc.svn.sourceforge.net/epydoc/?rev=1737&view=rev Author: edloper Date: 2008-02-22 17:07:47 -0800 (Fri, 22 Feb 2008) Log Message: ----------- Clarified a docstring Modified Paths: -------------- trunk/epydoc/src/epydoc/markup/__init__.py Modified: trunk/epydoc/src/epydoc/markup/__init__.py =================================================================== --- trunk/epydoc/src/epydoc/markup/__init__.py 2008-02-23 01:07:30 UTC (rev 1736) +++ trunk/epydoc/src/epydoc/markup/__init__.py 2008-02-23 01:07:47 UTC (rev 1737) @@ -466,7 +466,9 @@ should be linked to. @type label: C{string} or C{None} @param label: The label that should be used for the identifier, - if it's different from the name of the identifier. + if it's different from the name of the identifier. This + should be expressed in the target markup language -- e.g. + for latex, "_"s should be escaped. @rtype: C{string} @return: The translated crossreference link. """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ed...@us...> - 2008-02-23 20:10:27
|
Revision: 1762 http://epydoc.svn.sourceforge.net/epydoc/?rev=1762&view=rev Author: edloper Date: 2008-02-23 12:10:25 -0800 (Sat, 23 Feb 2008) Log Message: ----------- - DocstringLinker.url_for() is now an optional method Modified Paths: -------------- trunk/epydoc/src/epydoc/markup/__init__.py Modified: trunk/epydoc/src/epydoc/markup/__init__.py =================================================================== --- trunk/epydoc/src/epydoc/markup/__init__.py 2008-02-23 19:50:28 UTC (rev 1761) +++ trunk/epydoc/src/epydoc/markup/__init__.py 2008-02-23 20:10:25 UTC (rev 1762) @@ -453,7 +453,7 @@ @rtype: C{string} @return: The translated index term. """ - raise NotImplementedError, 'DocstringLinker.translate_indexterm()' + raise NotImplementedError('DocstringLinker.translate_indexterm()') def translate_identifier_xref(self, identifier, label=None): """ @@ -472,14 +472,15 @@ @rtype: C{string} @return: The translated crossreference link. """ - raise NotImplementedError, 'DocstringLinker.translate_xref()' + raise NotImplementedError('DocstringLinker.translate_xref()') def url_for(self, identifier): """ Given an identifier, return a URL pointing at that identifier. - This is used to create hyperlinks in dotgraphs. + This is used to create hyperlinks in dotgraphs. This method + is *optional* -- i.e., it may raise NotImplementedError """ - raise NotImplementedError, 'DocstringLinker.url_for()' + raise NotImplementedError('DocstringLinker.url_for()') ################################################## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |