Remap include directives in a list of lines so they can be extracted to a different directory. Returns remapped lines. - lines - text to remap - baseDir - target directory - specDir - source directory
(lines, baseDir, specDir)
| 229 | |
| 230 | |
| 231 | def remapIncludes(lines, baseDir, specDir): |
| 232 | """Remap include directives in a list of lines so they can be extracted to a |
| 233 | different directory. |
| 234 | |
| 235 | Returns remapped lines. |
| 236 | |
| 237 | - lines - text to remap |
| 238 | - baseDir - target directory |
| 239 | - specDir - source directory""" |
| 240 | # This should be compiled only once |
| 241 | includePat = re.compile(r'^include::(?P<path>.*)\[\]') |
| 242 | |
| 243 | newLines = [] |
| 244 | for line in lines: |
| 245 | matches = includePat.search(line) |
| 246 | if matches is not None: |
| 247 | path = matches.group('path') |
| 248 | |
| 249 | if path[0] != '{': |
| 250 | # Relative path to include file from here |
| 251 | incPath = f'{specDir}/{path}' |
| 252 | # Remap to be relative to baseDir |
| 253 | newPath = os.path.relpath(incPath, baseDir) |
| 254 | newLine = f'include::{newPath}[]\n' |
| 255 | logDiag('remapIncludes: remapping', line, '->', newLine) |
| 256 | newLines.append(newLine) |
| 257 | else: |
| 258 | # An asciidoctor variable starts the path. |
| 259 | # This must be an absolute path, not needing to be rewritten. |
| 260 | newLines.append(line) |
| 261 | else: |
| 262 | newLines.append(line) |
| 263 | return newLines |
| 264 | |
| 265 | |
| 266 | def refPageShell(pageName, pageDesc, pageAliases, fp, head_content = None, sections=None, tail_content=None, man_section=3): |