Copy the value of latex fragments through the pipeline.
This commit is contained in:
		
							parent
							
								
									e2f9938437
								
							
						
					
					
						commit
						8695cf17c5
					
				| @ -6,18 +6,11 @@ use crate::config::Config; | ||||
| use crate::error::CustomError; | ||||
| use crate::intermediate::IComment; | ||||
| 
 | ||||
| use super::macros::rnoop; | ||||
| 
 | ||||
| #[derive(Debug, Serialize)] | ||||
| #[serde(tag = "type")] | ||||
| #[serde(rename = "comment")] | ||||
| pub(crate) struct RenderComment {} | ||||
| 
 | ||||
| impl RenderComment { | ||||
|     pub(crate) fn new( | ||||
|         _config: &Config, | ||||
|         _output_directory: &Path, | ||||
|         _output_file: &Path, | ||||
|         _comment: &IComment, | ||||
|     ) -> Result<RenderComment, CustomError> { | ||||
|         Ok(RenderComment {}) | ||||
|     } | ||||
| } | ||||
| rnoop!(RenderComment, IComment); | ||||
|  | ||||
| @ -6,18 +6,25 @@ use crate::config::Config; | ||||
| use crate::error::CustomError; | ||||
| use crate::intermediate::ILatexFragment; | ||||
| 
 | ||||
| use super::macros::render; | ||||
| 
 | ||||
| #[derive(Debug, Serialize)] | ||||
| #[serde(tag = "type")] | ||||
| #[serde(rename = "latex_fragment")] | ||||
| pub(crate) struct RenderLatexFragment {} | ||||
| 
 | ||||
| impl RenderLatexFragment { | ||||
|     pub(crate) fn new( | ||||
|         _config: &Config, | ||||
|         _output_directory: &Path, | ||||
|         _output_file: &Path, | ||||
|         _comment: &ILatexFragment, | ||||
|     ) -> Result<RenderLatexFragment, CustomError> { | ||||
|         Ok(RenderLatexFragment {}) | ||||
|     } | ||||
| pub(crate) struct RenderLatexFragment { | ||||
|     value: String, | ||||
| } | ||||
| 
 | ||||
| render!( | ||||
|     RenderLatexFragment, | ||||
|     ILatexFragment, | ||||
|     original, | ||||
|     _config, | ||||
|     _output_directory, | ||||
|     _output_file, | ||||
|     { | ||||
|         Ok(RenderLatexFragment { | ||||
|             value: original.value.clone(), | ||||
|         }) | ||||
|     } | ||||
| ); | ||||
|  | ||||
							
								
								
									
										43
									
								
								src/context/macros.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/context/macros.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| /// Write the implementation for the render ast node.
 | ||||
| ///
 | ||||
| /// This exists to make changing the type signature easier.
 | ||||
| macro_rules! render { | ||||
|     ($rstruct:ident, $istruct:ident, $original:ident, $config:ident, $output_directory:ident, $output_file:ident, $fnbody:tt) => { | ||||
|         impl $rstruct { | ||||
|             pub(crate) fn new( | ||||
|                 config: &Config, | ||||
|                 output_directory: &Path, | ||||
|                 output_file: &Path, | ||||
|                 original: &$istruct, | ||||
|             ) -> Result<$rstruct, CustomError> { | ||||
|                 let $original = original; | ||||
|                 let $config = config; | ||||
|                 let $output_directory = output_directory; | ||||
|                 let $output_file = output_file; | ||||
|                 $fnbody | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| pub(crate) use render; | ||||
| 
 | ||||
| /// Write the implementation for a render ast node that has no fields.
 | ||||
| ///
 | ||||
| /// This exists to make changing the type signature easier.
 | ||||
| macro_rules! rnoop { | ||||
|     ($rstruct:ident, $istruct:ident) => { | ||||
|         impl $rstruct { | ||||
|             pub(crate) fn new( | ||||
|                 _config: &Config, | ||||
|                 _output_directory: &Path, | ||||
|                 _output_file: &Path, | ||||
|                 _original: &$istruct, | ||||
|             ) -> Result<$rstruct, CustomError> { | ||||
|                 Ok($rstruct {}) | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| pub(crate) use rnoop; | ||||
| @ -32,6 +32,7 @@ mod keyword; | ||||
| mod latex_environment; | ||||
| mod latex_fragment; | ||||
| mod line_break; | ||||
| mod macros; | ||||
| mod object; | ||||
| mod org_macro; | ||||
| mod paragraph; | ||||
|  | ||||
| @ -1,5 +1,19 @@ | ||||
| use super::macros::inoop; | ||||
| use super::macros::intermediate; | ||||
| 
 | ||||
| use crate::error::CustomError; | ||||
| 
 | ||||
| inoop!(ILatexFragment, LatexFragment); | ||||
| #[derive(Debug, Clone)] | ||||
| pub(crate) struct ILatexFragment { | ||||
|     pub(crate) value: String, | ||||
| } | ||||
| 
 | ||||
| intermediate!(ILatexFragment, LatexFragment, original, _registry, { | ||||
|     let value: String = if original.value.starts_with("$$") && original.value.ends_with("$$") { | ||||
|         format!("\\[{}\\]", &original.value[2..(original.value.len() - 2)]) | ||||
|     } else if original.value.starts_with("$") && original.value.ends_with("$") { | ||||
|         format!("\\({}\\)", &original.value[1..(original.value.len() - 1)]) | ||||
|     } else { | ||||
|         original.value.to_owned() | ||||
|     }; | ||||
|     Ok(ILatexFragment { value }) | ||||
| }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander