Skip to content

Commit

Permalink
dedent_subsections logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shaedrich authored Jun 6, 2024
1 parent 54918e2 commit de5fc30
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/superfences_ponylang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from mkdocs.utils.templates import TemplateContext

import os
import re

def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
if "snippet" in attrs: #options
Expand All @@ -36,8 +37,23 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
elif i == int(lineNum):
lines.append(line)
#source = str(lines)

if 'dedent_subsections' in attrs and attrs.get('dedent_subsections'):
p = re.compile('^\s+')
indents = []
for line in lines:
m = p.match(line)
if m is None:
indents.append(0)
else:
indents.append(m.span()[1])
indent = min(indents)
if indent > 0:
for i, line in enumerate(lines):
lines[i] = line[indent:None]

source = '\n'.join(lines)
source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(c) + str(options) + str(attrs) + str(classes) + str(kwargs)
#source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(c) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
Expand Down

0 comments on commit de5fc30

Please sign in to comment.