Skip to content

Commit ebca18e

Browse files
jelmerflying-sheep
andauthored
Handle images with multiple options (#53)
Co-authored-by: Philipp A. <flying-sheep@web.de>
1 parent c331cca commit ebca18e

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

parser/src/rst.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ replace = { ^"replace::" ~ " "* ~ paragraph }
8888

8989
image_directive = _{ ".." ~ PUSH(" "+) ~ image ~ DROP }
9090
image = { ^"image::" ~ line ~ image_opt_block? }
91-
image_opt_block = _{ PEEK[..-1] ~ PUSH(" " ~ POP) ~ image_option } //TODO: merge with other directives?
91+
image_opt_block = _{ PEEK[..-1] ~ PUSH(" " ~ POP) ~ image_option ~ (PEEK[..] ~ image_option)* }
9292
image_option = { ":" ~ image_opt_name ~ ":" ~ line }
9393
image_opt_name = { common_opt_name | "alt" | "height" | "width" | "scale" | "align" | "target" }
9494

parser/src/tests.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,36 @@ fn substitution_image() {
393393
};
394394
}
395395

396+
#[allow(clippy::cognitive_complexity)]
397+
#[test]
398+
fn substitution_image_with_alt() {
399+
parses_to! {
400+
parser: RstParser,
401+
input: "\
402+
.. |subst| image:: thing.png
403+
:alt: A thing
404+
:target: foo.html
405+
",
406+
rule: Rule::document,
407+
tokens: [
408+
substitution_def(0, 67, [
409+
substitution_name(4, 9),
410+
image(11, 67, [
411+
line(18, 29, [ str(18, 28) ]),
412+
image_option(32, 46, [
413+
image_opt_name(33, 36),
414+
line(37, 46, [ str(37, 45) ]),
415+
]),
416+
image_option(49, 67, [
417+
image_opt_name(50, 56),
418+
line(57, 67, [ str(57, 66) ]),
419+
]),
420+
]),
421+
]),
422+
]
423+
};
424+
}
425+
396426
// TODO: test images
397427

398428
#[allow(clippy::cognitive_complexity)]

0 commit comments

Comments
 (0)