Coverage for C:\leo.repo\leo-editor\leo\plugins\writers\markdown.py : 27%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#@+leo-ver=5-thin
2#@+node:ekr.20140726091031.18073: * @file ../plugins/writers/markdown.py
3"""The @auto write code for markdown."""
4# pylint: disable=unused-import
5from leo.core import leoGlobals as g
6import leo.plugins.writers.basewriter as basewriter
7#@+others
8#@+node:ekr.20140726091031.18075: ** class MarkdownWriter
9class MarkdownWriter(basewriter.BaseWriter):
10 """The writer class for markdown files."""
11 # def __init__(self,c):
12 # super().__init__(c)
13 #@+others
14 #@+node:ekr.20140726091031.18076: *3* mdw.write
15 def write(self, root):
16 """Write all the *descendants* of an @auto-markdown node."""
17 # Fix bug 66: errors inhibited read @auto foo.md.
18 # New in Leo 5.5: Skip !headlines. Convert all others to '#' sections.
19 self.root = root
20 self.write_root(root)
21 for p in root.subtree():
22 if hasattr(self.at, 'force_sentinels'):
23 self.put_node_sentinel(p, '<!--', delim2='-->')
24 self.write_headline(p)
25 # Ensure that every section ends with exactly two newlines.
26 s = p.b.rstrip() + '\n\n'
27 lines = s.splitlines(False)
28 for s in lines:
29 if not g.isDirective(s):
30 self.put(s)
31 root.setVisited()
32 return True
33 #@+node:ekr.20141110223158.20: *3* mdw.write_headline
34 def write_headline(self, p):
35 """
36 Write or skip the headline.
38 New in Leo 5.5: Always write '#' sections.
39 This will cause perfect import to fail.
40 The alternatives are much worse.
41 """
42 level = p.level() - self.root.level()
43 assert level > 0, p.h
44 kind = p.h and p.h[0]
45 if kind == '!':
46 pass # The signal for a declaration node.
47 # elif kind in '=-':
48 # self.put(p.h)
49 # self.put(kind*max(4,len(p.h)))
50 else:
51 self.put('%s %s' % ('#'*level, p.h))
52 #@+node:ekr.20171230170642.1: *3* mdw.write_root
53 def write_root(self, root):
54 """Write the root @auto-org node."""
55 lines = [z for z in g.splitLines(root.b) if not g.isDirective(z)]
56 for s in lines:
57 self.put(s)
58 #@-others
59#@-others
60writer_dict = {
61 '@auto': ['@auto-md','@auto-markdown',],
62 'class': MarkdownWriter,
63 'extensions': ['.md',],
64}
65#@@language python
66#@@tabwidth -4
67#@-leo