diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Cargo.toml | 49 | ||||
| -rw-r--r-- | document_tree/Cargo.toml | 19 | ||||
| -rw-r--r-- | document_tree/src/attribute_types.rs (renamed from src/document_tree/attribute_types.rs) | 4 | ||||
| -rw-r--r-- | document_tree/src/element_categories.rs (renamed from src/document_tree/element_categories.rs) | 12 | ||||
| -rw-r--r-- | document_tree/src/element_types.rs (renamed from src/document_tree/element_types.rs) | 0 | ||||
| -rw-r--r-- | document_tree/src/elements.rs (renamed from src/document_tree/elements.rs) | 6 | ||||
| -rw-r--r-- | document_tree/src/extra_attributes.rs (renamed from src/document_tree/extra_attributes.rs) | 10 | ||||
| -rw-r--r-- | document_tree/src/lib.rs | 43 | ||||
| -rw-r--r-- | document_tree/src/macro_util.rs (renamed from src/document_tree/macro_util.rs) | 4 | ||||
| -rw-r--r-- | document_tree/src/url.rs (renamed from src/url.rs) | 0 | ||||
| -rw-r--r-- | parser/Cargo.toml | 18 | ||||
| -rw-r--r-- | parser/src/conversion.rs (renamed from src/parser/conversion.rs) | 77 | ||||
| -rw-r--r-- | parser/src/conversion/block.rs (renamed from src/parser/conversion/block.rs) | 4 | ||||
| -rw-r--r-- | parser/src/conversion/inline.rs (renamed from src/parser/conversion/inline.rs) | 7 | ||||
| -rw-r--r-- | parser/src/conversion/tests.rs | 65 | ||||
| -rw-r--r-- | parser/src/lib.rs (renamed from src/parser.rs) | 2 | ||||
| -rw-r--r-- | parser/src/pair_ext_parse.rs (renamed from src/parser/pair_ext_parse.rs) | 0 | ||||
| -rw-r--r-- | parser/src/pest_rst.rs (renamed from src/parser/pest_rst.rs) | 0 | ||||
| -rw-r--r-- | parser/src/rst.pest (renamed from src/rst.pest) | 0 | ||||
| -rw-r--r-- | parser/src/simplify.rs (renamed from src/parser/simplify.rs) | 6 | ||||
| -rw-r--r-- | parser/src/tests.rs (renamed from src/parser/tests.rs) | 3 | ||||
| -rw-r--r-- | parser/src/token.rs (renamed from src/parser/token.rs) | 0 | ||||
| -rw-r--r-- | renderer/Cargo.toml | 23 | ||||
| -rw-r--r-- | renderer/src/html.rs (renamed from src/renderer/html.rs) | 13 | ||||
| -rw-r--r-- | renderer/src/html/tests.rs (renamed from src/renderer/html_tests.rs) | 21 | ||||
| -rw-r--r-- | renderer/src/lib.rs (renamed from src/renderer.rs) | 5 | ||||
| -rw-r--r-- | rst/Cargo.toml | 19 | ||||
| -rw-r--r-- | rst/src/main.rs (renamed from src/bin.rs) | 14 | ||||
| -rw-r--r-- | src/document_tree.rs | 35 | ||||
| -rw-r--r-- | src/lib.rs | 6 | 
31 files changed, 256 insertions, 211 deletions
| @@ -1,2 +1,2 @@  /target/ -/Cargo.lock +Cargo.lock @@ -1,42 +1,7 @@ -[package] -name = 'rst' -version = '0.2.0' -authors = [ 'Phil Schaf <flying-sheep@web.de>' ] - -description = 'a reStructuredText parser and renderer' -license = 'MIT OR Apache-2.0' - -documentation = 'https://flying-sheep.github.io/rust-rst' -homepage = 'https://github.com/flying-sheep/rust-rst' -repository = 'https://github.com/flying-sheep/rust-rst.git' - -edition = '2018' - -[lib] -name = 'rst' -path = 'src/lib.rs' - -[[bin]] -name = 'rst' -path = 'src/bin.rs' - -[dependencies] -failure = '0.1.5' -failure_derive = '0.1.5' -url = '1.7.2' -regex = '1.1.3' -bitflags = '1.0.4' -unicode_categories = '0.1.1' -pest = '2.1.0' -pest_derive = '2.1.0' -serde = '1.0.89' -serde_derive = '1.0.89' -serde_json = '1.0.39' -serde-xml-rs = '0.3.1' - -quicli = '0.4.0' -structopt = '0.2.15' -clap = '2.32.0' - -[dev-dependencies] -pretty_assertions = '0.6.1' +[workspace] +members = [ +	'document_tree', +	'parser', +	'renderer', +	'rst', +] diff --git a/document_tree/Cargo.toml b/document_tree/Cargo.toml new file mode 100644 index 0000000..09e827e --- /dev/null +++ b/document_tree/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = 'document_tree' +version = '0.2.0' +authors = ['Philipp A. <flying-sheep@web.de>'] +description = 'reStructuredText’s DocumenTree representation' +license = 'MIT OR Apache-2.0' + +documentation = 'https://flying-sheep.github.io/rust-rst' +homepage = 'https://github.com/flying-sheep/rust-rst' +repository = 'https://github.com/flying-sheep/rust-rst.git' + +edition = '2018' + +[dependencies] +failure = '0.1.6' +regex = '1.3.1' +url = '2.1.0' +serde = '1.0.104' +serde_derive = '1.0.104' diff --git a/src/document_tree/attribute_types.rs b/document_tree/src/attribute_types.rs index 30f3767..411b24d 100644 --- a/src/document_tree/attribute_types.rs +++ b/document_tree/src/attribute_types.rs @@ -102,11 +102,11 @@ impl FromStr for Measure {  }  #[cfg(test)] -mod test { +mod parse_tests {  	use super::*;  	#[test] -	fn test_parse_measure() { +	fn measure() {  		let _a: Measure = "1.5em".parse().unwrap();  		let _b: Measure = "20 mm".parse().unwrap();  		let _c: Measure = ".5in".parse().unwrap(); diff --git a/src/document_tree/element_categories.rs b/document_tree/src/element_categories.rs index db3f420..24a0798 100644 --- a/src/document_tree/element_categories.rs +++ b/document_tree/src/element_categories.rs @@ -2,7 +2,7 @@ use std::fmt::{self,Debug,Formatter};  use serde_derive::Serialize; -use super::elements::*; +use crate::elements::*;  pub trait HasChildren<C> {  	fn with_children(children: Vec<C>) -> Self; @@ -103,27 +103,27 @@ synonymous_enum!(SubTable { Title, TableGroup });  synonymous_enum!(SubTableGroup { TableColspec, TableHead, TableBody });  #[cfg(test)] -mod test { +mod conversion_tests {  	use std::default::Default;  	use super::*;  	#[test] -	fn test_convert_basic() { +	fn basic() {  		let _: BodyElement = Paragraph::default().into();  	}  	#[test] -	fn test_convert_more() { +	fn more() {  		let _: SubStructure = Paragraph::default().into();  	}  	#[test] -	fn test_convert_even_more() { +	fn even_more() {  		let _: StructuralSubElement = Paragraph::default().into();  	}  	#[test] -	fn test_convert_super() { +	fn super_() {  		let be: BodyElement = Paragraph::default().into();  		let _: StructuralSubElement = be.into();  	} diff --git a/src/document_tree/element_types.rs b/document_tree/src/element_types.rs index 429573e..429573e 100644 --- a/src/document_tree/element_types.rs +++ b/document_tree/src/element_types.rs diff --git a/src/document_tree/elements.rs b/document_tree/src/elements.rs index 7406cd7..26bccf6 100644 --- a/src/document_tree/elements.rs +++ b/document_tree/src/elements.rs @@ -1,9 +1,9 @@  use std::path::PathBuf;  use serde_derive::Serialize; -use super::attribute_types::{CanBeEmpty,ID,NameToken}; -use super::extra_attributes::{self,ExtraAttributes}; -use super::element_categories::*; +use crate::attribute_types::{CanBeEmpty,ID,NameToken}; +use crate::extra_attributes::{self,ExtraAttributes}; +use crate::element_categories::*;  //-----------------\\ diff --git a/src/document_tree/extra_attributes.rs b/document_tree/src/extra_attributes.rs index 55896ab..45fcf32 100644 --- a/src/document_tree/extra_attributes.rs +++ b/document_tree/src/extra_attributes.rs @@ -1,7 +1,15 @@  use serde_derive::Serialize;  use crate::url::Url; -use super::attribute_types::{CanBeEmpty,FixedSpace,ID,NameToken,AlignHV,AlignH,AlignV,TableAlignH,TableBorder,TableGroupCols,Measure,EnumeratedListType}; +use crate::attribute_types::{ +	CanBeEmpty, +	FixedSpace, +	ID,NameToken, +	AlignHV,AlignH,AlignV, +	TableAlignH,TableBorder,TableGroupCols, +	Measure, +	EnumeratedListType, +};  pub trait ExtraAttributes<A> {  	fn with_extra(extra: A) -> Self; diff --git a/document_tree/src/lib.rs b/document_tree/src/lib.rs new file mode 100644 index 0000000..324fc44 --- /dev/null +++ b/document_tree/src/lib.rs @@ -0,0 +1,43 @@ +#![recursion_limit="256"] + +///http://docutils.sourceforge.net/docs/ref/doctree.html +///serves as AST + +#[macro_use] +mod macro_util; + +pub mod url; +pub mod elements; +pub mod element_categories; +pub mod extra_attributes; +pub mod attribute_types; + +pub use self::elements::*; //Element,CommonAttributes,HasExtraAndChildren +pub use self::extra_attributes::ExtraAttributes; +pub use self::element_categories::HasChildren; + +#[cfg(test)] +mod tests { +	use super::*; + +	#[test] +	fn imperative() { +		let mut doc = Document::default(); +		let mut title = Title::default(); +		title.append_child("Hi"); +		doc.append_child(title); + +		println!("{:?}", doc); +	} + +	#[test] +	fn descriptive() { +		let doc = Document::with_children(vec![ +			Title::with_children(vec![ +				"Hi".into() +			]).into() +		]); + +		println!("{:?}", doc); +	} +} diff --git a/src/document_tree/macro_util.rs b/document_tree/src/macro_util.rs index d9b8a3e..dcf3725 100644 --- a/src/document_tree/macro_util.rs +++ b/document_tree/src/macro_util.rs @@ -18,7 +18,7 @@ macro_rules! cartesian {  #[cfg(test)] -mod test { +mod tests {  	macro_rules! print_cartesian {  		( [ $(($a1:tt, $a2:tt)),* , ] ) => {  			fn test_f(x:i64, y:i64) -> Result<(i64, i64), ()> { @@ -33,7 +33,7 @@ mod test {  	}  	#[test] -	fn test_print_cartesian() { +	fn print_cartesian() {  		cartesian!(print_cartesian, [1, 2, 3], [4, 5, 6]);  		assert_eq!(test_f(1, 4), Ok((1, 4)));  		assert_eq!(test_f(1, 3), Err(())); diff --git a/src/url.rs b/document_tree/src/url.rs index 31a0536..31a0536 100644 --- a/src/url.rs +++ b/document_tree/src/url.rs diff --git a/parser/Cargo.toml b/parser/Cargo.toml new file mode 100644 index 0000000..22f2490 --- /dev/null +++ b/parser/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = 'rst_parser' +version = '0.2.0' +authors = ['Philipp A. <flying-sheep@web.de>'] +edition = '2018' +description = 'a reStructuredText parser' +license = 'MIT OR Apache-2.0' + +documentation = 'https://flying-sheep.github.io/rust-rst' +homepage = 'https://github.com/flying-sheep/rust-rst' +repository = 'https://github.com/flying-sheep/rust-rst.git' + +[dependencies] +document_tree = { path = '../document_tree' } + +pest = '2.1.2' +pest_derive = '2.1.0' +failure = '0.1.6' diff --git a/src/parser/conversion.rs b/parser/src/conversion.rs index f9e2a78..de5f091 100644 --- a/src/parser/conversion.rs +++ b/parser/src/conversion.rs @@ -1,17 +1,19 @@  mod block;  mod inline; +#[cfg(test)] +mod tests;  use failure::Error;  use pest::iterators::Pairs; -use crate::document_tree::{ +use document_tree::{  	Element,HasChildren,  	elements as e,  	element_categories as c,  	attribute_types as at,  }; -use super::pest_rst::Rule; +use crate::pest_rst::Rule;  fn ssubel_to_section_unchecked_mut(ssubel: &mut c::StructuralSubElement) -> &mut e::Section { @@ -92,74 +94,3 @@ pub fn whitespace_normalize_name(name: &str) -> String {  	}  	ret  } - - -#[cfg(test)] -mod tests { -	use crate::{ -		parser::parse, -		document_tree::{ -			elements as e, -			element_categories as c, -			HasChildren, -		} -	}; -	 -	fn ssubel_to_section(ssubel: &c::StructuralSubElement) -> &e::Section { -		match ssubel { -			c::StructuralSubElement::SubStructure(ref b) => match **b { -				c::SubStructure::Section(ref s) => s, -				ref c => panic!("Expected section, not {:?}", c), -			}, -			ref c => panic!("Expected SubStructure, not {:?}", c), -		} -	} -	 -	const SECTIONS: &str = "\ -Intro before first section title - -Level 1 -******* - -------- -Level 2 -------- - -Level 3 -======= - -L1 again -******** - -L3 again, skipping L2 -===================== -"; -	 -	#[test] -	fn convert_skipped_section() { -		let doctree = parse(SECTIONS).unwrap(); -		let lvl0 = doctree.children(); -		assert_eq!(lvl0.len(), 3, "Should be a paragraph and 2 sections: {:?}", lvl0); -		 -		assert_eq!(lvl0[0], e::Paragraph::with_children(vec![ -			"Intro before first section title".to_owned().into() -		]).into(), "The intro text should fit"); -		 -		let lvl1a = ssubel_to_section(&lvl0[1]).children(); -		assert_eq!(lvl1a.len(), 2, "The 1st lvl1 section should have (a title and) a single lvl2 section as child: {:?}", lvl1a); -		//TODO: test title lvl1a[0] -		let lvl2  = ssubel_to_section(&lvl1a[1]).children(); -		assert_eq!(lvl2.len(), 2, "The lvl2 section should have (a title and) a single lvl3 section as child: {:?}", lvl2); -		//TODO: test title lvl2[0] -		let lvl3a = ssubel_to_section(&lvl2[1]).children(); -		assert_eq!(lvl3a.len(), 1, "The 1st lvl3 section should just a title: {:?}", lvl3a); -		//TODO: test title lvl3a[0] -		 -		let lvl1b = ssubel_to_section(&lvl0[2]).children(); -		assert_eq!(lvl1b.len(), 2, "The 2nd lvl1 section should have (a title and) a single lvl2 section as child: {:?}", lvl1b); -		//TODO: test title lvl1b[0] -		let lvl3b = ssubel_to_section(&lvl1b[1]).children(); -		assert_eq!(lvl3b.len(), 1, "The 2nd lvl3 section should have just a title: {:?}", lvl3b); -		//TODO: test title lvl3b[0] -	} -} diff --git a/src/parser/conversion/block.rs b/parser/src/conversion/block.rs index b14c2b5..ab18c48 100644 --- a/src/parser/conversion/block.rs +++ b/parser/src/conversion/block.rs @@ -1,7 +1,7 @@  use failure::{Error,bail};  use pest::iterators::Pair; -use crate::document_tree::{ +use document_tree::{  	Element,HasChildren,ExtraAttributes,  	elements as e,  	element_categories as c, @@ -9,7 +9,7 @@ use crate::document_tree::{  	attribute_types as at  }; -use crate::parser::{ +use crate::{  	pest_rst::Rule,  	pair_ext_parse::PairExt,  }; diff --git a/src/parser/conversion/inline.rs b/parser/src/conversion/inline.rs index b2fffa5..6094714 100644 --- a/src/parser/conversion/inline.rs +++ b/parser/src/conversion/inline.rs @@ -1,20 +1,19 @@  use failure::Error;  use pest::iterators::Pair; -use crate::document_tree::{ +use document_tree::{  	HasChildren,  	elements as e, +	url::Url,  	element_categories as c,  	extra_attributes as a,  	attribute_types as at,  }; -use crate::parser::{ +use crate::{  	pest_rst::Rule,  //    pair_ext_parse::PairExt,  }; - -use crate::url::Url;  use super::whitespace_normalize_name; diff --git a/parser/src/conversion/tests.rs b/parser/src/conversion/tests.rs new file mode 100644 index 0000000..89b0a1c --- /dev/null +++ b/parser/src/conversion/tests.rs @@ -0,0 +1,65 @@ +use document_tree::{ +	elements as e, +	element_categories as c, +	HasChildren, +}; + +use crate::parse; + +fn ssubel_to_section(ssubel: &c::StructuralSubElement) -> &e::Section { +	match ssubel { +		c::StructuralSubElement::SubStructure(ref b) => match **b { +			c::SubStructure::Section(ref s) => s, +			ref c => panic!("Expected section, not {:?}", c), +		}, +		ref c => panic!("Expected SubStructure, not {:?}", c), +	} +} + +const SECTIONS: &str = "\ +Intro before first section title + +Level 1 +******* + +------- +Level 2 +------- + +Level 3 +======= + +L1 again +******** + +L3 again, skipping L2 +===================== +"; + +#[test] +fn convert_skipped_section() { +	let doctree = parse(SECTIONS).unwrap(); +	let lvl0 = doctree.children(); +	assert_eq!(lvl0.len(), 3, "Should be a paragraph and 2 sections: {:?}", lvl0); +	 +	assert_eq!(lvl0[0], e::Paragraph::with_children(vec![ +		"Intro before first section title".to_owned().into() +	]).into(), "The intro text should fit"); +	 +	let lvl1a = ssubel_to_section(&lvl0[1]).children(); +	assert_eq!(lvl1a.len(), 2, "The 1st lvl1 section should have (a title and) a single lvl2 section as child: {:?}", lvl1a); +	//TODO: test title lvl1a[0] +	let lvl2  = ssubel_to_section(&lvl1a[1]).children(); +	assert_eq!(lvl2.len(), 2, "The lvl2 section should have (a title and) a single lvl3 section as child: {:?}", lvl2); +	//TODO: test title lvl2[0] +	let lvl3a = ssubel_to_section(&lvl2[1]).children(); +	assert_eq!(lvl3a.len(), 1, "The 1st lvl3 section should just a title: {:?}", lvl3a); +	//TODO: test title lvl3a[0] +	 +	let lvl1b = ssubel_to_section(&lvl0[2]).children(); +	assert_eq!(lvl1b.len(), 2, "The 2nd lvl1 section should have (a title and) a single lvl2 section as child: {:?}", lvl1b); +	//TODO: test title lvl1b[0] +	let lvl3b = ssubel_to_section(&lvl1b[1]).children(); +	assert_eq!(lvl3b.len(), 1, "The 2nd lvl3 section should have just a title: {:?}", lvl3b); +	//TODO: test title lvl3b[0] +} diff --git a/src/parser.rs b/parser/src/lib.rs index 00c967d..23e97c7 100644 --- a/src/parser.rs +++ b/parser/src/lib.rs @@ -9,7 +9,7 @@ pub mod tests;  use failure::Error;  use pest::Parser; -use crate::document_tree::Document; +use document_tree::Document;  use self::pest_rst::{RstParser,Rule};  use self::conversion::convert_document; diff --git a/src/parser/pair_ext_parse.rs b/parser/src/pair_ext_parse.rs index a04b3dd..a04b3dd 100644 --- a/src/parser/pair_ext_parse.rs +++ b/parser/src/pair_ext_parse.rs diff --git a/src/parser/pest_rst.rs b/parser/src/pest_rst.rs index 74199a8..74199a8 100644 --- a/src/parser/pest_rst.rs +++ b/parser/src/pest_rst.rs diff --git a/src/rst.pest b/parser/src/rst.pest index f3a1516..f3a1516 100644 --- a/src/rst.pest +++ b/parser/src/rst.pest diff --git a/src/parser/simplify.rs b/parser/src/simplify.rs index cc169ee..7974991 100644 --- a/src/parser/simplify.rs +++ b/parser/src/simplify.rs @@ -21,8 +21,8 @@ TODO: continue documenting how it’s done via https://repo.or.cz/docutils.git/b  use std::collections::HashMap; -use crate::url::Url; -use crate::document_tree::{ +use document_tree::{ +	url::Url,  	Document,  	HasChildren,  	attribute_types::NameToken, @@ -377,7 +377,7 @@ impl ResolvableRefs for c::TextOrInlineElement {  					// TODO: This replaces the reference by a Problematic node.  					// The corresponding SystemMessage node should go in a generated  					// section with class "system-messages" at the end of the document. -					use crate::document_tree::Problematic; +					use document_tree::Problematic;  					let mut replacement: Box<Problematic> = Box::new(Default::default());  					replacement.children_mut().push(  						c::TextOrInlineElement::String(Box::new(format!("|{}|", e.extra().refname[0].0))) diff --git a/src/parser/tests.rs b/parser/src/tests.rs index a034c0e..1ef965a 100644 --- a/src/parser/tests.rs +++ b/parser/src/tests.rs @@ -1,6 +1,7 @@  use pest::consumes_to;  use pest::parses_to; -use super::pest_rst::{RstParser, Rule}; + +use crate::pest_rst::{RstParser, Rule};  #[test]  fn plain() { diff --git a/src/parser/token.rs b/parser/src/token.rs index b3b7bac..b3b7bac 100644 --- a/src/parser/token.rs +++ b/parser/src/token.rs diff --git a/renderer/Cargo.toml b/renderer/Cargo.toml new file mode 100644 index 0000000..bc80adc --- /dev/null +++ b/renderer/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = 'rst_renderer' +version = '0.2.0' +authors = ['Philipp A. <flying-sheep@web.de>'] +edition = '2018' +description = 'a reStructuredText renderer' +license = 'MIT OR Apache-2.0' + +documentation = 'https://flying-sheep.github.io/rust-rst' +homepage = 'https://github.com/flying-sheep/rust-rst' +repository = 'https://github.com/flying-sheep/rust-rst.git' + +[dependencies] +document_tree = { path = '../document_tree' } + +failure = '0.1.6' +serde_json = '1.0.44' +serde-xml-rs = '0.3.1' + +[dev-dependencies] +rst_parser = { path = '../parser' } + +pretty_assertions = '0.6.1' diff --git a/src/renderer/html.rs b/renderer/src/html.rs index 6041ec0..73b994d 100644 --- a/src/renderer/html.rs +++ b/renderer/src/html.rs @@ -1,13 +1,15 @@ +#[cfg(test)] +pub mod tests; +  use std::io::Write;  use failure::Error;  // use crate::url::Url; -use crate::document_tree::{ +use document_tree::{  	Document,Element,HasChildren,ExtraAttributes,  	elements as e,  	element_categories as c, -	extra_attributes as a,  }; @@ -166,7 +168,8 @@ impl_html_render_cat!(BodyElement { Paragraph, LiteralBlock, DoctestBlock, MathB  impl_html_render_simple!(Paragraph => p, LiteralBlock => pre, MathBlock => math, Rubric => a, Compound => p, Container => div, BulletList => ul["\n"], EnumeratedList => ol["\n"], DefinitionList => dl["\n"], FieldList => dl["\n"], OptionList => pre, LineBlock => div["\n"], BlockQuote => blockquote, Admonition => aside, Attention => aside, Hint => aside, Note => aside, Caution => aside, Danger => aside, Error => aside, Important => aside, Tip => aside, Warning => aside, Figure => figure);  impl_html_render_simple_nochildren!(Table => table);  //TODO: after implementing the table, move it to elems with children -impl<I> HTMLRender for I where I: e::Element + a::ExtraAttributes<a::Image> { +//impl<I> HTMLRender for I where I: e::Element + a::ExtraAttributes<a::Image> +macro_rules! impl_render_html_image { ($t:ty) => { impl HTMLRender for $t {  	fn render_html<W>(&self, renderer: &mut HTMLRenderer<W>) -> Result<(), Error> where W: Write {  		let extra = self.extra();  		if let Some(ref target) = extra.target { @@ -186,7 +189,9 @@ impl<I> HTMLRender for I where I: e::Element + a::ExtraAttributes<a::Image> {  		}  		Ok(())  	} -} +}}} +impl_render_html_image!(e::Image); +impl_render_html_image!(e::ImageInline);  impl HTMLRender for e::DoctestBlock {  	fn render_html<W>(&self, _renderer: &mut HTMLRenderer<W>) -> Result<(), Error> where W: Write { diff --git a/src/renderer/html_tests.rs b/renderer/src/html/tests.rs index 117b2d4..8477699 100644 --- a/src/renderer/html_tests.rs +++ b/renderer/src/html/tests.rs @@ -1,7 +1,8 @@  use pretty_assertions::assert_eq; -use crate::parser::parse; -use super::html::render_html; +use rst_parser::parse; + +use crate::html::render_html;  fn check_renders_to(rst: &str, expected: &str) {  	println!("Rendering:\n{}\n---", rst); @@ -13,7 +14,7 @@ fn check_renders_to(rst: &str, expected: &str) {  }  #[test] -fn test_simple_string() { +fn simple_string() {  	check_renders_to(  		"Simple String",  		"<p>Simple String</p>", @@ -21,7 +22,7 @@ fn test_simple_string() {  }  #[test] -fn test_simple_string_with_markup() { +fn simple_string_with_markup() {  	check_renders_to(  		"Simple String with *emph* and **strong**",  		"<p>Simple String with <em>emph</em> and <strong>strong</strong></p>", @@ -29,7 +30,7 @@ fn test_simple_string_with_markup() {  }  #[test] -fn test_check_inline_literal() { +fn inline_literal() {  	check_renders_to(  		"Simple String with an even simpler ``inline literal``",  		"<p>Simple String with an even simpler <code>inline literal</code></p>", @@ -50,7 +51,7 @@ __ http://www.test.com/test_url  */  #[test] -fn test_two_paragraphs() { +fn two_paragraphs() {  	check_renders_to(  		"One paragraph.\n\nTwo paragraphs.",  		"<p>One paragraph.</p>\n<p>Two paragraphs.</p>", @@ -58,7 +59,7 @@ fn test_two_paragraphs() {  }  #[test] -fn test_named_reference() { +fn named_reference() {  	check_renders_to("\  A simple `named reference`_ with stuff in between the  reference and the target. @@ -71,7 +72,7 @@ reference and the target.</p>\  }  #[test] -fn test_substitution() { +fn substitution() {  	check_renders_to("\  A |subst|. @@ -138,7 +139,7 @@ Some stuff  */  #[test] -fn test_section_hierarchy() { +fn section_hierarchy() {  	check_renders_to("\  +++++  Title @@ -178,7 +179,7 @@ And even more stuff  }  #[test] -fn test_bullet_list() { +fn bullet_list() {  	check_renders_to("\  * bullet  * list diff --git a/src/renderer.rs b/renderer/src/lib.rs index 82a5826..4d6bfdb 100644 --- a/src/renderer.rs +++ b/renderer/src/lib.rs @@ -1,13 +1,11 @@  mod html; -#[cfg(test)] -pub mod html_tests;  use std::io::Write;  use failure::Error; -use crate::document_tree::Document; +use document_tree::Document;  pub fn render_json<W>(document: &Document, stream: W) -> Result<(), Error> where W: Write { @@ -21,4 +19,3 @@ pub fn render_xml<W>(document: &Document, stream: W) -> Result<(), Error> where  }  pub use html::render_html; - diff --git a/rst/Cargo.toml b/rst/Cargo.toml new file mode 100644 index 0000000..3d1d6f2 --- /dev/null +++ b/rst/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = 'rst' +version = '0.2.0' +authors = ['Philipp A. <flying-sheep@web.de>'] +edition = '2018' +description = 'a reStructuredText parser and renderer for the command line' +license = 'MIT OR Apache-2.0' + +documentation = 'https://flying-sheep.github.io/rust-rst' +homepage = 'https://github.com/flying-sheep/rust-rst' +repository = 'https://github.com/flying-sheep/rust-rst.git' + +[dependencies] +rst_renderer = { path = '../renderer' } +rst_parser = { path = '../parser' } + +quicli = '0.4.0' +structopt = '0.2.15' +clap = '2.32.0' diff --git a/src/bin.rs b/rst/src/main.rs index 394b416..3c0b8e5 100644 --- a/src/bin.rs +++ b/rst/src/main.rs @@ -1,20 +1,12 @@ -#![recursion_limit="256"] - -pub mod document_tree; -pub mod parser; -pub mod renderer; -pub mod url; - -  use structopt::StructOpt; -use clap::{_clap_count_exprs, arg_enum}; +use clap::arg_enum;  use quicli::{  	fs::read_file,  	prelude::{CliResult,Verbosity},  }; -use self::parser::parse; -use self::renderer::{ +use rst_parser::parse; +use rst_renderer::{  	render_json,  	render_xml,  	render_html, diff --git a/src/document_tree.rs b/src/document_tree.rs deleted file mode 100644 index 0af47ba..0000000 --- a/src/document_tree.rs +++ /dev/null @@ -1,35 +0,0 @@ -///http://docutils.sourceforge.net/docs/ref/doctree.html -///serves as AST - -#[macro_use] -mod macro_util; - -pub mod elements; -pub mod element_categories; -pub mod extra_attributes; -pub mod attribute_types; - -pub use self::elements::*; //Element,CommonAttributes,HasExtraAndChildren -pub use self::extra_attributes::ExtraAttributes; -pub use self::element_categories::HasChildren; - -#[test] -fn test_imperative() { -	let mut doc = Document::default(); -	let mut title = Title::default(); -	title.append_child("Hi"); -	doc.append_child(title); -	 -	println!("{:?}", doc); -} - -#[test] -fn test_descriptive() { -	let doc = Document::with_children(vec![ -		Title::with_children(vec![ -			"Hi".into() -		]).into() -	]); -	 -	println!("{:?}", doc); -} diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 6e39b1a..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![recursion_limit="256"] - -pub mod document_tree; -pub mod parser; -pub mod renderer; -pub mod url; | 
