@@ -192,6 +192,19 @@ where
192
192
}
193
193
}
194
194
195
+ #[ non_exhaustive]
196
+ #[ derive( Debug , Clone , PartialEq , Eq , Copy ) ]
197
+ #[ cfg_attr( feature = "arbitrary" , derive( arbitrary:: Arbitrary ) ) ]
198
+ /// Selects between wikilinks with the title first or the URL first.
199
+ pub ( crate ) enum WikiLinksMode {
200
+ /// Indicates that the URL precedes the title. For example: `[[http://example.com|link
201
+ /// title]]`.
202
+ UrlFirst ,
203
+
204
+ /// Indicates that the title precedes the URL. For example: `[[link title|http://example.com]]`.
205
+ TitleFirst ,
206
+ }
207
+
195
208
#[ non_exhaustive]
196
209
#[ derive( Default , Debug , Clone , Builder ) ]
197
210
#[ cfg_attr( feature = "arbitrary" , derive( arbitrary:: Arbitrary ) ) ]
@@ -472,6 +485,11 @@ pub struct ExtensionOptions {
472
485
/// [[url|link label]]
473
486
/// ````
474
487
///
488
+ /// When both this option and [`wikilinks_title_before_pipe`][0] are enabled, this option takes
489
+ /// precedence.
490
+ ///
491
+ /// [0]: Self::wikilinks_title_before_pipe
492
+ ///
475
493
/// ```
476
494
/// # use comrak::{markdown_to_html, Options};
477
495
/// let mut options = Options::default();
@@ -487,6 +505,10 @@ pub struct ExtensionOptions {
487
505
/// ```` md
488
506
/// [[link label|url]]
489
507
/// ````
508
+ /// When both this option and [`wikilinks_title_after_pipe`][0] are enabled,
509
+ /// [`wikilinks_title_after_pipe`][0] takes precedence.
510
+ ///
511
+ /// [0]: Self::wikilinks_title_after_pipe
490
512
///
491
513
/// ```
492
514
/// # use comrak::{markdown_to_html, Options};
@@ -617,6 +639,19 @@ pub struct ExtensionOptions {
617
639
pub link_url_rewriter : Option < Arc < dyn URLRewriter > > ,
618
640
}
619
641
642
+ impl ExtensionOptions {
643
+ pub ( crate ) fn wikilinks ( & self ) -> Option < WikiLinksMode > {
644
+ match (
645
+ self . wikilinks_title_before_pipe ,
646
+ self . wikilinks_title_after_pipe ,
647
+ ) {
648
+ ( false , false ) => None ,
649
+ ( true , false ) => Some ( WikiLinksMode :: TitleFirst ) ,
650
+ ( _, _) => Some ( WikiLinksMode :: UrlFirst ) ,
651
+ }
652
+ }
653
+ }
654
+
620
655
#[ non_exhaustive]
621
656
#[ derive( Default , Clone , Debug , Builder ) ]
622
657
#[ cfg_attr( feature = "arbitrary" , derive( arbitrary:: Arbitrary ) ) ]
0 commit comments