diff --git a/coursebuilder/__main__.py b/coursebuilder/__main__.py index e91f791..3f355b4 100644 --- a/coursebuilder/__main__.py +++ b/coursebuilder/__main__.py @@ -23,7 +23,7 @@ class MarkdownGenerator: pass - def generate_markdown(self,ti,pagebreak = False,title = None) -> str: + def generate_markdown(self,ti,pagebreak = False,title = False) -> str: line_length = 128 column_ratio= 0.28 @@ -32,7 +32,7 @@ class MarkdownGenerator: d_len = line_length-h_len if title: - print('#',title,'\n') + print('#',ti[0][1],'\n') print(''.join(['+',"".ljust(h_len,'-'),'+',"".ljust(d_len,'-'),'+'])) @@ -136,7 +136,7 @@ class CourseBuilder: return [k,', '.join(parts)] - def process(self,meta,fields = [],lang = 'de',pagebreak = False): + def process(self,meta,fields = [],lang = 'de',pagebreak = False,createTitle=False): table_items = [] @@ -148,7 +148,7 @@ class CourseBuilder: case 'multikey': table_items.append(self.process_multikey(meta,field,lang)) mdg = MarkdownGenerator() - mdg.generate_markdown(table_items,pagebreak) + mdg.generate_markdown(table_items,pagebreak,createTitle) def main(): @@ -161,6 +161,7 @@ def main(): parser.add_argument('-f','--fields',help="Fields to be used, the table will be build accordingly",action="extend", nargs="+", type=str) parser.add_argument('-s','--schema',help="using provided schema") parser.add_argument('-p','--pagebreak',action="store_true",help="add a pagebreak after each module") + parser.add_argument('-t','--title',action="store_true",help="take first value in list as title") # get arguments args = parser.parse_args() @@ -184,7 +185,7 @@ def main(): for m in args.meta: with open(m) as fm: - cb.process(yaml.load(fm,Loader=yaml.Loader),fields=actual_fields,lang=args.lang,pagebreak=args.pagebreak) + cb.process(yaml.load(fm,Loader=yaml.Loader),fields=actual_fields,lang=args.lang,pagebreak=args.pagebreak,createTitle=args.title) else: parser.print_help() diff --git a/test/simple/mod.test.yaml b/test/simple/mod.test.yaml index e5bb6f7..d538f18 100644 --- a/test/simple/mod.test.yaml +++ b/test/simple/mod.test.yaml @@ -12,6 +12,19 @@ name: # content: + en: | + 1. Dog + 1. German Shepherd + 2. Belgian Shepherd + 1. Malinois + 2. Groenendael + 4. Tervuren + 2. Cat + 1. Siberian + 2. Siamese + + +content-alt: en: | 1. Dog @@ -31,3 +44,77 @@ content: 2. Siamese + + +content-blah: + en: | + 1. Blah + + 2. Blub + + 1. Blah + + 1. Blub + + 1. Blah + + 1. Blub + + 1. Blah + + 1. Blub + + 1. Blah + + 1. Blub + + 3. Blah + + 4. Blub + + 5. Blah + + 6. Blah and Blub + + 1. Blah + + 1. Blub + + 7. Blah and Blub + + - Blah + + - Blub + + - Blah + + - Blub + + 8. Blub and Blah + + - Blah + + - Blub + + - Blah + + - Blub + + - Blah + + - Blub + + - Blah + + - Blub + + 9. Blah, Blub and Blub + + - Blah + + - Blub + + - Blah + + - Blub +