Skip to content

Commit

Permalink
fix: Sphinx generated incorrect type references for display
Browse files Browse the repository at this point in the history
When rendering a type reference link, the trailing backtick must be followed by
a non-word character; however the code generated array and union references that
followed this backtick directly with `[` or `)` respectively. This caused a lot
of warnings to be emitted by `sphinx-build`, and resulted in incorrect output.

This adds an escaped space (`\ `) after the backticks, which `sphinx-build`
correctly interprets as a non-word character, but results in no character being
emitted to the output - thus generating the desired output.
  • Loading branch information
RomainMuller committed Sep 17, 2018
1 parent 845cc48 commit 01343bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/jsii-pacmak/lib/targets/sphinx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ class SphinxDocsGenerator extends Generator {
switch (type.collection.kind) {
case spec.CollectionKind.Array:
result = {
ref: `${ref}[]`,
display: `${display}[]`
ref: `${ref}\\ []`,
display: `${display}\\ []`
};
break;
case spec.CollectionKind.Map:
Expand All @@ -551,7 +551,7 @@ class SphinxDocsGenerator extends Generator {
// Wrap a string between parenthesis if it contains " or "
function wrap(str: string): string {
if (str.indexOf(' or ') === -1) { return str; }
return `(${str})`;
return `(${str}\\ )`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ MyFirstStruct (interface)

.. py:attribute:: firstOptional
:type: string[] or undefined *(abstract)*
:type: string\ [] or undefined *(abstract)*


Number
Expand Down
26 changes: 13 additions & 13 deletions packages/jsii-pacmak/test/expected.jsii-calc/sphinx/jsii-calc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ AllTypes

.. py:attribute:: anyArrayProperty
:type: any[]
:type: any\ []


.. py:attribute:: anyMapProperty
Expand All @@ -363,7 +363,7 @@ AllTypes

.. py:attribute:: arrayProperty
:type: string[]
:type: string\ []


.. py:attribute:: booleanProperty
Expand Down Expand Up @@ -403,7 +403,7 @@ AllTypes

.. py:attribute:: unionArrayProperty
:type: (number or :py:class:`~jsii-calc.composition.CompositeOperation`)[]
:type: (number or :py:class:`~jsii-calc.composition.CompositeOperation`)\ []


.. py:attribute:: unionMapProperty
Expand All @@ -418,7 +418,7 @@ AllTypes

.. py:attribute:: unknownArrayProperty
:type: any[]
:type: any\ []


.. py:attribute:: unknownMapProperty
Expand Down Expand Up @@ -754,15 +754,15 @@ Calculator
A log of all operations.


:type: :py:class:`@scope/jsii-calc-lib.Value`[] *(readonly)*
:type: :py:class:`@scope/jsii-calc-lib.Value`\ [] *(readonly)*


.. py:attribute:: operationsMap
A map of per operation name of all operations performed.


:type: string => :py:class:`@scope/jsii-calc-lib.Value`[] *(readonly)*
:type: string => :py:class:`@scope/jsii-calc-lib.Value`\ [] *(readonly)*


.. py:attribute:: curr
Expand Down Expand Up @@ -962,7 +962,7 @@ DerivedStruct (interface)

.. py:attribute:: optionalArray
:type: string[] or undefined *(abstract)*
:type: string\ [] or undefined *(abstract)*


DoubleTrouble
Expand Down Expand Up @@ -2158,7 +2158,7 @@ ObjectRefsInCollections
:param values:
:type values: :py:class:`@scope/jsii-calc-lib.Value`[]
:type values: :py:class:`@scope/jsii-calc-lib.Value`\ []
:rtype: number
Expand Down Expand Up @@ -2601,7 +2601,7 @@ Sum
The parts to sum.
:type: :py:class:`@scope/jsii-calc-lib.Value`[]
:type: :py:class:`@scope/jsii-calc-lib.Value`\ []
SyncVirtualMethods
Expand Down Expand Up @@ -2981,13 +2981,13 @@ VariadicMethod
:param \*prefix: a prefix that will be use for all values returned by ``#asArray``.
:type \*prefix: number
.. py:method:: asArray(first, *others) -> number[]
.. py:method:: asArray(first, *others) -> number\ []
:param first: the first element of the array to be returned (after the ``prefix`` provided at construction time).
:type first: number
:param \*others: other elements to be included in the array.
:type \*others: number
:rtype: number[]
:rtype: number\ []
VirtualMethodPlayground
Expand Down Expand Up @@ -3120,15 +3120,15 @@ CompositeOperation
A set of postfixes to include in a decorated .toString().
:type: string[]
:type: string\ []
.. py:attribute:: decorationPrefixes
A set of prefixes to include in a decorated .toString().
:type: string[]
:type: string\ []
.. py:attribute:: stringStyle
Expand Down

0 comments on commit 01343bf

Please sign in to comment.