Skip to content

Commit

Permalink
Correct db.with.attribute and allow floats
Browse files Browse the repository at this point in the history
The width attribute can hold any length that contains:
- a float with a unit whereas the float as one digit after the dot
- no zero length like 0UNIT or 0.0UNIT
- no leading zeros like 05UNIT
- no spaces around the value
  • Loading branch information
tomschr committed Dec 8, 2023
1 parent cc367d1 commit 84b142f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
12 changes: 8 additions & 4 deletions geekodoc/rng/2_5.2/geekodoc-v2.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -1127,15 +1127,19 @@ include "db52itsxi.rnc"

# Issue 103
# Validate the width attribute which consists of a number followed by a unit.
# Not allowed is only the number without the unit
#
# Not allowed is:
# - a number without the unit
# - a zero width, be it 0UNIT or 0.0UNIT. Allowed is 0.xUNIT whereas 9 >= x >= 1
# - a leading zero like 05UNIT
div {
db.width.attribute =
## Specifies the width of the element
## Only values with units are possible, single values are forbidden
## Allowed units are %, mm, cm, in, and *
## Only a float with a unit are possible, single floats are forbidden
## Allowed units are %, mm, cm, in, em, and *
attribute width {
xsd:string {
pattern = "([0-9]|[1-9][0-9]+)(%|mm|cm|in|\*)"
pattern = "(0\.[0-9]|[1-9][0-9]*(\.[0-9])?)(%|mm|cm|in|em|\*)"
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion tests/v2/bad/width-attr-103.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="geekodoc-v2-flat.rnc" type="application/relax-ng-compact-syntax"?>
<?xml-model href="/usr/share/xml/geekodoc/rng/geekodoc-latest-flat.rnc" type="application/relax-ng-compact-syntax"?>
<article version="5.1-subset GeekoDoc-2.0.0" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:db="http://docbook.org/ns/docbook"
Expand Down Expand Up @@ -39,4 +39,12 @@
</mediaobject>
</informalfigure>

<informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="image.png" width="03.5mm"/>
</imageobject>
</mediaobject>
</informalfigure>

</article>
34 changes: 31 additions & 3 deletions tests/v2/good/width-attr-103.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@
<informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="image.png" width="60%"/>
<imagedata fileref="image.png" width="9%"/>
</imageobject>
</mediaobject>
</informalfigure>
<informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="image.png" width="9%"/>
<imagedata fileref="image.png" width="9.5%"/>
</imageobject>
</mediaobject>
</informalfigure>
<informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="image.png" width="60%"/>
</imageobject>
</mediaobject>
</informalfigure>
Expand All @@ -29,6 +36,13 @@
</imageobject>
</mediaobject>
</informalfigure>
<informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="image.png" width="5.3in"/>
</imageobject>
</mediaobject>
</informalfigure>
<informalfigure>
<mediaobject>
<imageobject>
Expand All @@ -44,6 +58,13 @@
</imageobject>
</mediaobject>
</informalfigure>
<informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="image.png" width="5.7cm"/>
</imageobject>
</mediaobject>
</informalfigure>
<informalfigure>
<mediaobject>
<imageobject>
Expand All @@ -59,12 +80,19 @@
</imageobject>
</mediaobject>
</informalfigure>
<informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="image.png" width="5.2mm"/>
</imageobject>
</mediaobject>
</informalfigure>
<informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="image.png" width="120mm"/>
</imageobject>
</mediaobject>
</informalfigure>

</article>

0 comments on commit 84b142f

Please sign in to comment.