Added direct print of metadata.
This commit is contained in:
		
							parent
							
								
									7de248bcdc
								
							
						
					
					
						commit
						91bbbfc2b7
					
				
					 2 changed files with 16 additions and 2 deletions
				
			
		
							
								
								
									
										3
									
								
								test.md
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								test.md
									
									
									
									
									
								
							|  | @ -1,6 +1,7 @@ | |||
| --- | ||||
| title: 'Wooooo a title' | ||||
| subtitle: 'A subtitle' | ||||
| are_we_there_yet: False | ||||
| --- | ||||
| [#test-import.md]{} | ||||
| 
 | ||||
|  | @ -36,7 +37,7 @@ def bruh(no): | |||
| This should only be shown to cats the second time | ||||
| :::: | ||||
| 
 | ||||
| 
 | ||||
| # [$are_we_there_yet]{} | ||||
| 
 | ||||
|  | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										15
									
								
								transform.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								transform.py
									
									
									
									
									
								
							|  | @ -75,7 +75,7 @@ def transform(e: Element, c: Context) -> Element: # Returns next sibling element | |||
| 	## Shorthands | ||||
| 	if isinstance(e, Span) and len(e.content) == 1 and isinstance(e.content[0], Str): | ||||
| 		## Handle special command shorthand [!commandname]{} | ||||
| 		if re.match(r"^![\w.]+$", e.content[0].text): | ||||
| 		if re.match(r"^![\w]+$", e.content[0].text): | ||||
| 			e = InlineCommand(identifier=e.identifier, classes=e.classes, attributes={**e.attributes, "c": e.content[0].text[1:]}) | ||||
| 
 | ||||
| 		## Handle import [#path/file.md]{} | ||||
|  | @ -86,6 +86,19 @@ def transform(e: Element, c: Context) -> Element: # Returns next sibling element | |||
| 			importedDoc.walk(transform, c) | ||||
| 			return nullify(e) | ||||
| 
 | ||||
| 		## Handle metadata print [$something.something]{} | ||||
| 		elif re.match(r"^\$[\w.]+$", e.content[0].text): | ||||
| 			val = c.get_metadata(e.content[0].text[1:], False) | ||||
| 			if isinstance(val, MetaInlines): | ||||
| 				e = Span(*val.content) | ||||
| 				e = e.walk(transform, c) | ||||
| 			elif isinstance(val, MetaString): | ||||
| 				e = Span(Str(val.string)) | ||||
| 			elif isinstance(val, MetaBool): | ||||
| 				e = Span(Str(str(val.boolean))) | ||||
| 			else: | ||||
| 				raise ValueError(f"Cannot print value of metadatum {e.content[0].text[1:]}") | ||||
| 
 | ||||
| 	## Execute commands | ||||
| 	# panflute's walk transforms the children first, then the root element, so | ||||
| 	# the content of the element the command receives is already transformed. | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue