From 7018f5d3c42f18b6c83f398db9f1915361a7c679 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sun, 8 Dec 2019 20:32:54 +0100 Subject: Fix and test substitution --- .travis.yml | 2 ++ src/parser/conversion/inline.rs | 12 ++++++------ src/parser/tests.rs | 6 +++--- src/renderer/html_tests.rs | 9 +++++++++ src/rst.pest | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 46a87c8..0f8af64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,5 @@ language: rust cache: cargo rust: - stable +env: + - RUST_BACKTRACE=short diff --git a/src/parser/conversion/inline.rs b/src/parser/conversion/inline.rs index 52803ef..b2fffa5 100644 --- a/src/parser/conversion/inline.rs +++ b/src/parser/conversion/inline.rs @@ -21,12 +21,12 @@ use super::whitespace_normalize_name; pub fn convert_inline(pair: Pair) -> Result { Ok(match pair.as_rule() { Rule::str | Rule::str_nested => pair.as_str().into(), - Rule::ws_newline => " ".to_owned().into(), - Rule::reference => convert_reference(pair)?, - Rule::substitution_ref => convert_substitution_ref(pair)?.into(), - Rule::emph => e::Emphasis::with_children(convert_inlines(pair)?).into(), - Rule::strong => e::Strong::with_children(convert_inlines(pair)?).into(), - Rule::literal => e::Literal::with_children(convert_inlines(pair)?).into(), + Rule::ws_newline => " ".to_owned().into(), + Rule::reference => convert_reference(pair)?, + Rule::substitution_name => convert_substitution_ref(pair)?.into(), + Rule::emph => e::Emphasis::with_children(convert_inlines(pair)?).into(), + Rule::strong => e::Strong::with_children(convert_inlines(pair)?).into(), + Rule::literal => e::Literal::with_children(convert_inlines(pair)?).into(), rule => unimplemented!("unknown rule {:?}", rule), }) } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index bad818e..a034c0e 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -157,12 +157,12 @@ A |subst| in-line ]), substitution_def(19, 52, [ substitution_name(23, 28), - replace(30, 52, [ paragraph(39, 52, [str(39, 52)]) ]), + replace(30, 52, [ paragraph(40, 52, [str(40, 52)]) ]), ]), substitution_def(53, 101, [ substitution_name(57, 63), - replace(65, 101, [ paragraph(74, 101, [ - str(74, 86), ws_newline(86, 87), + replace(65, 101, [ paragraph(75, 101, [ + str(75, 86), ws_newline(86, 87), str(88, 100), ]) ]), ]), diff --git a/src/renderer/html_tests.rs b/src/renderer/html_tests.rs index 62a02f6..117b2d4 100644 --- a/src/renderer/html_tests.rs +++ b/src/renderer/html_tests.rs @@ -70,6 +70,15 @@ reference and the target.

\ "); } +#[test] +fn test_substitution() { + check_renders_to("\ +A |subst|. + +.. |subst| replace:: text substitution +", "

A text substitution.

"); +} + /* #[test] fn test_section_hierarchy() { diff --git a/src/rst.pest b/src/rst.pest index 7c4fc0f..f3a1516 100644 --- a/src/rst.pest +++ b/src/rst.pest @@ -76,7 +76,7 @@ common_opt_name = { "class" | "name" } // Replace. A directive only usable in substitutions. -replace = { ^"replace::" ~ paragraph } +replace = { ^"replace::" ~ " "* ~ paragraph } // Image. A directive. -- cgit v1.2.3