# -*- coding: utf-8 -*- # lp4all: literate programming embedded in source code as wiki comments # Copyright (C) 2006 Jean-Marie Favreau, Frédéric Lehobey, David Mentré # and Thomas Petazzoni # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
NodeContentText and inherit classes constituted a wiki text structure.
class NodeContentText: def __init__(self, text = "", children = []): self.children = children self.text = text def __str__(self): return "[Node] %d children" % len(self.children)
First we defined node which cannot be contained in simple text. Simple text nodes are defined below.
class NodeContentList(NodeContentText): def __init__(self, text = "", level = 0, children = []): self.level = level NodeContentText.__init__(self, text = text, children = children)
A NodeContentNewLine produces a paragraph switch in result document.
class NodeContentNewLine(NodeContentText): def __init__(self): NodeContentText.__init__(self)
A NodeContentPre containts a pre-formatted text. Display result is a
monospace text (for example code source in comments)
class NodeContentPre(NodeContentText): def __init__(self, text = "", children = []): NodeContentText.__init__(self, text, children)
A NodeContentHR produces a paragraph switch with visible horizontal line.
class NodeContentHR(NodeContentText): def __init__(self): NodeContentText.__init__(self)
Other nodes are simple text nodes (see
simple parser definition for contents allowed
in a simple text). There children may be nodes,
except NodeContentNewLine and NodeContentPre and NodeContentList
A NodeContentLink is an extrernal link.
class NodeContentLink(NodeContentText): def __init__(self, uri = "", children = [], text = ""): if children == [] and text == "": text = uri NodeContentText.__init__(self, children = children, text = text) self.uri = uri
A NodeContentLabel is an anchor used by NodeContentRef to
create internal links between lp4all wiki pages.
class NodeContentLabel(NodeContentText): def __init__(self, label): NodeContentText.__init__(self, label)
A NodeContentRef is an internal link, target (ref) is defined by a
label (see NodeContentLabel definition).
class NodeContentRef(NodeContentLink): def __init__(self, ref = "", text = "", children = []): NodeContentLink.__init__(self, children = children, uri = ref, text = text)
A NodeContentStrong produces a strong text (text means text and
children texts)
class NodeContentStrong(NodeContentText): def __init__(self, text = "", children = []): NodeContentText.__init__(self, text, children)
A NodeContentTitle is a title (3 levels are allowed)
class NodeContentTitle(NodeContentText): def __init__(self, text = "", level = 0, children = []): self.level = level NodeContentText.__init__(self, text, children)
A NodeContentEmphasize produces an amphasize text (text means text
and # children texts)
class NodeContentEmphasize(NodeContentText): def __init__(self, text = "", children = []): NodeContentText.__init__(self, text, children)
A NodeContentCode produces an monospace text (text means text
and # children texts)
class NodeContentCode(NodeContentText): def __init__(self, text = "", children = []): NodeContentText.__init__(self, text, children)
A NodeContentCancel produces an cancel text (text means text
and # children texts)
class NodeContentCancel(NodeContentText): def __init__(self, text = "", children = []): NodeContentText.__init__(self, text, children)
Nodes: wiki tree structure
We defined here node structure, produced by lex/yacc parser on wiki comments.