~autumnull/flatiron

a4c8022431e9e91470b2042884fbce51b99d59ff — Autumn! 2 years ago 15d28c1
Changed escaping mechanic in notextile blocks
4 files changed, 27 insertions(+), 10 deletions(-)

M SPEC.md
M src/parse.rs
M tests/notextile.rs
M tests/sample.textile
M SPEC.md => SPEC.md +2 -2
@@ 168,9 168,9 @@ Now some more text within the code block</code></pre>

### Raw phrases containing equals signs

Raw phrases, e.g. `==no **textile**==` can contain double equals signs, as long as they are escaped using backslashes. e.g.
Raw phrases, e.g. `==no **textile**==` can contain double equals signs, as long as they are escaped using a backslash. e.g.
```textile
==This is two equals signs: \=\= here are two more: \=\===
==This is two equals signs: \== here are two more: \====
```
will be rendered as
```

M src/parse.rs => src/parse.rs +23 -5
@@ 4,7 4,8 @@ use nom::{
    character::complete::{char, line_ending, none_of, satisfy},
    combinator::{complete, eof, fail, map, map_res, opt, value},
    multi::{
        fold_many1, fold_many_m_n, many0, many0_count, many1_count, many_till,
        fold_many0, fold_many1, fold_many_m_n, many0, many0_count, many1_count,
        many_till,
    },
    sequence::{delimited, preceded, terminated, tuple},
    IResult,


@@ 764,16 765,33 @@ fn line_break(input: &str) -> IResult<&str, InlineTag> {
pub fn no_textile(input: &str) -> IResult<&str, InlineTag> {
    let (rest, content) = delimited(
        tag("=="),
        escaped_transform(
            none_of("\\="),
            '\\',
            alt((value("\\", tag("\\")), value("=", tag("=")))),
        fold_many0(
            alt((
                value("\\", tag("\\\\")),
                value("==", tag("\\==")),
                no_textile_content,
            )),
            String::new,
            |mut acc, s| {
                acc.push_str(s);
                acc
            },
        ),
        tag("=="),
    )(input)?;
    Ok((rest, InlineTag::NoTextile(content)))
}

fn no_textile_content(input: &str) -> IResult<&str, &str> {
    let res: IResult<&str, &str> = alt((tag("=="), tag("\\")))(input);
    if let Err(_) = res {
        if input != "" {
            return Ok((&input[1..], &input[0..1]));
        }
    }
    fail(input)
}

fn code(input: &str) -> IResult<&str, InlineTag> {
    let (rest, content) = delimited(
        char('@'),

M tests/notextile.rs => tests/notextile.rs +1 -2
@@ 12,8 12,7 @@ fn no_textile_basic() {

#[test]
fn no_textile_with_equals() {
    let input =
        "==This is two equals signs: \\=\\= here are two more: \\=\\===";
    let input = "==This is two equals signs: \\== here are two more: \\====";
    let result = no_textile(input);
    assert_eq!(
        result,

M tests/sample.textile => tests/sample.textile +1 -1
@@ 35,7 35,7 @@ Mixed list:
** Sub point 2


Well, that went well. How about we insert an ==<a href\="http://www.textism.com/" title\="watch out">old-fashioned hypertext link</a>==? Will the quote marks in the tags get messed up? No!
Well, that went well. How about we insert an ==<a href="http://www.textism.com/" title="watch out">old-fashioned hypertext link</a>==? Will the quote marks in the tags get messed up? No!

"This is a link (optional title)":http://www.textism.com