Skip to content

Commit

Permalink
Merge pull request #68 from MetRonnie/patch
Browse files Browse the repository at this point in the history
Fix bug in `literal_sub_include`
  • Loading branch information
oliver-sanders authored Mar 14, 2022
2 parents 5b640e5 + 02c31a7 commit 0771401
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions cylc/sphinx_ext/literal_sub_include/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@
"""

from typing import TYPE_CHECKING

from cylc.sphinx_ext.literal_sub_include.directives import LiteralSubInclude

if TYPE_CHECKING:
from sphinx.application import Sphinx


__version__ = '1.0.0'


Expand Down
12 changes: 7 additions & 5 deletions cylc/sphinx_ext/literal_sub_include/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@
# -----------------------------------------------------------------------------

from functools import wraps
from typing import List

from docutils.parsers.rst import directives
from sphinx.directives.code import LiteralInclude, LiteralIncludeReader


def substitute(lines, items):
def substitute(lines: List[str], items: dict) -> None:
"""Substitute |strings| in the provided "lines" with values from "items".
Example:
>>> lines = ['foo |bar| baz']
>>> substitute(lines, {'bar': 'pub'})
>>> lines = ['foo |bar| baz', 'foo bar |baz|']
>>> substitute(lines, {'bar': 'pub', 'baz': 'qux'})
>>> lines
['foo pub baz']
['foo pub baz', 'foo bar qux']
"""
for ind, line in enumerate(lines):
for key, value in items.items():
lines[ind] = line.replace(f'|{key}|', value)
line = line.replace(f'|{key}|', value)
lines[ind] = line


def substitution_decorator(fcn):
Expand Down

0 comments on commit 0771401

Please sign in to comment.