|
From: <mi...@us...> - 2020-12-01 11:46:56
|
Revision: 8585
http://sourceforge.net/p/docutils/code/8585
Author: milde
Date: 2020-12-01 11:38:25 +0000 (Tue, 01 Dec 2020)
Log Message:
-----------
Add support for Markdown.
Provide a wrapper for the 3rd party `recommonmark`__ Markdown parser
already in use in Sphinx.
Add test cases for CommonMark parsing.
Also: Correct copyright note and set executable bit on two tests.
Fix small typo in test content.
__ https://pypi.org/project/recommonmark/
Modified Paths:
--------------
trunk/docutils/docutils/parsers/__init__.py
trunk/docutils/test/DocutilsTestSupport.py
trunk/docutils/test/test_parsers/test_rst/test_bullet_lists.py
trunk/docutils/test/test_parsers/test_rst/test_line_length_limit.py
trunk/docutils/test/test_parsers/test_rst/test_line_length_limit_default.py
trunk/docutils/test/test_parsers/test_rst/test_transitions.py
Added Paths:
-----------
trunk/docutils/docutils/parsers/recommonmark_wrapper.py
trunk/docutils/test/test_parsers/test_recommonmark/
trunk/docutils/test/test_parsers/test_recommonmark/__init__.py
trunk/docutils/test/test_parsers/test_recommonmark/test_block_quotes.py
trunk/docutils/test/test_parsers/test_recommonmark/test_bullet_lists.py
trunk/docutils/test/test_parsers/test_recommonmark/test_enumerated_lists.py
trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py
trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py
trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit.py
trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit_default.py
trunk/docutils/test/test_parsers/test_recommonmark/test_literal_blocks.py
trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py
trunk/docutils/test/test_parsers/test_recommonmark/test_paragraphs.py
trunk/docutils/test/test_parsers/test_recommonmark/test_section_headers.py
trunk/docutils/test/test_parsers/test_recommonmark/test_targets.py
trunk/docutils/test/test_parsers/test_recommonmark/test_transitions.py
trunk/docutils/tools/md2html5.py
trunk/docutils/tools/md2pseudoxml.py
trunk/docutils/tools/md2xml.py
Property Changed:
----------------
trunk/docutils/test/test_parsers/test_rst/test_line_length_limit.py
trunk/docutils/test/test_parsers/test_rst/test_line_length_limit_default.py
Modified: trunk/docutils/docutils/parsers/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/__init__.py 2020-12-01 10:53:38 UTC (rev 8584)
+++ trunk/docutils/docutils/parsers/__init__.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -11,11 +11,27 @@
import sys
from importlib import import_module
-from docutils import Component
+from docutils import Component, frontend
class Parser(Component):
+ settings_spec = (
+ 'Generic Parser Options',
+ None,
+ (('Disable the "raw" directives; replaced with a "warning" '
+ 'system message.',
+ ['--no-raw'],
+ {'action': 'store_false', 'default': 1, 'dest': 'raw_enabled',
+ 'validator': frontend.validate_boolean}),
+ ('Enable the "raw" directive. Enabled by default.',
+ ['--raw-enabled'],
+ {'action': 'store_true'}),
+ ('Maximal number of characters in an input line. Default 10 000.',
+ ['--line-length-limit'],
+ {'metavar': '<length>', 'type': 'int', 'default': 10000,
+ 'validator': frontend.validate_nonnegative_int}),
+ ))
component_type = 'parser'
config_section = 'parsers'
@@ -39,7 +55,10 @@
'restructuredtext': 'rst',
'rest': 'rst',
'restx': 'rst',
- 'rtxt': 'rst',}
+ 'rtxt': 'rst',
+ 'recommonmark': 'recommonmark_wrapper',
+ 'commonmark': 'recommonmark_wrapper',
+ 'markdown': 'recommonmark_wrapper'}
def get_parser_class(parser_name):
"""Return the Parser class from the `parser_name` module."""
Added: trunk/docutils/docutils/parsers/recommonmark_wrapper.py
===================================================================
--- trunk/docutils/docutils/parsers/recommonmark_wrapper.py (rev 0)
+++ trunk/docutils/docutils/parsers/recommonmark_wrapper.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+# -*- coding: utf8 -*-
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+#
+# Revision: $Revision$
+# Date: $Date$
+"""
+A parser for CommonMark MarkDown text using `recommonmark`__.
+
+__ https://pypi.org/project/recommonmark/
+"""
+
+import docutils.parsers
+from docutils import nodes
+
+try:
+ from recommonmark.parser import CommonMarkParser as _recommonmarkParser
+ _recommonmarkParser.supported = ('recommonmark', 'commonmark',
+ 'markdown', 'md')
+ with_recommonmark = True
+except ImportError as err:
+ with_recommonmark = False
+ class _recommonmarkParser(docutils.parsers.Parser):
+ def parse(self, inputstring, document):
+ error = document.reporter.warning(
+ 'Missing dependency: MarkDown input is processed by a 3rd '
+ 'party parser but Python did not find the required module '
+ '"recommonmark" (https://pypi.org/project/recommonmark/).')
+ document.append(error)
+
+class Parser(_recommonmarkParser):
+ config_section = 'recommonmark parser'
+ config_section_dependencies = ('parsers',)
+
+ def parse(self, inputstring, document):
+ """Use the upstream parser and clean up afterwards.
+ """
+ # check for exorbitantly long lines
+ for i, line in enumerate(inputstring.split('\n')):
+ if len(line) > document.settings.line_length_limit:
+ error = document.reporter.error(
+ 'Line %d exceeds the line-length-limit.'%(i+1))
+ document.append(error)
+ return
+
+ # pass to upstream parser
+ try:
+ _recommonmarkParser.parse(self, inputstring, document)
+ except Exception as err:
+ error = document.reporter.error('Parsing with "recommonmark" '
+ 'returned the error:\n%s'%err)
+ document.append(error)
+
+ # Post-Processing
+ # ---------------
+
+ # remove spurious empty lines
+ for node in document.traverse(nodes.TextElement):
+ node.children = [child for child in node.children
+ if not (isinstance(child, nodes.Text)
+ and str(child) == '\n')]
+
+ # add "code" class argument to inline literal (code spans)
+ for node in document.traverse(lambda n: isinstance(n,
+ (nodes.literal, nodes.literal_block))):
+ node['classes'].append('code')
+ # move "language" argument to classes
+ for node in document.traverse(nodes.literal_block):
+ if 'language' in node.attributes:
+ node['classes'].append(node['language'])
+ del node['language']
+
+ # remove empty target nodes
+ for node in document.traverse(nodes.target):
+ # remove empty name
+ node['names'] = [v for v in node['names'] if v]
+ if node.children or [v for v in node.attributes.values() if v]:
+ continue
+ node.parent.remove(node)
+
+ # replace raw nodes if raw is not allowed
+ if not document.settings.raw_enabled:
+ for node in document.traverse(nodes.raw):
+ warning = document.reporter.warning('Raw content disabled.')
+ node.parent.replace(node, warning)
+
+ # fix section nodes
+ for node in document.traverse(nodes.section):
+ # remove spurious IDs (first may be from duplicate name)
+ if len(node['ids']) > 1:
+ node['ids'].pop()
+ # fix section levels
+ section_level = self.get_section_level(node)
+ if node['level'] != section_level:
+ warning = document.reporter.warning(
+ 'Title level inconsistent. Changing from %d to %d.'
+ %(node['level'], section_level),
+ nodes.literal_block('', node[0].astext()))
+ node.insert(1, warning)
+ # remove non-standard attribute "level"
+ del node['level'] # TODO: store the original md level somewhere
+
+ def get_section_level(self, node):
+ level = 1
+ while True:
+ node = node.parent
+ if isinstance(node, nodes.document):
+ return level
+ if isinstance(node, nodes.section):
+ level += 1
Property changes on: trunk/docutils/docutils/parsers/recommonmark_wrapper.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Modified: trunk/docutils/test/DocutilsTestSupport.py
===================================================================
--- trunk/docutils/test/DocutilsTestSupport.py 2020-12-01 10:53:38 UTC (rev 8584)
+++ trunk/docutils/test/DocutilsTestSupport.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -47,6 +47,7 @@
import re
import inspect
import traceback
+import warnings
from pprint import pformat
testroot = os.path.abspath(os.path.dirname(__file__) or os.curdir)
@@ -63,7 +64,7 @@
from docutils import frontend, nodes, statemachine, utils
from docutils.utils import urischemes
from docutils.transforms import universal
- from docutils.parsers import rst
+ from docutils.parsers import rst, recommonmark_wrapper
from docutils.parsers.rst import states, tableparser, roles, languages
from docutils.readers import standalone, pep
from docutils.statemachine import StringList, string2lines
@@ -82,7 +83,6 @@
except:
import pdb
-
if sys.version_info >= (3, 0):
unicode = str # noqa
@@ -518,6 +518,38 @@
test_case_class = PEPParserTestCase
+class RecommonmarkParserTestCase(ParserTestCase):
+
+ """Recommonmark-specific parser test case."""
+
+ parser = recommonmark_wrapper.Parser()
+ """Parser shared by all RecommonmarkParserTestCases."""
+
+ option_parser = frontend.OptionParser(
+ components=(recommonmark_wrapper.Parser,))
+ settings = option_parser.get_default_values()
+ settings.report_level = 5
+ settings.halt_level = 5
+ settings.debug = package_unittest.debug
+
+class RecommonmarkParserTestSuite(ParserTestSuite):
+
+ """A collection of RecommonmarkParserTestCases."""
+
+ test_case_class = RecommonmarkParserTestCase
+ skip_message = 'skip "%s" (module `recommonmark` not found)'
+
+ def generateTests(self, dict, dictname='totest'):
+ if 'recommonmark' not in recommonmark_wrapper.Parser.supported:
+ if RecommonmarkParserTestSuite.skip_message: # warn (only once)
+ print(self.skip_message%self.id)
+ RecommonmarkParserTestSuite.skip_message = ''
+ return
+ # suppress UserWarnings from recommonmark parser
+ warnings.filterwarnings('ignore', message='Unsupported.*type')
+ ParserTestSuite.generateTests(self, dict, dictname='totest')
+
+
class GridTableParserTestCase(CustomTestCase):
parser = tableparser.GridTableParser()
@@ -756,7 +788,7 @@
class HtmlPublishPartsTestSuite(CustomTestSuite):
testcase_class = HtmlWriterPublishPartsTestCase
-
+
def generateTests(self, dict, dictname='totest'):
for name, (settings_overrides, cases) in dict.items():
settings = self.suite_settings.copy()
Added: trunk/docutils/test/test_parsers/test_recommonmark/__init__.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/__init__.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/__init__.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,15 @@
+import os
+import os.path
+import sys
+import unittest
+
+sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
+prev = ''
+while sys.path[0] != prev:
+ try:
+ import DocutilsTestSupport
+ break
+ except ImportError:
+ prev = sys.path[0]
+ sys.path[0] = os.path.dirname(prev)
+sys.path.pop(0)
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/__init__.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Added: trunk/docutils/test/test_parsers/test_recommonmark/test_block_quotes.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_block_quotes.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_block_quotes.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,110 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+
+"""
+Test for block quotes in CommonMark parsers
+Cf. the `CommonMark Specification <https://spec.commonmark.org/>`__
+"""
+
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite()
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['block_quotes'] = [
+["""\
+> block quote
+> line 2
+""",
+"""\
+<document source="test data">
+ <block_quote>
+ <paragraph>
+ block quote
+ line 2
+"""],
+["""\
+Line 1.
+
+ > Indented block quote.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Line 1.
+ <block_quote>
+ <paragraph>
+ Indented block quote.
+"""],
+["""\
+Line 1.
+Line 2.
+> Block quote, without blank line before.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Line 1.
+ Line 2.
+ <block_quote>
+ <paragraph>
+ Block quote, without blank line before.
+"""],
+["""\
+Line 1.
+Line 2.
+
+>Block quote,
+continuation line
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Line 1.
+ Line 2.
+ <block_quote>
+ <paragraph>
+ Block quote,
+ continuation line
+"""],
+["""\
+Here is a paragraph.
+
+> > Nested
+>
+> block quotes.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Here is a paragraph.
+ <block_quote>
+ <block_quote>
+ <paragraph>
+ Nested
+ <paragraph>
+ block quotes.
+"""],
+]
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_block_quotes.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Copied: trunk/docutils/test/test_parsers/test_recommonmark/test_bullet_lists.py (from rev 8584, trunk/docutils/test/test_parsers/test_rst/test_bullet_lists.py)
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_bullet_lists.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_bullet_lists.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,200 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+
+"""
+Test for bullet lists in CommonMark parsers.
+Cf. the `CommonMark Specification <https://spec.commonmark.org/>`__
+"""
+
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite()
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['bullet_lists'] = [
+["""\
+- item
+""",
+"""\
+<document source="test data">
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ item
+"""],
+["""\
+* item 1
+
+* item 2
+""",
+"""\
+<document source="test data">
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ item 1
+ <list_item>
+ <paragraph>
+ item 2
+"""],
+["""\
+No blank line between:
+
++ item 1
++ item 2
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ No blank line between:
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ item 1
+ <list_item>
+ <paragraph>
+ item 2
+"""],
+["""\
+- item 1, paragraph 1.
+
+ item 1, paragraph 2.
+
+- item 2
+""",
+"""\
+<document source="test data">
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ item 1, paragraph 1.
+ <paragraph>
+ item 1, paragraph 2.
+ <list_item>
+ <paragraph>
+ item 2
+"""],
+["""\
+- item 1, line 1
+ item 1, line 2
+- item 2
+""",
+"""\
+<document source="test data">
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ item 1, line 1
+ item 1, line 2
+ <list_item>
+ <paragraph>
+ item 2
+"""],
+["""\
+Different bullets start different lists:
+
+- item 1
+
++ item 1
+
+* no blank line
+- required between lists
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Different bullets start different lists:
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ item 1
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ item 1
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ no blank line
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ required between lists
+"""],
+["""\
+- item 1
+continuation of item 1
+""",
+"""\
+<document source="test data">
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ item 1
+ continuation of item 1
+"""],
+["""\
+-
+
+empty item above
+""",
+"""\
+<document source="test data">
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ empty item above
+"""],
+["""\
+-
+empty item above, no blank line
+""",
+"""\
+<document source="test data">
+ <bullet_list>
+ <list_item>
+ <paragraph>
+ empty item above, no blank line
+"""],
+[u"""\
+Unicode bullets are not supported by CommonMark.
+
+• BULLET
+
+‣ TRIANGULAR BULLET
+
+⁃ HYPHEN BULLET
+""",
+u"""\
+<document source="test data">
+ <paragraph>
+ Unicode bullets are not supported by CommonMark.
+ <paragraph>
+ • BULLET
+ <paragraph>
+ ‣ TRIANGULAR BULLET
+ <paragraph>
+ ⁃ HYPHEN BULLET
+"""],
+]
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Added: trunk/docutils/test/test_parsers/test_recommonmark/test_enumerated_lists.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_enumerated_lists.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_enumerated_lists.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,385 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+"""
+Test for enumerated lists in CommonMark parsers
+Cf. the `CommonMark Specification <https://spec.commonmark.org/>`__
+"""
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite()
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['enumerated_lists'] = [
+["""\
+1. Item one.
+
+2. Item two.
+
+3. Item three.
+""",
+"""\
+<document source="test data">
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item one.
+ <list_item>
+ <paragraph>
+ Item two.
+ <list_item>
+ <paragraph>
+ Item three.
+"""],
+["""\
+No blank lines betwen items:
+
+1. Item one.
+2. Item two.
+3. Item three.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ No blank lines betwen items:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item one.
+ <list_item>
+ <paragraph>
+ Item two.
+ <list_item>
+ <paragraph>
+ Item three.
+"""],
+["""\
+1.
+ Content may start at the next line
+ if it's indented at least 3 spaces.
+""",
+"""\
+<document source="test data">
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Content may start at the next line
+ if it's indented at least 3 spaces.
+"""],
+["""\
+1.
+empty item above, no blank line, no indent
+""",
+"""\
+<document source="test data">
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ empty item above, no blank line, no indent
+"""],
+["""\
+Items are auto-numbered.
+No check for consistency: Skipping item 3
+
+1. Item 1.
+2. Item 2.
+4. Item 4.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Items are auto-numbered.
+ No check for consistency: Skipping item 3
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item 1.
+ <list_item>
+ <paragraph>
+ Item 2.
+ <list_item>
+ <paragraph>
+ Item 4.
+"""],
+["""\
+No warning when starting with non-ordinal-1:
+
+0. Item zero.
+1. Item one.
+2. Item two.
+3. Item three.
+
+And again:
+
+2. Item two.
+3. Item three.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ No warning when starting with non-ordinal-1:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item zero.
+ <list_item>
+ <paragraph>
+ Item one.
+ <list_item>
+ <paragraph>
+ Item two.
+ <list_item>
+ <paragraph>
+ Item three.
+ <paragraph>
+ And again:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item two.
+ <list_item>
+ <paragraph>
+ Item three.
+"""],
+["""\
+1. Item one: line 1,
+ line 2.
+2. Item two: line 1,
+line 2.
+3. Item three: paragraph 1, line 1,
+ line 2.
+
+ Paragraph 2.
+""",
+"""\
+<document source="test data">
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item one: line 1,
+ line 2.
+ <list_item>
+ <paragraph>
+ Item two: line 1,
+ line 2.
+ <list_item>
+ <paragraph>
+ Item three: paragraph 1, line 1,
+ line 2.
+ <paragraph>
+ Paragraph 2.
+"""],
+["""\
+Supported enumeration sequences:
+
+1. Item 1.
+2. Item 2.
+
+1) Item 1)
+2) Item 2)
+
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Supported enumeration sequences:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item 1.
+ <list_item>
+ <paragraph>
+ Item 2.
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item 1)
+ <list_item>
+ <paragraph>
+ Item 2)
+"""],
+["""\
+Nested enumerated lists:
+
+1. Item 1
+
+ 1) Item 1.1
+ 2) Item 1.2
+ 3) Item 1.3
+
+2. Item 2
+
+ 1. Item 2.1
+
+ 1) Item 2.1.1
+ 2) Item 2.1.2
+ 3) Item 2.1.3
+
+ 2. Item 2.2
+
+ 3. Item 2.3
+
+3. Item 3.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Nested enumerated lists:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item 1
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item 1.1
+ <list_item>
+ <paragraph>
+ Item 1.2
+ <list_item>
+ <paragraph>
+ Item 1.3
+ <list_item>
+ <paragraph>
+ Item 2
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item 2.1
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item 2.1.1
+ <list_item>
+ <paragraph>
+ Item 2.1.2
+ <list_item>
+ <paragraph>
+ Item 2.1.3
+ <list_item>
+ <paragraph>
+ Item 2.2
+ <list_item>
+ <paragraph>
+ Item 2.3
+ <list_item>
+ <paragraph>
+ Item 3.
+"""],
+["""\
+1. Item one: line 1,
+ line 2.
+2. Item two: line 1,
+ line 2.
+3. Item three: paragraph 1, line 1,
+line 2.
+
+ Item three: paragraph 2.
+""",
+"""\
+<document source="test data">
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ Item one: line 1,
+ line 2.
+ <list_item>
+ <paragraph>
+ Item two: line 1,
+ line 2.
+ <list_item>
+ <paragraph>
+ Item three: paragraph 1, line 1,
+ line 2.
+ <paragraph>
+ Item three: paragraph 2.
+"""],
+["""\
+3-space indent, with a trailing space:
+
+1. \n\
+ list item 1
+
+3-space indent, no trailing space:
+
+1.
+ list item 1
+
+2-space indent, empty list item:
+
+1.
+ foo
+
+1-space indent, empty list item:
+
+1.
+ foo
+
+0-space indent, empty list item:
+
+1.
+foo
+
+No item content:
+
+1.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ 3-space indent, with a trailing space:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ list item 1
+ <paragraph>
+ 3-space indent, no trailing space:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ list item 1
+ <paragraph>
+ 2-space indent, empty list item:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ foo
+ <paragraph>
+ 1-space indent, empty list item:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ foo
+ <paragraph>
+ 0-space indent, empty list item:
+ <enumerated_list>
+ <list_item>
+ <paragraph>
+ foo
+ <paragraph>
+ No item content:
+ <enumerated_list>
+ <list_item>
+"""],
+]
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_enumerated_lists.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Added: trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,92 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# $Id$
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+"""
+Tests for HTML blocks in CommonMark parsers
+Cf. the `CommonMark Specification <https://spec.commonmark.org/>`__
+"""
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite()
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['html_blocks'] = [
+["""\
+A paragraph:
+
+<p>A HTML block.</p>
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph:
+ <raw format="html" xml:space="preserve">
+ <p>A HTML block.</p>
+"""],
+["""\
+<DIV CLASS="foo">
+
+*Markdown*
+
+</DIV>
+""",
+"""\
+<document source="test data">
+ <raw format="html" xml:space="preserve">
+ <DIV CLASS="foo">
+ <paragraph>
+ <emphasis>
+ Markdown
+ <raw format="html" xml:space="preserve">
+ </DIV>
+"""],
+["""\
+<a href="foo">
+*bar*
+</a>
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <raw format="html" xml:space="preserve">
+ <a href="foo">
+ <emphasis>
+ bar
+ <raw format="html" xml:space="preserve">
+ </a>
+"""],
+["""\
+<!-- foo -->*bar*
+*baz*
+""",
+"""\
+<document source="test data">
+ <raw format="html" xml:space="preserve">
+ <!-- foo -->*bar*
+ *baz*
+"""],
+]
+
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_html_blocks.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Added: trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,539 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+"""
+Tests for inline markup in CommonMark parsers
+Cf. the `CommonMark Specification <https://spec.commonmark.org/>`__
+"""
+
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite()
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['emphasis'] = [
+["""\
+*emphasis*
+_also emphasis_
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <emphasis>
+ emphasis
+ <emphasis>
+ also emphasis
+"""],
+[u"""\
+Partially*emphasised*word.
+""",
+u"""\
+<document source="test data">
+ <paragraph>
+ Partially
+ <emphasis>
+ emphasised
+ word.
+"""],
+["""\
+*emphasized sentence
+across lines*
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <emphasis>
+ emphasized sentence
+ across lines
+"""],
+["""\
+*no emphasis without closing asterisk
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ *
+ no emphasis without closing asterisk
+"""],
+[r"""
+No markup when \*escaped or unbalanced *.
+
+What about *this**?
+Unbalanced _markup__ is kept as-is without warning.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ No markup when \n\
+ *
+ escaped or unbalanced \n\
+ *
+ .
+ <paragraph>
+ What about \n\
+ <emphasis>
+ this
+ *
+ ?
+ Unbalanced \n\
+ <emphasis>
+ markup
+ _
+ is kept as-is without warning.
+"""],
+[r"""
+Emphasized asterisk: *\**
+
+Emphasized double asterisk: *\*\**
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Emphasized asterisk: \n\
+ <emphasis>
+ *
+ <paragraph>
+ Emphasized double asterisk: \n\
+ <emphasis>
+ *
+ *
+"""],
+]
+
+totest['strong'] = [
+["""\
+**strong**
+__also strong__
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <strong>
+ strong
+ <strong>
+ also strong
+"""],
+["""\
+Strong asterisk must be escaped **\\***
+
+Strong double asterisk: **\\*\\***
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Strong asterisk must be escaped \n\
+ <strong>
+ *
+ <paragraph>
+ Strong double asterisk: \n\
+ <strong>
+ *
+ *
+"""],
+["""\
+**not strong without closing asterisks
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ **
+ not strong without closing asterisks
+"""],
+]
+
+totest['literal'] = [
+["""\
+Inline `literals` are called `code spans` in CommonMark.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Inline \n\
+ <literal classes="code">
+ literals
+ are called \n\
+ <literal classes="code">
+ code spans
+ in CommonMark.
+"""],
+[r"""
+`\*literal`
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <literal classes="code">
+ \\*literal
+"""],
+[r"""
+``lite\ral``
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <literal classes="code">
+ lite\\ral
+"""],
+[r"""
+``literal\``
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <literal classes="code">
+ literal\\
+"""],
+[u"""\
+l'``literal`` and l\u2019``literal`` with apostrophe
+""",
+u"""\
+<document source="test data">
+ <paragraph>
+ l'
+ <literal classes="code">
+ literal
+ and l\u2019
+ <literal classes="code">
+ literal
+ with apostrophe
+"""],
+[u"""\
+quoted '``literal``', quoted "``literal``",
+quoted \u2018``literal``\u2019, quoted \u201c``literal``\u201d,
+quoted \xab``literal``\xbb
+""",
+u"""\
+<document source="test data">
+ <paragraph>
+ quoted '
+ <literal classes="code">
+ literal
+ ', quoted "
+ <literal classes="code">
+ literal
+ ",
+ quoted \u2018
+ <literal classes="code">
+ literal
+ \u2019, quoted \u201c
+ <literal classes="code">
+ literal
+ \u201d,
+ quoted \xab
+ <literal classes="code">
+ literal
+ \xbb
+"""],
+[u"""\
+``'literal'`` with quotes, ``"literal"`` with quotes,
+``\u2018literal\u2019`` with quotes, ``\u201cliteral\u201d`` with quotes,
+``\xabliteral\xbb`` with quotes
+""",
+u"""\
+<document source="test data">
+ <paragraph>
+ <literal classes="code">
+ 'literal'
+ with quotes, \n\
+ <literal classes="code">
+ "literal"
+ with quotes,
+ <literal classes="code">
+ \u2018literal\u2019
+ with quotes, \n\
+ <literal classes="code">
+ \u201cliteral\u201d
+ with quotes,
+ <literal classes="code">
+ \xabliteral\xbb
+ with quotes
+"""],
+[r"""
+``literal ``no literal
+
+No warning for `standalone TeX quotes' or other *unbalanced markup**.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <literal classes="code">
+ literal
+ no literal
+ <paragraph>
+ No warning for \n\
+ `
+ standalone TeX quotes\' or other \n\
+ <emphasis>
+ unbalanced markup
+ *
+ .
+"""],
+["""\
+``not literal without closing backquotes
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ ``
+ not literal without closing backquotes
+"""],
+[r"""
+Python ``list``s use square bracket syntax.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Python \n\
+ <literal classes="code">
+ list
+ s use square bracket syntax.
+"""],
+[r"""
+Blank after opening `` not allowed.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Blank after opening \n\
+ ``
+ not allowed.
+"""],
+[r"""
+no blank ``after closing``still ends a literal.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ no blank \n\
+ <literal classes="code">
+ after closing
+ still ends a literal.
+"""],
+]
+
+totest['references'] = [
+["""\
+[ref]
+
+[ref]: /uri
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <reference name="ref" refuri="/uri">
+ ref
+"""],
+["""\
+Inline image ![foo *bar*][foobar]
+in a paragraph.
+
+[FOOBAR]: train.jpg "train & tracks"
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Inline image \n\
+ <image alt="foo " title="train & tracks" uri="train.jpg">
+ in a paragraph.
+"""],
+["""\
+[phrase reference]
+
+[phrase reference]: /uri
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <reference name="phrase reference" refuri="/uri">
+ phrase reference
+"""],
+[u"""\
+No whitespace required around a[phrase reference].
+
+[phrase reference]: /uri
+""",
+u"""\
+<document source="test data">
+ <paragraph>
+ No whitespace required around a
+ <reference name="phrase reference" refuri="/uri">
+ phrase reference
+ .
+"""],
+["""\
+[phrase reference
+across lines]
+
+[phrase reference across lines]: /uri
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <reference name="phrase referenceacross lines" refuri="/uri">
+ phrase reference
+ across lines
+"""],
+]
+
+totest['appended_URIs'] = [
+["""\
+[anonymous reference](http://example.com)
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <reference name="anonymous reference" refuri="http://example.com">
+ anonymous reference
+"""],
+["""\
+Inline image  more text.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Inline image \n\
+ <image alt="a train" uri="train.jpg">
+ more text.
+"""],
+["""\
+Inline image  more text.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Inline image \n\
+ <image alt="foo" title="title" uri="/url">
+ more text.
+"""],
+["""\
+[URI must follow immediately]
+(http://example.com)
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ [
+ URI must follow immediately
+ ]
+ (http://example.com)
+"""],
+["""\
+Relative URIs' reference text can't be omitted:
+
+[reference](reference)
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Relative URIs' reference text can't be omitted:
+ <paragraph>
+ <reference name="reference" refuri="reference">
+ reference
+"""],
+]
+
+totest['standalone hyperlink'] = [
+["""\
+CommonMark calls standalone hyperlinks
+like <http://example.com> "autolinks".
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ CommonMark calls standalone hyperlinks
+ like \n\
+ <reference name="http://example.com" refuri="http://example.com">
+ http://example.com
+ "autolinks".
+"""],
+]
+
+totest['raw HTML'] = [
+["""\
+foo <a href="uri"> bar
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ foo \n\
+ <raw format="html" xml:space="preserve">
+ <a href="uri">
+ bar
+"""],
+["""\
+foo <br /> bar
+and <!-- this is an inline
+comment - with hyphen -->
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ foo \n\
+ <raw format="html" xml:space="preserve">
+ <br />
+ bar
+ and \n\
+ <raw format="html" xml:space="preserve">
+ <!-- this is an inline
+ comment - with hyphen -->
+"""],
+["""\
+Hard line breaks are not supported by Docutils.
+Not the soft line break preceded by two or more spaces, \n\
+nor the more visible alternative,\\
+a backslash before the line ending.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Hard line breaks are not supported by Docutils.
+ Not the soft line break preceded by two or more spaces,
+ nor the more visible alternative,
+ a backslash before the line ending.
+"""],
+]
+
+totest['markup recognition rules'] = [
+[r"""
+Character-level m*a***r**`k`_u_p
+works except for underline.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Character-level m
+ <emphasis>
+ a
+ <strong>
+ r
+ <literal classes="code">
+ k
+ _
+ u
+ _
+ p
+ works except for underline.
+"""],
+]
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_inline_markup.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Copied: trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit.py (from rev 8584, trunk/docutils/test/test_parsers/test_rst/test_line_length_limit_default.py)
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+
+"""
+Tests for inline markup in docutils/parsers/rst/states.py.
+Interpreted text tests are in a separate module, test_interpreted.py.
+"""
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite(
+ suite_settings={'line_length_limit': 80})
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['default'] = [
+["""\
+within the limit
+%s
+""" % ("x"*80),
+"""\
+<document source="test data">
+ <paragraph>
+ within the limit
+ %s
+""" % ("x"*80)],
+["""\
+above the limit
+%s
+""" % ("x"*81),
+"""\
+<document source="test data">
+ <system_message level="3" source="test data" type="ERROR">
+ <paragraph>
+ Line 2 exceeds the line-length-limit.
+"""],
+]
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Copied: trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit_default.py (from rev 8584, trunk/docutils/test/test_parsers/test_rst/test_line_length_limit_default.py)
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit_default.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit_default.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,58 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# $Id$
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+
+"""
+Tests for inline markup in docutils/parsers/rst/states.py.
+Interpreted text tests are in a separate module, test_interpreted.py.
+"""
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite()
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['default'] = [
+["""\
+within the limit
+%s
+""" % ("x"*10000),
+"""\
+<document source="test data">
+ <paragraph>
+ within the limit
+ %s
+""" % ("x"*10000)],
+["""\
+above the limit
+%s
+""" % ("x"*10001),
+"""\
+<document source="test data">
+ <system_message level="3" source="test data" type="ERROR">
+ <paragraph>
+ Line 2 exceeds the line-length-limit.
+"""],
+]
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_line_length_limit_default.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Added: trunk/docutils/test/test_parsers/test_recommonmark/test_literal_blocks.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_literal_blocks.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_literal_blocks.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,198 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# $Id$
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+"""
+Tests for literal blocks in CommonMark parsers
+Cf. the `CommonMark Specification <https://spec.commonmark.org/>`__
+"""
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite()
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['literal_blocks'] = [
+["""\
+A paragraph:
+
+ A literal block (indented code block).
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph:
+ <literal_block classes="code" xml:space="preserve">
+ A literal block (indented code block).
+"""],
+["""\
+A paragraph:
+~~~
+A literal block (fenced code block).
+~~~
+Another paragraph:
+
+ Another literal block.
+ With two blank lines following.
+
+
+A final paragraph.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph:
+ <literal_block classes="code" xml:space="preserve">
+ A literal block (fenced code block).
+ <paragraph>
+ Another paragraph:
+ <literal_block classes="code" xml:space="preserve">
+ Another literal block.
+ With two blank lines following.
+ <paragraph>
+ A final paragraph.
+"""],
+["""\
+A paragraph
+on more than
+one line.
+ No literal block
+ but paragraph continuation lines.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph
+ on more than
+ one line.
+ No literal block
+ but paragraph continuation lines.
+"""],
+["""\
+A paragraph:
+
+ A literal block.
+no blank line
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph:
+ <literal_block classes="code" xml:space="preserve">
+ A literal block.
+ <paragraph>
+ no blank line
+"""],
+["""\
+A paragraph:
+```
+ A fenced code block.
+```
+no blank lines.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph:
+ <literal_block classes="code" xml:space="preserve">
+ A fenced code block.
+ <paragraph>
+ no blank lines.
+"""],
+[r"""
+A paragraph:
+
+ Not a literal block because only indented 3 spaces.
+""",
+r"""<document source="test data">
+ <paragraph>
+ A paragraph:
+ <paragraph>
+ Not a literal block because only indented 3 spaces.
+"""],
+[r"""
+ A literal block.
+
+ Not a literal block.
+""",
+r"""<document source="test data">
+ <literal_block classes="code" xml:space="preserve">
+ A literal block.
+ <paragraph>
+ Not a literal block.
+"""],
+["""\
+A paragraph:
+
+ A wonky literal block.
+ Literal line 2.
+
+ Literal line 3.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph:
+ <literal_block classes="code" xml:space="preserve">
+ A wonky literal block.
+ Literal line 2.
+ \n\
+ Literal line 3.
+"""],
+["""\
+A paragraph:
+~~~
+ A fenced literal block.
+Literal line 2.
+
+ Literal line 3.
+~~~
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph:
+ <literal_block classes="code" xml:space="preserve">
+ A fenced literal block.
+ Literal line 2.
+ \n\
+ Literal line 3.
+"""],
+["""\
+A paragraph:
+~~~ ruby
+A literal block (fenced code block)
+with *info string*.
+~~~
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph:
+ <literal_block classes="code ruby" xml:space="preserve">
+ A literal block (fenced code block)
+ with *info string*.
+"""],
+]
+
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_literal_blocks.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Added: trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,100 @@
+#!/usr/bin/env python3
+# -*- coding: utf8 -*-
+# :Copyright: © 2020 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+
+"""
+Various tests for the recommonmark parser.
+"""
+
+from __future__ import absolute_import
+import sys
+import unittest
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport # must be imported before docutils
+from docutils import core, utils
+from docutils.core import publish_string
+from docutils.parsers import recommonmark_wrapper
+
+sample1 = """\
+Test unexpected section titles.
+
+* Title
+ =====
+ Paragraph.
+"""
+
+sample_with_html = """\
+A paragraph:
+
+<p>A HTML block.</p>
+
+Next paragraph.
+
+<script type="text/javascript">
+// some dangerous JavaScript
+
+Final paragraph.
+"""
+
+skip_msg = 'optional module "recommonmark" not found'
+
+class reCommonMarkParserTests(unittest.TestCase):
+
+ @unittest.skipUnless(recommonmark_wrapper.with_recommonmark, skip_msg)
+ def test_parsing_error(self):
+ output = publish_string(sample1, parser_name='recommonmark',
+ settings_overrides={'warning_stream': ''})
+
+ self.assertIn(b'Parsing with "recommonmark" returned the error:',
+ output)
+
+ @unittest.skipUnless(recommonmark_wrapper.with_recommonmark, skip_msg)
+ def test_raw_disabled(self):
+ output = publish_string(sample_with_html, parser_name='recommonmark',
+ settings_overrides={'warning_stream': '',
+ 'raw_enabled': False})
+ self.assertNotIn(b'<raw>', output)
+ self.assertIn(b'<system_message', output)
+ self.assertIn(b'Raw content disabled.', output)
+
+ @unittest.skipUnless(recommonmark_wrapper.with_recommonmark, skip_msg)
+ def test_raw_disabled_inline(self):
+ output = publish_string('foo <a href="uri">', parser_name='recommonmark',
+ settings_overrides={'warning_stream': '',
+ 'raw_enabled': False,
+ })
+ self.assertNotIn(b'<raw>', output)
+ self.assertIn(b'<system_message', output)
+ self.assertIn(b'Raw content disabled.', output)
+
+
+ @unittest.skipUnless(recommonmark_wrapper.with_recommonmark, skip_msg)
+ def test_raw_disabled(self):
+ output = publish_string(sample_with_html, parser_name='recommonmark',
+ settings_overrides={'warning_stream': '',
+ 'raw_enabled': False,
+ 'report_level': 3,
+ })
+ self.assertNotIn(b'<raw>', output)
+ self.assertNotIn(b'<system_message', output)
+
+ @unittest.skipIf(recommonmark_wrapper.with_recommonmark,
+ 'recommonmark_wrapper: parser found, fallback not used')
+ def test_fallback_parser(self):
+ output = publish_string(sample1, parser_name='recommonmark',
+ settings_overrides={'warning_stream': ''})
+ self.assertIn(b'Python did not find the required module "recommonmark"',
+ output)
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_misc.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Added: trunk/docutils/test/test_parsers/test_recommonmark/test_paragraphs.py
===================================================================
--- trunk/docutils/test/test_parsers/test_recommonmark/test_paragraphs.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_recommonmark/test_paragraphs.py 2020-12-01 11:38:25 UTC (rev 8585)
@@ -0,0 +1,81 @@
+#! /usr/bin/env python
+
+# $Id$
+# Author: David Goodger <go...@py...>
+# Copyright: This module has been placed in the public domain.
+
+"""
+Tests for states.py.
+"""
+from __future__ import absolute_import
+
+if __name__ == '__main__':
+ import __init__
+from test_parsers import DocutilsTestSupport
+
+
+def suite():
+ s = DocutilsTestSupport.RecommonmarkParserTestSuite()
+ s.generateTests(totest)
+ return s
+
+totest = {}
+
+totest['paragraphs'] = [
+["""\
+A paragraph.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A paragraph.
+"""],
+["""\
+Paragraph 1.
+
+Paragraph 2.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Paragraph 1.
+ <paragraph>
+ Paragraph 2.
+"""],
+["""\
+Line 1.
+Line 2.
+Line 3.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Line 1.
+ Line 2.
+ Line 3.
+"""],
+["""\
+Paragraph 1, Line 1.
+Line 2.
+Line 3.
+
+Paragraph 2, Line 1.
+Line 2.
+Line 3.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Paragraph 1, Line 1.
+ Line 2.
+ Line 3.
+ <paragraph>
+ Paragraph 2, Line 1.
+ Line 2.
+ Line 3.
+"""],
+]
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main(defaultTest='suite')
Property changes on: trunk/docutils/test/test_parsers/test_recommonmark/test_paragraphs.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Added: trunk/do...
[truncated message content] |