diff --git a/assets/css/index.css b/assets/css/index.css index b72bb84..40e9d29 100644 --- a/assets/css/index.css +++ b/assets/css/index.css @@ -526,6 +526,41 @@ html { scrollbar-gutter: stable; } +/* Railroad diagrams */ +svg.railroad-diagram { + background-color:rgba(0,0,0,0); +} + +svg.railroad-diagram path { + stroke-width:3; + stroke:black; + fill: rgba(0,0,0,0); +} + +svg.railroad-diagram text { + font:bold 14px monospace; + text-anchor:middle; +} + +svg.railroad-diagram text.label{ + text-anchor:start; +} + +svg.railroad-diagram text.comment{ + font:italic 12px monospace; +} + +svg.railroad-diagram rect{ + stroke-width:3; + stroke: black; + fill: hsl(120,100%,90%); +} +svg.railroad-diagram rect.group-box { + stroke: gray; + stroke-dasharray: 10 5; + fill: none; +} + /* Chroma syntax highlighting /* Background */ .bg { diff --git a/build/stack/syntax.py b/build/stack/syntax.py index 5c70b70..763d518 100644 --- a/build/stack/syntax.py +++ b/build/stack/syntax.py @@ -82,26 +82,8 @@ def syntax(self, **kwargs) -> str: def diagram(self) -> DiagramItem: if self._type == ArgumentType.COMMAND: - s = [] - i = 0 - optionals = [] - while i < len(self._arguments): - arg = self._arguments[i].diagram() - if type(arg) is Optional: - optionals.append(arg) - else: - if len(optionals) != 0: - optionals.sort(key=lambda x: x.width) - s += optionals - optionals = [] - s.append(arg) - i += 1 - if len(optionals) != 0: - optionals.sort(key=lambda x: x.width) - s += optionals - self._stack.append(Sequence(Terminal(self._display))) - for arg in s: + for arg in [arg.diagram() for arg in self._arguments]: if type(arg) is not Sequence: items = [arg] else: @@ -176,7 +158,7 @@ def diagram(self) -> str: d.writeSvg(s.write) # Hack: strip out the 'width' and 'height' attrs from the svg s = s.getvalue() - for attr in ['width', 'height']: + for attr in ['height']: a = f'{attr}="' x = s.find(a) y = s.find('"', x + len(a)) diff --git a/layouts/commands/single.html b/layouts/commands/single.html index 7ada885..d552f88 100644 --- a/layouts/commands/single.html +++ b/layouts/commands/single.html @@ -1,6 +1,7 @@ {{ define "head" }} + {{ end }} {{ define "main" }} @@ -32,10 +33,27 @@
- {{- $syntax -}} -+
+ {{- $syntax -}} ++