From f1c1422d0ae17f46999735bbb787cca188ecfa54 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sun, 8 Dec 2019 17:27:38 +0100 Subject: render newlines to spaces --- src/parser/conversion/inline.rs | 1 + src/parser/tests.rs | 9 ++++++--- src/renderer/html_tests.rs | 2 +- src/rst.pest | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/parser/conversion/inline.rs b/src/parser/conversion/inline.rs index 297680a..bdabbf0 100644 --- a/src/parser/conversion/inline.rs +++ b/src/parser/conversion/inline.rs @@ -21,6 +21,7 @@ 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(), diff --git a/src/parser/tests.rs b/src/parser/tests.rs index e161108..bad818e 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -161,7 +161,10 @@ A |subst| in-line ]), substitution_def(53, 101, [ substitution_name(57, 63), - replace(65, 101, [ paragraph(74, 101, [str(74, 86), str(88, 100)]) ]), + replace(65, 101, [ paragraph(74, 101, [ + str(74, 86), ws_newline(86, 87), + str(88, 100), + ]) ]), ]), ] }; @@ -222,8 +225,8 @@ paragraph bullet_item(21, 131, [ line(24, 31, [ str(24, 30) ]), paragraph(34, 74, [ - str(34, 43), - str(47, 58), + str(34, 43), ws_newline(43, 44), + str(47, 58), ws_newline(58, 59), str(62, 73), ]), bullet_list(77, 131, [ diff --git a/src/renderer/html_tests.rs b/src/renderer/html_tests.rs index 30fc1b1..62a02f6 100644 --- a/src/renderer/html_tests.rs +++ b/src/renderer/html_tests.rs @@ -65,7 +65,7 @@ reference and the target. .. _`named reference`: http://www.test.com/test_url ", "\ -

A simple named reference with stuff in between the +

A simple named reference with stuff in between the \ reference and the target.

\ "); } diff --git a/src/rst.pest b/src/rst.pest index 1034d03..7c4fc0f 100644 --- a/src/rst.pest +++ b/src/rst.pest @@ -103,8 +103,9 @@ admonition_content = _{ PEEK[..-1] ~ PUSH(" " ~ POP) ~ hanging_block ~ block* } line = { !marker ~ inline+ ~ NEWLINE } blank_line = _{ !marker ~ !inline ~ " "* ~ NEWLINE } -inlines = _{ !marker ~ inline+ ~ ( NEWLINE ~ (PEEK[..] ~ !marker ~ inline+ ~ NEWLINE)+ )? } -inline = _{ inline_special | str } +inlines = _{ !marker ~ inline+ ~ ( ( ws_newline ~ PEEK[..] ~ !marker ~ inline+ )+ ~ NEWLINE )? } +ws_newline = { NEWLINE } +inline = _{ inline_special | str } inline_special = _{ reference | substitution_ref -- cgit v1.2.3