summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2015-07-20 11:14:56 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2015-07-20 11:16:38 (GMT)
commit64cf5fdb880815ff21652ddb74e48490dd2f56fe (patch) (side-by-side diff)
treee91d3946e4ad36a4c103d7224b6d6b4eaa7d38c0
parentc41c19ff0b19cbca7c850239bfa11295a674f520 (diff)
downloadwikitrans-64cf5fdb880815ff21652ddb74e48490dd2f56fe.tar.gz
wikitrans-64cf5fdb880815ff21652ddb74e48490dd2f56fe.tar.bz2
Fix parsing of headers. Add more tests.
* WikiTrans/wikimarkup.py (delim): Use [ \t] instead of \s. (parse0): Undo c41c19ff. * testdata/headings.html: Update. * testdata/nowiki-ind.html: New file. * testdata/nowiki-ind.wiki: New file. * testdata/nowiki-tag.html: New file. * testdata/nowiki-tag.wiki: New file. * testdata/nowiki.html: New file. * testdata/nowiki.wiki: New file. * tests/test.py: Add new files.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--WikiTrans/wikimarkup.py8
-rw-r--r--testdata/headings.html6
-rw-r--r--testdata/nowiki-ind.html5
-rw-r--r--testdata/nowiki-ind.wiki9
-rw-r--r--testdata/nowiki-tag.html1
-rw-r--r--testdata/nowiki-tag.wiki1
-rw-r--r--testdata/nowiki.html1
-rw-r--r--testdata/nowiki.wiki1
-rw-r--r--tests/test.py12
9 files changed, 36 insertions, 8 deletions
diff --git a/WikiTrans/wikimarkup.py b/WikiTrans/wikimarkup.py
index d56c664..2fad0af 100644
--- a/WikiTrans/wikimarkup.py
+++ b/WikiTrans/wikimarkup.py
@@ -86,7 +86,7 @@ class TagAttributes(object):
class BaseWikiMarkup(object):
- delim = re.compile("^==+\s*|\s*==+\s*$|(^----$)|^\\*+|^#+|^[;:]+|(\\[\\[)|\\[|(\\{\\{)|(\\]\\])|\\]|(\\}\\})|\\||(\\'\\'\\'?)|<")
+ delim = re.compile("^==+[ \t]*|[ \t]*==+[ \t]*$|(^----$)|^\\*+|^#+|^[;:]+|(\\[\\[)|\\[|(\\{\\{)|(\\]\\])|\\]|(\\}\\})|\\||(\\'\\'\\'?)|<")
otag = re.compile("<(?P<tag>[a-zA-Z0-9_]+)(?:\s+(?P<args>[^>]+))?\s*(?P<closed>/)?>")
ctag = re.compile("</(?P<tag>[a-zA-Z0-9_]+)\s*>")
refstart = re.compile("^https?://")
@@ -667,7 +667,8 @@ class BaseWikiMarkup(object):
if self.peektkn()['type'] == 'NL':
break
else:
- self.dprint(80, "LEAVE parse_header=%s", "None")
+ self.dprint(80, "LEAVE parse_header=%s, tok=%s",
+ "None", self.peektkn())
return None
else:
x = self.parse_inline(tok)
@@ -792,9 +793,6 @@ class BaseWikiMarkup(object):
return ret
def parse0(self):
- if self.tokind == 0:
- self.newline = True
- return self.parse_para()
tok = self.getkn()
self.dprint(80, "ENTER parse0(%s)", tok)
toktype = tok['type']
diff --git a/testdata/headings.html b/testdata/headings.html
index 0ec26ac..4dd1203 100644
--- a/testdata/headings.html
+++ b/testdata/headings.html
@@ -1,9 +1,9 @@
-<h2> Section headings </h2>
+<h2>Section headings</h2>
<p><i>Headings</i> organize your writing into
sections. The Wiki software can automatically
-generate a <a href="http://pl.wiktionary.org/wiki/table%20of%20contents">table of contents</a> from them.</p><h3> Subsection </h3>
-<p>Using more "equals" (=) signs creates a subsection.</p><h4> A smaller subsection </h4>
+generate a <a href="http://pl.wiktionary.org/wiki/table%20of%20contents">table of contents</a> from them.</p><h3>Subsection</h3>
+<p>Using more "equals" (=) signs creates a subsection.</p><h4>A smaller subsection</h4>
<p>Don't skip levels,
like from two to four equals signs.</p><p>Start with 2 equals signs not 1
diff --git a/testdata/nowiki-ind.html b/testdata/nowiki-ind.html
new file mode 100644
index 0000000..b2bd72c
--- a/dev/null
+++ b/testdata/nowiki-ind.html
@@ -0,0 +1,5 @@
+<p>Para</p><pre>
+ a
+ b
+ c
+</pre><p>para</p>
diff --git a/testdata/nowiki-ind.wiki b/testdata/nowiki-ind.wiki
new file mode 100644
index 0000000..9d315a0
--- a/dev/null
+++ b/testdata/nowiki-ind.wiki
@@ -0,0 +1,9 @@
+Para
+
+<nowiki>
+ a
+ b
+ c
+</nowiki>
+
+para
diff --git a/testdata/nowiki-tag.html b/testdata/nowiki-tag.html
new file mode 100644
index 0000000..58b96fc
--- a/dev/null
+++ b/testdata/nowiki-tag.html
@@ -0,0 +1 @@
+<p>A <tag></p> \ No newline at end of file
diff --git a/testdata/nowiki-tag.wiki b/testdata/nowiki-tag.wiki
new file mode 100644
index 0000000..9aca78b
--- a/dev/null
+++ b/testdata/nowiki-tag.wiki
@@ -0,0 +1 @@
+A <<nowiki/>tag>
diff --git a/testdata/nowiki.html b/testdata/nowiki.html
new file mode 100644
index 0000000..346d0c3
--- a/dev/null
+++ b/testdata/nowiki.html
@@ -0,0 +1 @@
+<p>#:version=1.0<i>rest</i> of line</p>
diff --git a/testdata/nowiki.wiki b/testdata/nowiki.wiki
new file mode 100644
index 0000000..6c7833c
--- a/dev/null
+++ b/testdata/nowiki.wiki
@@ -0,0 +1 @@
+<nowiki>#:version=1.0</nowiki>''rest'' of line
diff --git a/tests/test.py b/tests/test.py
index cde21bc..c54a717 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -80,6 +80,18 @@ class TestMarkupParserBasic (unittest.TestCase):
def test_itbold3(self):
self.assertTrue(self.__test('itbold3'))
pass
+
+ def test_nowiki(self):
+ self.assertTrue(self.__test('nowiki'))
+ pass
+
+ def test_nowiki_tag(self):
+ self.assertTrue(self.__test('nowiki-tag'))
+ pass
+
+ def test_nowiki_ind(self):
+ self.assertTrue(self.__test('nowiki-ind'))
+ pass
# def test_door(self):
# self.assertTrue(self.__test('door'))

Return to:

Send suggestions and report system problems to the System administrator.