Coverage for src/lcdoc/mkdocs/lp/plugs/markmap/__init__.py: 100.00%

Shortcuts 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

7 statements  

1# page_assets = { 

2# 'header': { 

3# 'script': [ 

4# 'https://unpkg.com/d3@6.7.0/dist/d3.min.js', 

5# 'https://unpkg.com/markmap-lib@0.11.5/dist/browser/index.min.js', 

6# 'https://unpkg.com/markmap-view@0.2.6/dist/index.min.js', 

7# ] 

8# } 

9# } 

10 

11page_assets = { 

12 'mode': 'd3', 

13 'header': [ 

14 '//unpkg.com/markmap-lib@0.11.5/dist/browser/index.min.js', 

15 '//unpkg.com/markmap-view@0.2.6/dist/index.min.js', 

16 ], 

17} 

18 

19 

20R = ''' 

21<svg id="%(id)s" style="width: %(width)s; height: %(height)s"></svg> 

22''' 

23 

24JSF = ''' 

25 

26<script> 

27function do_%(id)s () { 

28 const md=`%(md)s` 

29 const transformer = new markmap.Transformer(); 

30 const {root, features} = transformer.transform(md.replaceAll('X_R', '`')); 

31 const { styles, scripts } = transformer.getUsedAssets(features); 

32 

33 if (styles) markmap.loadCSS(styles); 

34 if (scripts) markmap.loadJS(scripts, { getMarkmap: () => markmap }); 

35 markmap.Markmap.create('#%(id)s' , {}, root); 

36} 

37do_%(id)s () 

38 

39</script> 

40 

41 

42 

43''' 

44 

45 

46def run(cmd, kw): lp|features/lp/plugs/markmap/index.md

47 ctx = { 

48 'md': cmd.replace('`', 'X_R'), 

49 'id': kw['id'], 

50 'width': kw.get('width', '100%'), 

51 'height': kw.get('height', '100%'), 

52 } 

53 lpjs = JSF % ctx lp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/markmap/index.md

54 return {'res': R % ctx, 'formatted': True, 'footer': lpjs} lp|features/lp/plugs/markmap/index.mdlp|features/lp/plugs/markmap/index.md