Skip to content

Commit

Permalink
Fix DTD to be at least parsable.
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Jul 19, 2019
1 parent 25a5765 commit 7bbf755
Show file tree
Hide file tree
Showing 7 changed files with 689 additions and 504 deletions.
9 changes: 7 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
CHANGES
=======

3.8.1 (unreleased)
3.9.0 (unreleased)
------------------

- Nothing changed yet.
- Create a proper, parsable DTD. Add a test that verifies its validity.

- Updated `rml.dtd`.

- ``strandLabels`` does not support text content. That was accidentally
asserted due to bad schema inheritance.


3.8.0 (2019-06-24)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def read(*rnames):

setup (
name="z3c.rml",
version='3.8.1.dev0',
version='3.9.0',
author="Stephan Richter and the Zope Community",
author_email="zope-dev@zope.org",
description="An alternative implementation of RML",
Expand Down
10 changes: 5 additions & 5 deletions src/z3c/rml/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,11 +1082,6 @@ class Strands(PropertyCollection):

class IStrandLabelBase(ILabelBase):

_text = attr.TextNode(
title=u'Text',
description=u'The label text of the strand.',
required=False)

row = attr.Integer(
title=u'Row',
description=u'The row of the strand label',
Expand All @@ -1105,6 +1100,11 @@ class IStrandLabelBase(ILabelBase):
class IStrandLabel(IStrandLabelBase):
"""A label for a strand."""

_text = attr.TextNode(
title=u'Text',
description=u'The label text of the strand.',
required=False)

dR = attr.Float(
title=u'Radial Shift',
description=u'The radial shift of the label.',
Expand Down
38 changes: 27 additions & 11 deletions src/z3c/rml/dtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,34 @@
}


def generateElement(name, signature):
def generateElement(name, signature, seen):
if signature is None:
return ''
# Create the list of sub-elements.
subElementList = []
for occurence in signature.queryTaggedValue('directives', ()):
subElementList.append(
occurence.tag + occurence2Symbol.get(occurence.__class__, '')
)
# Determine whether we have #PCDATA first.
fields = zope.schema.getFieldsInOrder(signature)
for attrName, field in fields:
if isinstance(field, attr.TextNode):
subElementList.append('#PCDATA')
break
subElementList = ','.join(subElementList)
# Create the list of sub-elements.
occurence = '*'
for occurence in signature.queryTaggedValue('directives', ()):
if '#PCDATA' in subElementList:
subElementList.append(occurence.tag)
occurence = occurence2Symbol.get(occurence.__class__, '')
else:
subElementList.append(
occurence.tag +
occurence2Symbol.get(occurence.__class__, '')
)
subElementList = ' | '.join(subElementList)
if subElementList:
subElementList = ' (' + subElementList + ')'
if '#PCDATA' in subElementList:
subElementList += occurence
else:
subElementList = ' EMPTY'
text = '\n<!ELEMENT %s%s>' %(name, subElementList)
# Create a list of attributes for this element.
for attrName, field in fields:
Expand All @@ -50,7 +61,7 @@ def generateElement(name, signature):
continue
# Create the type
if isinstance(field, attr.Choice):
type = '(' + '|'.join(field.choices.keys()) + ')'
type = '(' + ' | '.join(field.choices.keys()) + ')'
else:
type = 'CDATA'
# Create required flag
Expand All @@ -61,14 +72,19 @@ def generateElement(name, signature):
# Put it all together
text += '\n<!ATTLIST %s %s %s %s>' %(name, attrName, type, required)
text += '\n'
# Walk through all sub-elements, creating th eDTD entries for them.
# DTD does not support redefinition of an element type or have context
# specific elements.
if name in seen:
text = '\n<!--' + text + '-->\n'
seen.append(name)
# Walk through all sub-elements, creating the DTD entries for them.
for occurence in signature.queryTaggedValue('directives', ()):
text += generateElement(occurence.tag, occurence.signature)
text += generateElement(occurence.tag, occurence.signature, seen)
return text


def generate(useWrapper=False):
text = generateElement('document', document.Document.signature)
text = generateElement('document', document.Document.signature, [])
if useWrapper:
text = '<!DOCTYPE RML [\n%s]>\n' %text
return text
Expand Down
Binary file modified src/z3c/rml/rml-reference.pdf
Binary file not shown.
Loading

0 comments on commit 7bbf755

Please sign in to comment.