Exclude language from the switches property.
This commit is contained in:
parent
b556f4617f
commit
a548c7e170
@ -14,6 +14,7 @@ use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many_till;
|
||||
use nom::multi::separated_list0;
|
||||
use nom::multi::separated_list1;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
@ -162,7 +163,11 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>(
|
||||
let (switches, number_lines, retain_labels, use_labels, label_format) = {
|
||||
if let Some(parameters) = parameters {
|
||||
(
|
||||
Some(parameters.source),
|
||||
if parameters.source.len() == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(parameters.source)
|
||||
},
|
||||
parameters.number_lines,
|
||||
parameters.retain_labels,
|
||||
parameters.use_labels,
|
||||
@ -260,7 +265,11 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>(
|
||||
let (switches, language, number_lines, retain_labels, use_labels, label_format) = {
|
||||
if let Some(parameters) = parameters {
|
||||
(
|
||||
Some(parameters.source),
|
||||
if parameters.source.len() == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(parameters.source)
|
||||
},
|
||||
parameters.language,
|
||||
parameters.number_lines,
|
||||
parameters.retain_labels,
|
||||
@ -393,21 +402,23 @@ fn _example_src_switches<'s>(
|
||||
let mut label_format = None;
|
||||
let mut saw_r = false;
|
||||
let mut language = None;
|
||||
let (remaining, (source, (words, _))) =
|
||||
consumed(tuple((separated_list1(space1, switch_word), space0)))(input)?;
|
||||
|
||||
let mut words_iter = words.into_iter();
|
||||
if grab_language {
|
||||
match words_iter.next() {
|
||||
Some(l) => {
|
||||
language = Some(Into::<&str>::into(l));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
let remaining = if grab_language {
|
||||
let (remain, first_word) = opt(map(tuple((switch_word, space0)), |(word, _)| word))(input)?;
|
||||
language = first_word.map(Into::<&str>::into);
|
||||
remain
|
||||
} else {
|
||||
input
|
||||
};
|
||||
|
||||
let (remaining, (source, (words, _))) = if language.is_none() {
|
||||
consumed(tuple((separated_list1(space1, switch_word), space0)))(remaining)?
|
||||
} else {
|
||||
consumed(tuple((separated_list0(space1, switch_word), space0)))(remaining)?
|
||||
};
|
||||
|
||||
let mut state = SwitchState::Normal;
|
||||
for word in words_iter {
|
||||
for word in words {
|
||||
let normalized_word = Into::<&str>::into(word);
|
||||
loop {
|
||||
match (&state, normalized_word) {
|
||||
|
Loading…
Reference in New Issue
Block a user