summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-08-05 08:09:01 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-08-05 08:37:49 (GMT)
commita4917480cc989ce2cbaee79345149a7be22eccac (patch) (side-by-side diff)
treed1a1bd895e7d305cd894941ea37faebad039c354
parent1fb7bc5aefaebf830b969c418f7987f50f4187f7 (diff)
downloadwikitrans-a4917480cc989ce2cbaee79345149a7be22eccac.tar.gz
wikitrans-a4917480cc989ce2cbaee79345149a7be22eccac.tar.bz2
Implement <ref> and <references>
* WikiTrans/wikimarkup.py (BaseWikiMarkup.tags): Add 'ref' and 'references'. * WikiTrans/wikitoken.py (WikiTagNode): If the parser has the 'references' attribute, store each <ref> there. * WikiTrans/wikidump.py: Handle new tags. * WikiTrans/wiki2html.py (HtmlTagNode): Handle new tags. (HtmlWikiMarkup.references): New attribute * WikiTrans/wiki2texi.py (TexiTagNode): Handle new tags. * WikiTrans/wiki2text.py (TextTagNode): Handle new tags. (TextWikiMarkup.showrefs): Renamed from references (TextWikiMarkup.references): New attribute.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--WikiTrans/wiki2html.py21
-rw-r--r--WikiTrans/wiki2texi.py7
-rw-r--r--WikiTrans/wiki2text.py17
-rw-r--r--WikiTrans/wikidump.py8
-rw-r--r--WikiTrans/wikimarkup.py2
-rw-r--r--WikiTrans/wikitoken.py11
6 files changed, 59 insertions, 7 deletions
diff --git a/WikiTrans/wiki2html.py b/WikiTrans/wiki2html.py
index 81b918f..7c71602 100644
--- a/WikiTrans/wiki2html.py
+++ b/WikiTrans/wiki2html.py
@@ -145,2 +145,21 @@ class HtmlTagNode(WikiTagNode):
return '<pre><code>' + s + '</code></pre>' #FIXME
+ elif self.tag == 'ref':
+ n = self.idx+1
+ return '<sup id="cite_ref-%d" class="reference"><a name="cite_ref-%d" href=#cite_note-%d">%d</a></sup>' % (n,n,n,n)
+ elif self.tag == 'references':
+ s = '<div class="references">\n'
+ s += '<ol class="references">\n'
+ n = 0
+ for ref in self.parser.references:
+ n += 1
+ s += ('<li id="cite_note-%d">' + \
+ '<span class="mw-cite-backlink">' + \
+ '<b><a href="#cite_ref-%d">^</a></b>' + \
+ '</span>' + \
+ '<span class="reference-text">' + \
+ ref.content.format() + \
+ '</span>' + \
+ '</li>\n') % (n,n)
+ s += '</ol>\n</div>\n'
+ return s
else:
@@ -179,3 +198,3 @@ class HtmlWikiMarkup (WikiMarkup):
nested = 0
-
+ references = []
def __init__(self, *args, **kwargs):
diff --git a/WikiTrans/wiki2texi.py b/WikiTrans/wiki2texi.py
index 9a12d37..39c70c6 100644
--- a/WikiTrans/wiki2texi.py
+++ b/WikiTrans/wiki2texi.py
@@ -105,2 +105,8 @@ class TexiTagNode(WikiTagNode):
self.content.format()
+ elif self.tag == 'ref':
+ parser._print('@footnote{', escape=False);
+ self.content.format();
+ parser._print('}', escape=False)
+ elif self.tag == 'references':
+ pass
else:
@@ -343,2 +349,3 @@ class TexiWikiMarkup (WikiMarkup):
+
diff --git a/WikiTrans/wiki2text.py b/WikiTrans/wiki2text.py
index 35f1aff..dc2e003 100644
--- a/WikiTrans/wiki2text.py
+++ b/WikiTrans/wiki2text.py
@@ -106,3 +106,3 @@ class TextLinkNode(WikiSeqNode):
if ns == 'NS_IMAGE':
- if not self.parser.references:
+ if not self.parser.showrefs:
return ""
@@ -123,3 +123,3 @@ class TextLinkNode(WikiSeqNode):
tgt = self.parser.mktgt(arg)
- if self.parser.references:
+ if self.parser.showrefs:
return "%s (see %s) " % (text, tgt)
@@ -192,2 +192,8 @@ class TextTagNode(WikiTagNode):
self.parser.nested -= 1
+ elif self.tag == 'ref':
+ s = '[%d]' % (self.idx+1)
+ elif self.tag == 'references':
+ s = '\nReferences:\n'
+ for ref in self.parser.references:
+ s += ('[%d]. ' % (ref.idx+1)) + ref.content.format() + '\n'
else:
@@ -208,3 +214,3 @@ class TextWikiMarkup (WikiMarkup):
# Do not show references.
- references = False
+ showrefs = False
# Provide a minimum markup
@@ -214,2 +220,5 @@ class TextWikiMarkup (WikiMarkup):
num = 0
+
+ # Array of footnote references
+ references = []
@@ -220,3 +229,3 @@ class TextWikiMarkup (WikiMarkup):
if 'refs' in keywords:
- self.references = keywords['refs']
+ self.showrefs = keywords['refs']
if 'markup' in keywords:
diff --git a/WikiTrans/wikidump.py b/WikiTrans/wikidump.py
index 5b257f9..7457dfa 100644
--- a/WikiTrans/wikidump.py
+++ b/WikiTrans/wikidump.py
@@ -21,4 +21,12 @@ from WikiTrans.wikimarkup import WikiMarkup
+class DumpReferences(object):
+ idx = 0
+ def __len__(self):
+ return self.idx + 1
+ def append(self, obj):
+ self.idx += 1
+
class DumpWikiMarkup(WikiMarkup):
indent = None
+ references = DumpReferences()
def __init__(self, **kwarg):
diff --git a/WikiTrans/wikimarkup.py b/WikiTrans/wikimarkup.py
index af97063..0987da2 100644
--- a/WikiTrans/wikimarkup.py
+++ b/WikiTrans/wikimarkup.py
@@ -116,3 +116,3 @@ class BaseWikiMarkup(object):
- tags = [ 'code', 'nowiki', 'tt', 'div' ]
+ tags = [ 'code', 'nowiki', 'tt', 'div', 'ref', 'references' ]
diff --git a/WikiTrans/wikitoken.py b/WikiTrans/wikitoken.py
index 5606ecc..2238a66 100644
--- a/WikiTrans/wikitoken.py
+++ b/WikiTrans/wikitoken.py
@@ -63,2 +63,4 @@ class WikiContentNode(WikiNode):
content = None
+ def format(self):
+ pass
@jsonencoder
@@ -116,2 +118,8 @@ class WikiTagNode(WikiContentNode):
args = None
+ idx = None
+ def __init__(self, *args, **keywords):
+ super(WikiTagNode, self).__init__(*args, **keywords)
+ if self.type == 'TAG' and self.tag == 'ref' and hasattr(self.parser,'references'):
+ self.idx = len(self.parser.references)
+ self.parser.references.append(self)
@jsonencoder
@@ -122,3 +130,4 @@ class WikiTagNode(WikiContentNode):
'args': self.args.tab if self.args else None,
- 'content': self.content.jsonEncode()
+ 'content': self.content.jsonEncode() if self.content else None,
+ 'idx': self.idx
}

Return to:

Send suggestions and report system problems to the System administrator.