I have started the process of converting the lengthy documentation for #334
<https://github.com/leo-editor/leo-editor/issues/334> to a .md file on
GitHub.
LeoDocs.leo now contains this tree:
@nosent importers.md
<< intro >>
@others
@language md
However, the user is responsible for generate markdown headers, as
described here
<https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#headers>.
This will quickly become a chore, especially when rearranging the tree.
The new @button make-md-headers script does this automatically. At
present, it does this only for the "nearest" @<file> x.md trees, using the
new p.nearest() generator. However, it would also be possible to
regenerate *all* .md trees, using another generator.
Anyway, the present driver code is:
def run(p1):
'''Run markup on all nearby trees.'''
def predicate(p):
return p.isAnyAtFileNode() and p.h.strip().endswith('.md')
for root in p1.nearest_roots(predicate):
for p in root.self_and_subtree():
markup(p, root)
And business end is:
pattern = re.compile(r'^(#+\s+)(.*)$')
def markup(p, root):
'''prepend p.b[0] with markdown section markup, if appriate.'''
# g.trace(p.h)
root_level = root.level()
lines = g.splitLines(p.b)
if len(lines) < 2: return
line0, line1 = lines[0], lines[1]
if (
not p.h.startswith('@md-ignore') and
not line0.isspace() and # A real first line.
not line0.startswith('@') and # Not a directive
line1.isspace() # the next line is blank
):
m = pattern.match(line0)
if m:
# g.trace('FOUND', repr(m.group(1)), repr(m.group(2)))
# Remove existing markup.
line0 = m.group(2) + '\n'
hashes = '#'*(p.level()-root_level+1)
lines[0] = '%s %s' % (hashes, line0)
# g.printList(lines)
s = ''.join(lines)
if p.b != s:
print('changed %s' % (p.h))
p.setDirty()
c.setChanged(True)
p.b = ''.join(lines)
As you can see, this is not undoable...
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.