feat: add \git escape to double-quoted filenames in inclusion
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This allows you to include a file extracted from a specific git commit. Still needs documentation.
This commit is contained in:
parent
7027ccc98d
commit
921719c165
8 changed files with 586 additions and 1 deletions
|
@ -16,6 +16,8 @@ from mkdocs_simple_plugin.plugin import SimplePlugin, StreamExtract
|
|||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import yaml
|
||||
|
||||
|
||||
|
@ -109,11 +111,21 @@ is checked for `{! ... !}`.
|
|||
utils.log.error(errmsg)
|
||||
raise EOFError(errmsg)
|
||||
filename = body_match['fn']
|
||||
gitextract = False
|
||||
if doublequoted:
|
||||
if filename[:5] == r'\git ':
|
||||
gitextract = True
|
||||
filename = filename[5:]
|
||||
filename = (filename.encode('latin-1', 'backslashreplace')
|
||||
.decode('unicode-escape'))
|
||||
include_path = self.include_root + '/' + filename
|
||||
print(f"Including |{include_path}|")
|
||||
if gitextract:
|
||||
(write_handle, include_path) = tempfile.mkstemp()
|
||||
utils.log.info(
|
||||
f"semiliterate: extracting {filename} to {include_path}")
|
||||
contents = subprocess.check_output(['git', 'show', filename])
|
||||
os.write(write_handle, contents)
|
||||
os.close(write_handle)
|
||||
new_root = re.match(r'(.*)/', include_path)[1]
|
||||
try:
|
||||
include_parameters = yaml.safe_load(body_match['yml'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue